def turn_right(): motors.enable() if not disable_motor_flag: motors.setSpeeds(-turn_motor_speed, turn_motor_speed) time.sleep(motor_turn_time) motors.setSpeeds(0, 0) motors.disable()
def main(): motors.enable() motors.setSpeeds(0, 0) inp = "" while inp != "q": try: inp = input("f, b, s, or q: ") except: print("\nNo fun exiting") motors.setSpeeds(0, 0) motors.disable() sys.exit(0) if inp == "f": motors.motor1.setSpeed(-480) elif inp == "b": motors.motor1.setSpeed(480) elif inp == "s": motors.motor1.setSpeed(0) elif inp == "q": motors.setSpeeds(0, 0) motors.disable() sys.exit(0) else: print("nope")
def main(): global bus global busloc initsensor(bus, busloc) timezone = pytz.timezone(STRTZ) motors.enable() motors.setSpeeds(0, 0) inp = "" while inp != "q": cur_pos = mydeg(get_pos()) try: inp = input("Current Angle: %s - a, f, b, s, or q: " % cur_pos) except: print("\nNo fun exiting") motors.setSpeeds(0, 0) motors.disable() sys.exit(0) if inp == "f": motors.motor1.setSpeed(-480) elif inp == "b": motors.motor1.setSpeed(480) elif inp == "s": motors.motor1.setSpeed(0) elif inp == "q": motors.setSpeeds(0, 0) motors.disable() sys.exit(0) elif inp == "a": print( "Oh cool, you want to set an angle! Type it here, oh, use whole numbers for now" ) print("") myangle = input( "Set a whole number angle between %s (East) and %s (West): " % (EAST_ANGLE, WEST_ANGLE)) if 1 == 1: ang = int(myangle) print("Using %s as your angle (you entered %s, we int() it)" % (ang, myangle)) print("Setting Now") goto_angle(ang) print("Set complete") print("") else: print("We couldn't int your angle, ignoring you for now") continue else: print("nope")
motors.motor1.setSpeed(-MAX_SPEED) raiseIfFault() #Forward halfspeed elif keyboard.is_pressed("e"): #print("\n backward (w)") motors.enable() motors.motor1.setSpeed(-halfspeed) raiseIfFault() elif keyboard.is_pressed("p"): #print("\n backward (w)") motors.enable() motors.motor2.setSpeed(MAX_SPEED) raiseIfFault() elif keyboard.is_pressed("b"): #print("\n backward (w)") motors.enable() motors.motor2.setSpeed(MAX_SPEED) raiseIfFault() #Stop else: #print("\n no input") motors.disable() except: #print("shouldn't see this") #break # if user pressed a key other than the given key, break time.sleep(0.05)
def key_rover(ch,prev_ch,motorspeed,motors_enabled): #check if this is the first time executing this function while ch: print ch #Rover Motors Re-Enable if ch == 'h': if motors_enabled == False: motors.enable() motors_enabled = True print ('Rover Motors Enabled. To disable, press \';\'') #Don't allow any other input until motors re-enabled elif motors_enabled == False: print ('Rover Motors Disabled. To enable, press \'h\'') #Rover Motors Disable elif ch == ';': if motors_enabled == True: motors.disable() motors_enabled = False print ('Rover Motors Disabled. To enable, press \'h\'') #Rover Forward elif ch == 'i': print ('Rover Forward') motors.setSpeeds(motorspeed,motorspeed) #Rover Backward elif ch == 'k': print ('Rover Backward') motors.setSpeeds(-motorspeed,-motorspeed) #Rover Pivot Right elif ch == 'l': print ('Rover Pivot Right') motors.setSpeeds(motorspeed,-motorspeed) #Rover Pivot Left elif ch == 'j': print ('Rover Pivot Left') motors.setSpeeds(-motorspeed,motorspeed) #Rover Speed Up elif ch == 'o': #check that the motorspeed is not MAX_SPEED if(motorspeed == MAX_SPEED): print ('Rover is at maximum defined speed of %d.', motorspeed) else: motorspeed = motorspeed + SPEED_INTERVAL; #check if the increase put motorspeed over MAX_SPEED & correct if(motorspeed >= MAX_SPEED): motorspeed == MAX_SPEED print ('Rover Speed Up: %d', motorspeed) #Rover Slow Down elif ch == 'u': #check that the motorspeed is not 0 if(motorspeed == 0): print ('Rover is at minimum speed of %d.', motorspeed) else: motorspeed = motorspeed - SPEED_INTERVAL; #check if the decrease put motorspeed under 0 & correct if(motorspeed <= 0): motorspeed == 0 print ('Rover Slow Down: %d', motorspeed) #Rover stop if no key input else: motors.setSpeeds(0, 0) print ('Rover Stop') prev_ch = 'Stopped' return motorspeed, motors_enabled
def index(): return 'Go away.' motors.disable()
motors.setSpeeds(0, 0) #Keagan guaranteeing motors are stopped print msg #initialize ROS node #Wait for initialization to finish #Keagan -- is this where I should place my operating code? print('Send commands to rover now...') while True: ch = getch() print ch #Exit if ch == '\x03': motors.disable() rover_enabled = False exit(0) #Keagan--should this become break so that some # code can still execute? #Re-enabling motors if ch == 'h': if rover_enabled == False: rover_enabled = True motors.enable() motors.setSpeeds(0, 0) print('Motors Re-enabled. To disable, press \';\'') #Operate Rover if key_held(ch, prev_ch) == False: if rover_enabled == True:
def key_rover(ch, prev_ch): #check if this is the first time executing this function if first_execute == True: prev_ch = 'placeholder' first_execute = False while ch: print ch #Rover Forward if ch == 'i': rospy.loginfo('Rover Forward') motors.setSpeed(motorspeed, motorspeed) #Rover Backward elif ch == 'k': rospy.loginfo('Rover Backward') motors.setSpeed(-motorspeed, -motorspeed) #Rover Pivot Right elif ch == 'l': rospy.loginfo('Rover Pivot Right') motors.setSpeed(motorspeed, -motorspeed) #Rover Pivot Left elif ch == 'j': rospy.loginfo('Rover Pivot Left') motors.setSpeed(-motorspeed, motorspeed) #Rover Speed Up elif ch == 'o': #check that the motorspeed is not MAX_SPEED if (motorspeed == MAX_SPEED): rospy.loginfo('Rover is at maximum defined speed of %d.', motorspeed) else: motorspeed = motorspeed + SPEED_INTERVAL #check if the increase put motorspeed over MAX_SPEED & correct if (motorspeed >= MAX_SPEED): motorspeed == MAX_SPEED rospy.loginfo('Rover Speed Up: %d', motorspeed) #Rover Slow Down elif ch == 'u': #check that the motorspeed is not 0 if (motorspeed == 0): rospy.loginfo('Rover is at minimum speed of %d.', motorspeed) else: motorspeed = motorspeed - SPEED_INTERVAL #check if the decrease put motorspeed under 0 & correct if (motorspeed <= 0): motorspeed == 0 rospy.loginfo('Rover Slow Down: %d', motorspeed) #Rover Motors Disable elif ch == ';': if motors_enabled == True: motors.disable() motors_enabled = False rospy.loginfo('Rover Motors Disabled. To enable, press \'p\'') #Rover stop if no key input else: motors.setSpeed(0, 0) rospy.loginfo('Rover Stop') prev_ch = 'Stopped' return None
def shut_motors(self): motors.setSpeeds(0, 0) motors.disable()