<commit_before># -*- coding: utf-8 -*-
#
# K9's Movement Subsystem - Autonomous Motor Driver
#
# authored by <NAME> February 2018 for AoT Autonomy Team
#
# Licensed under The Unlicense, so free for public domain use
#
# This program provides K9 with a stack of instructions for his movement

import time
import math

print "Importing Redis library..."
import redis
# Connect to a local Redis server
print "Connecting to local redis host"
r = redis.Redis(host='127.0.0.1',port=6379)

sim=False

if __name__ == '__main__' :
    import sys     # allows for command line to be interpreted
    if ( len(sys.argv) > 1 ) :
        if ( sys.argv[1] == "test" ) :
            sim = True
            print "Simulating without RoboClaw" # let the user know they are in sim mode

CLICK2METRES = 0.00611 # converts clicks to metres
WALKINGSPEED = 1 # top speed of robot in metres per second
TOPSPEED = int(WALKINGSPEED/CLICK2METRES) # calculate and store max velocity
ACCELERATION = int(0.5*TOPSPEED) # accelerate to top speed in 0.5s
TURNING_CIRCLE = int(1.1938/CLICK2METRES) # clicks in a full spin
HALF_WHEEL_GAP = 0.095 # half the distance between the wheels

if not sim:
    from roboclaw import Roboclaw
    rc = Roboclaw("/dev/roboclaw",115200)
    rc.Open()
    address = 0x80

if sim:
    import turtle
    turtle.radians()

def stop():
    '''Lock motors to stop motion
    '''
    if not sim:
        rc.SpeedAccelM1(address,12000,1)
        time.sleep(0.05)
    	rc.SpeedAccelM2(address,-12000,-1)
        time.sleep(0.05)
        rc.SpeedAccelM1(address,12000,1)
        time.sleep(0.05)
    	rc.SpeedAccelM2(address,-12000,-1)
        time.sleep(0.05)        
        rc.SpeedAccelM2(address,12000,0)

def waitForMove2Finish():
    ''' Waits until robot has finished move
    '''
    if not sim:
        buffers = (0,0,0)
        while (buffers[1]!=0x80 and buffers[2]!=0x80):
            buffers = rc.ReadBuffers(address);
    stop()

def calc_turn_modifier(radius):
    turn_modifier = 1 - (0.9/(radius+1))
    return turn_modifier

def calc_click_vel(clicks,turn_mod):
    '''Calculates target velocity for motors

    Arguments:
    clicks -- a signed click distance
    turn_mod -- a modifier based on radius of turn

    '''
    sign_modifier = 1
    if (clicks<0):
        sign_modifier = -1
    click_vel = math.sqrt(abs(float(2*clicks*ACCELERATION*turn_mod)))
    if (click_vel > TOPSPEED*turn_mod) :
        click_vel = TOPSPEED*turn_mod
    return click_vel*sign_modifier<commit_msg>Try number 3 at stop()<commit_after># -*- coding: utf-8 -*-
#
# K9's Movement Subsystem - Autonomous Motor Driver
#
# authored by <NAME> February 2018 for AoT Autonomy Team
#
# Licensed under The Unlicense, so free for public domain use
#
# This program provides K9 with a stack of instructions for his movement

import time
import math

print "Importing Redis library..."
import redis
# Connect to a local Redis server
print "Connecting to local redis host"
r = redis.Redis(host='127.0.0.1',port=6379)

sim=False

if __name__ == '__main__' :
    import sys     # allows for command line to be interpreted
    if ( len(sys.argv) > 1 ) :
        if ( sys.argv[1] == "test" ) :
            sim = True
            print "Simulating without RoboClaw" # let the user know they are in sim mode

CLICK2METRES = 0.00611 # converts clicks to metres
WALKINGSPEED = 1 # top speed of robot in metres per second
TOPSPEED = int(WALKINGSPEED/CLICK2METRES) # calculate and store max velocity
ACCELERATION = int(0.5*TOPSPEED) # accelerate to top speed in 0.5s
TURNING_CIRCLE = int(1.1938/CLICK2METRES) # clicks in a full spin
HALF_WHEEL_GAP = 0.095 # half the distance between the wheels

if not sim:
    from roboclaw import Roboclaw
    rc = Roboclaw("/dev/roboclaw",115200)
    rc.Open()
    address = 0x80

if sim:
    import turtle
    turtle.radians()

def stop():
    '''Lock motors to stop motion
    '''
    if not sim:
        rc.SpeedAccelM1(address,12000,1)
        time.sleep(0.05)
    	rc.SpeedAccelM2(address,-12000,-1)
        time.sleep(0.05)
        rc.SpeedAccelM1(address,12000,1)
        time.sleep(0.05)
    	rc.SpeedAccelM2(address,-12000,-1)
        time.sleep(0.05)
        rc.SpeedAccelDistanceM1M2(address=address,accel=int(ACCELERATION),speed1=0,distance1=0,speed2=0,distance2=0,buffer=int(0))

def waitForMove2Finish():
    ''' Waits until robot has finished move
    '''
    if not sim:
        buffers = (0,0,0)
        while (buffers[1]!=0x80 and buffers[2]!=0x80):
            buffers = rc.ReadBuffers(address);
    stop()

def calc_turn_modifier(radius):
    turn_modifier = 1 - (0.9/(radius+1))
    return turn_modifier

def calc_click_vel(clicks,turn_mod):
    '''Calculates target velocity for motors

    Arguments:
    clicks -- a signed click distance
    turn_mod -- a modifier based on radius of turn

    '''
    sign_modifier = 1
    if (clicks<0):
        sign_modifier = -1
    click_vel = math.sqrt(abs(float(2*clicks*ACCELERATION*turn_mod)))
    if (click_vel > TOPSPEED*turn_mod) :
        click_vel = TOPSPEED*turn_mod
    return click_vel*sign_modifier
{'fraction_non_alphanumeric': 0.10450698681361936, 'fraction_numerical': 0.04743160795119071, 'mean_word_length': 3.0688550840672537, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1623904', 'n_tokens_mistral': 1884, 'n_tokens_neox': 1736, 'n_words': 489}