def main(): print("Robo Sim v2 \n") lSprite=sprite('../sprites/leverSprite.cfg') gSprite=sprite('../sprites/genericSprite.cfg') mSprite=sprite('../sprites/motorSprite.cfg') config=(4,4,6,6) link=gRobot.robot(config) servo0=servos.servo(0) servo1=servos.servo(1) servo2=servos.servo(2) servo3=servos.servo(3) motor0=motors.motor(0,0,1000,0,mSprite) motor1=motors.motor(1,0,1000,0,mSprite) lMot=motors.motor(2,50,1000,0,mSprite) rMot=motors.motor(3,50,1000,0,mSprite) link.addMotors(motor0,motor1) link.addServos(servo0,servo1,servo2,servo3) link.addDriveMotors(lMot,rMot,10) rScreen=interface.robotScreen() print('') try: robot.draw() except NameError: print("Not a valid bot") try: link.enableServos() except NameError: print("Not a valid bot") window=interface.simScreen(1600,900) # # while window.is_open: # window.clear(window.color) # # for event in window.events: # if type(event)==sfml.CloseEvent: # window.close() # # window.draw(lSprite) # # window.display() link.defineContext(window) link.update() print('')
def __init__(self, lMotor1, lMotor2, rMotor1, rMotor2, freq=100): enable, aMotor, bMotor = lMotor1 self.left_motor1 = motor(enable, aMotor, bMotor, freq) enable, aMotor, bMotor = lMotor1 self.left_motor2 = motor(enable, aMotor, bMotor, freq) enable, aMotor, bMotor = rMotor1 self.right_motor1 = motor(enable, aMotor, bMotor, freq) enable, aMotor, bMotor = rMotor2 self.right_motor2 = motor(enable, aMotor, bMotor, freq)
def main(): # test and run the the Robot # motor GPIO Pins GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) StdByPin = 14 # this is the common pin leftMotorPins = [12, 23, 24] # fill up with GPIO pins, PWMA, AIn1, AIn2 rightMotorPins = [13, 25, 26] # same as above leftMotorPins.append(StdByPin) rightMotorPins.append(StdByPin) #Sensor GPIO Pins trig = 4 # common trig pin echo_left = 17 #left sensor echo pin echo_fwd = 27 #forward sensor echo pin echo_right = 22 #right sensor echo pin #button pins button_pin = 18 GPIO.setup(button_pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) #set up motors and sensors Motors = [ motors.motor(leftMotorPins, 'Left'), motors.motor(rightMotorPins, 'Right') ] Sensors = [ sensors.ultrasonic_sensor([trig, echo_left]), sensors.ultrasonic_sensor([trig, echo_fwd]), sensors.ultrasonic_sensor([trig, echo_right]) ] #set up robot PiOde = RobotOne(Motors, Sensors) signal.signal(signal.SIGINT, signal_handler) GPIO.add_event_detect(button_pin, GPIO.RISING, bouncetime=200) GPIO.add_event_callback(button_pin, button_handler) #previous_button_state = False while True: # do forever #button,previous_button_state = buttons.button_pressed(button_pin,previous_button_state) if roaming: PiOde.roam() print('roaming') else: PiOde.stop() print('stopped') GPIO.cleanup()
def main(HOST='', PORT=65432): #HOST is localhost #set up Ctrl C interrupt signal.signal(signal.SIGINT, signal_handler) #Initialise the Board params = load(open('params.yaml').read(), Loader=Loader) GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) StdByPin = params['StdByPin'] # this is the common pin leftMotorPins = params[ 'leftMotorPins'] # fill up with GPIO pins, PWMA, AIn1, AIn2 rightMotorPins = params['rightMotorPins'] # same as above leftMotorPins.append(StdByPin) rightMotorPins.append(StdByPin) #set up motors and sensors Motors = [ motors.motor(leftMotorPins, 'Left'), motors.motor(rightMotorPins, 'Right') ] Sensors = [ sensors.ultrasonic_sensor([params['trig'], params['echo_left']]), sensors.ultrasonic_sensor([params['trig'], params['echo_fwd']]), sensors.ultrasonic_sensor([params['trig'], params['echo_right']]) ] #set up robot PiOde = robots.RobotOne(Motors, Sensors) PiOde.test() #Buttons button_pin = params['button_pin'] GPIO.setup(button_pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) #set up button handling GPIO.add_event_detect(button_pin, GPIO.RISING, bouncetime=200) GPIO.add_event_callback(button_pin, PiOde.toggle_roaming) d = Driver(PiOde, HOST, PORT) sense = threading.Thread(target=d.sense) rx_commands = threading.Thread(target=d.rx_commands) drive = threading.Thread(target=d.drive) sense.start() rx_commands.start() drive.start()
def main(): #test and drive the the Robot with PS3 Controller #set up Ctrl C interrupt signal.signal(signal.SIGINT, signal_handler) #Initialise the Board params = load(open('params.yaml').read(), Loader=Loader) GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) StdByPin = params['StdByPin'] # this is the common pin leftMotorPins = params[ 'leftMotorPins'] # fill up with GPIO pins, PWMA, AIn1, AIn2 rightMotorPins = params['rightMotorPins'] # same as above leftMotorPins.append(StdByPin) rightMotorPins.append(StdByPin) #set up motors and sensors Motors = [ motors.motor(leftMotorPins, 'Left'), motors.motor(rightMotorPins, 'Right') ] Sensors = [ sensors.ultrasonic_sensor([params['trig'], params['echo_left']]), sensors.ultrasonic_sensor([params['trig'], params['echo_fwd']]), sensors.ultrasonic_sensor([params['trig'], params['echo_right']]) ] #set up robot PiOde = robots.RobotOne(Motors, Sensors) #PiOde.test() #Buttons button_pin = params['button_pin'] GPIO.setup(button_pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) #set up button handling #GPIO.add_event_detect(button_pin, GPIO.RISING,callback=lambda x: PiOde.toggle_roaming(), bouncetime = 200) #GPIO.add_event_callback(button_pin, button_handler) ps3drive(PiOde)
leftMotorPins.append(StdByPin) rightMotorPins.append(StdByPin) #Sensor GPIO Pins trig = 19 # common trig pin echo_left = 17 #left sensor echo pin echo_fwd = 4 #forward sensor echo pin echo_right = 16 #right sensor echo pin #button pins button_pin = 18 GPIO.setup(button_pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) #set up motors and sensors Motors = [ motors.motor(leftMotorPins, 'Left'), motors.motor(rightMotorPins, 'Right') ] Sensors = [ sensors.ultrasonic_sensor([trig, echo_left]), sensors.ultrasonic_sensor([trig, echo_fwd]), sensors.ultrasonic_sensor([trig, echo_right]) ] #set up robot PiOde = robots.RobotOne(Motors, Sensors) #set up Ctrl C interrupt signal.signal(signal.SIGINT, signal_handler) #set up button handling
from zumo_button import ZumoButton as btn from motors import Motors as motor from reflectance_sensors import ReflectanceSensors as scanner button = btn() m = motor() def main(): button.wait_for_press() m.forward(speed=0.5, dur=0.5) m.backward(speed=0.5, dur=0.5) main() class MotorObj: def __init__(self): # definer funksjoner for alle sensorene i en dict self.sensors = { Camera: self.react_camera, IRProximitySensor: self.react_IR, ReflectanceSensors: self.react_reflect, Ultrasonic: self.react_ultra } self.current_value = 0 def run(sensor, value): # tar inn en tuppel med sensor, verdi ''' feks: kamera ser at et objekt dekker nesten hele field-of-view (objektet er nært) får da inn en høy verdi i tuppelen, og må feks rygge lengre bak, enn om objektet hadde vært lengre unna '''
def main(): #test and run the the Robot parser = argparse.ArgumentParser(description='Driver for RoboKar') parser.add_argument('--v', default=1.0) parser.add_argument('--w', default=0) parser.add_argument('--testing', default=False) parser.add_argument('--time', default=10) args = parser.parse_args() GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) StdByPin = 22 # this is the common pin leftMotorPins = [12, 23, 24] # fill up with GPIO pins, PWMA, AIn1, AIn2 rightMotorPins = [13, 25, 5] # same as above leftMotorPins.append(StdByPin) rightMotorPins.append(StdByPin) # Cleanup done at exit @atexit.register def cleanup_robot(): if args.testing != 'True': print('EXITING') PiOde.stop() GPIO.cleanup() pass #Sensor GPIO Pins trig = 19 # common trig pin echo_left = 17 #left sensor echo pin echo_fwd = 4 #forward sensor echo pin echo_right = 16 #right sensor echo pin #set up motors and sensors Motors = [ motors.motor(leftMotorPins, 'Left'), motors.motor(rightMotorPins, 'Right') ] Sensors = [ sensors.ultrasonic_sensor([trig, echo_left]), sensors.ultrasonic_sensor([trig, echo_fwd]), sensors.ultrasonic_sensor([trig, echo_right]) ] #set up robot PiOde = RobotOne(Motors, Sensors) #set up Ctrl C interrupt signal.signal(signal.SIGINT, signal_handler) #button pins button_pin = 18 GPIO.setup(button_pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) #set up button handling #GPIO.add_event_detect(button_pin, GPIO.RISING,callback=lambda x: PiOde.toggle_roaming(), bouncetime = 200) #GPIO.add_event_callback(button_pin, button_handler) # Test the Robot #PiOde.set_roaming_on() #while PiOde.is_roaming(): # PiOde.roam() PiOde.command_vel([float(args.v), float(args.w)]) time.sleep(float(args.time))
def __init__(self, tMotor, sMotor, freq=100): enableT, bMotorT, aMotorT = tMotor self.traction_motor = motor(enableT, aMotorT, bMotorT, freq) enable, bMotor, aMotor = sMotor self.steering_motor = motor(enable, aMotor, bMotor, freq)
lock_pin = 17 unlock_pin = 4 pwm_pin = 18 motor_pin = 23 counter = 0 lockid = 0 red_led = 26 blue_led = 20 green_led = 21 manual_button = 12 GPIO.setup(red_led, GPIO.OUT) GPIO.setup(green_led, GPIO.OUT) GPIO.setup(blue_led, GPIO.OUT) db = Database_Connection() manual = False motor1 = motor() def run_motor(channel): global manual manual = True print ('ADASDFSDFASDFLJasdjkafnsdjklfh asjkld sdfhajkl hvzm,xcbvxc') #set pins for input and output GPIO.setup(lock_switch, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(unlock_switch, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(red_led, GPIO.OUT) GPIO.setup(green_led, GPIO.OUT) GPIO.setup(blue_led, GPIO.OUT) GPIO.setup(manual_button, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.add_event_detect(manual_button, GPIO.RISING, callback = run_motor) arduino = arduino_communication()
def main(): parser = argparse.ArgumentParser(description='Web Driver for RoboKar') parser.add_argument('--hostname', default='0.0.0.0') parser.add_argument('--port', default=5000) parser.add_argument('--testing',default=False) args = parser.parse_args() # Cleanup done at exit @atexit.register def cleanup_robot(): if args.testing != 'True': print('EXITING') PiOde.stop() GPIO.cleanup() server.shutdown() pass if args.testing != 'True': # Rpi Sepcific Commands - if not testing import RPi.GPIO as GPIO import sensors import motors import robots params = load(open('params.yaml').read(), Loader=Loader) GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) StdByPin = params['StdByPin'] # this is the common pin leftMotorPins = params['leftMotorPins'] # fill up with GPIO pins, PWMA, AIn1, AIn2 rightMotorPins = params['rightMotorPins'] # same as above leftMotorPins.append(StdByPin) rightMotorPins.append(StdByPin) #set up motors and sensors Motors = [motors.motor(leftMotorPins,'Left'),motors.motor(rightMotorPins,'Right')] Sensors = [sensors.ultrasonic_sensor([params['trig'],params['echo_left']]), sensors.ultrasonic_sensor([params['trig'],params['echo_fwd']]), sensors.ultrasonic_sensor([params['trig'],params['echo_right']])] #set up robot PiOde = robots.RobotOne(Motors,Sensors) #PiOde.test() #Buttons button_pin = params['button_pin'] GPIO.setup(button_pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) #set up button handling GPIO.add_event_detect(button_pin, GPIO.RISING, bouncetime = 200) GPIO.add_event_callback(button_pin, PiOde.toggle_roaming) print('PiOde Set Up Complete') else: PiOde = None # driver instance d = Driver(PiOde,args) #start the threaded processes threading.Thread(target=d.sense,daemon=True).start() #start the flask server app = Flask(__name__) #app.add_url_rule('/','web_interface',d.web_interface) #app.add_url_rule('/read_vel','read_vel',d.read_vel) app.route("/")(d.web_interface) app.route("/read_vel")(d.read_vel) app.route("/stop")(d.stop) app.route("/exit")(lambda:sys.exit(0)) server = ServerThread(app,args) server.start()