def go(given_angle, given_distance): angle = given_angle distance = given_distance curr_time = time.time() next_state = False #constants in feet diameter = 11.25 wheel_circumference = 16.72 #right is master, left is slave global slave_power global master_power master_power = .25 slave_power = -.25 global right_num_revs right_num_revs = 0 global left_num_revs left_num_revs = 0 global kp kp = .5 #distance modifier d_mod = .95 turns = angle / 360.0 * math.pi * diameter / wheel_circumference dist = distance / wheel_circumference encoders.init() encoders.clear() motors.init() global en_right global en_left en_left, en_right = encoders.read() while True: try: if (abs(right_num_revs) + abs(left_num_revs) ) / 2.0 >= turns * d_mod and not next_state: print slave_power print master_power curr_time = time.time() next_state = True if time.time() > (curr_time + 0) and next_state: break motors.speed(slave_power, master_power) adjustMotorPowers() readEncoder() except KeyboardInterrupt: break motors.speed(0, 0) time.sleep(1) kill_constant = 5 right_num_revs = 0.0 left_num_revs = 0.0 slave_power = 0.233 master_power = 0.25 while True: if (abs(right_num_revs) + abs(left_num_revs)) / 2.0 >= dist * d_mod: break try: if (abs(left_num_revs) - abs(right_num_revs)) > kill_threshold: master_power += .95 * master_power + .05 * kill_constant print(str(right_num_revs) + " " + str(left_num_revs)) motors.speed(slave_power, master_power) adjustMotorPowers_straight() readEncoder_straight() print "Slave Speed: " + str(slave_power), "Master Speed: " + str( master_power) except KeyboardInterrupt: break motors.cleanup()
print("Recommended Poll Interval: %dmS\n" % poll_interval) curr_time = time.time() next_state = False while True: try: if(abs(right_num_revs)+abs(left_num_revs))/2.0 >= turns*d_mod and not next_state: #print(str(right_num_revs)+" "+str(left_num_revs)) print slave_power print master_power curr_time=time.time() next_state = True if time.time()>(curr_time + 0) and next_state: break motors.speed(slave_power, master_power) adjustMotorPowers() readEncoder() except KeyboardInterrupt: break motors.speed(0,0) time.sleep(1) encoders.clear() right_num_revs = 0.0 left_num_revs = 0.0 slave_power = 0.25 master_power = 0.25 target_power = 0.6 alpha = .95
import motors motors.init() motors.speed(0,0)
from __future__ import division import motors from time import sleep motors.init() for i in xrange(0, 1000): motors.speed(i / 1000, 0) sleep(0.001) for i in xrange(0, 1000): motors.speed(1, i / 1000) sleep(0.001) for i in xrange(0, 1000): motors.speed(1, 1 - i / 1000) sleep(0.001) for i in xrange(0, 1000): motors.speed(1 - i / 1000, 0) sleep(0.001) motors.cleanup()
import motors motors.init() motors.speed(0, 0)
def go(given_angle, given_distance): angle = given_angle distance = given_distance curr_time = time.time() next_state = False #constants in feet diameter = 11.25 wheel_circumference = 16.72 #right is master, left is slave global slave_power global master_power master_power = .25 slave_power = -.25 global right_num_revs right_num_revs= 0 global left_num_revs left_num_revs = 0 global kp kp = .5 #distance modifier d_mod = .95 turns= angle/360.0*math.pi*diameter/wheel_circumference dist = distance/wheel_circumference encoders.init() encoders.clear() motors.init() global en_right global en_left en_left, en_right = encoders.read() while True: try: if(abs(right_num_revs)+abs(left_num_revs))/2.0 >= turns*d_mod and not next_state: print slave_power print master_power curr_time=time.time() next_state = True if time.time()>(curr_time + 0) and next_state: break motors.speed(slave_power, master_power) adjustMotorPowers() readEncoder() except KeyboardInterrupt: break motors.speed(0,0) time.sleep(1) kill_constant = 5 right_num_revs = 0.0 left_num_revs = 0.0 slave_power = 0.233 master_power = 0.25 while True: if (abs(right_num_revs)+abs(left_num_revs))/2.0 >= dist*d_mod: break try: if(abs(left_num_revs)-abs(right_num_revs)) > kill_threshold: master_power += .95*master_power + .05*kill_constant print(str(right_num_revs)+" "+str(left_num_revs)) motors.speed(slave_power, master_power) adjustMotorPowers_straight() readEncoder_straight() print "Slave Speed: "+str(slave_power), "Master Speed: "+str(master_power) except KeyboardInterrupt: break motors.cleanup()
from __future__ import division import motors from time import sleep motors.init() for i in xrange(0, 1000): motors.speed(i/1000, 0) sleep(0.001) for i in xrange(0, 1000): motors.speed(1, i/1000) sleep(0.001) for i in xrange(0, 1000): motors.speed(1, 1 - i/1000) sleep(0.001) for i in xrange(0, 1000): motors.speed(1 - i/1000, 0) sleep(0.001) motors.cleanup()