def setUpClass(): VirtualJoystickTest.joystick0 = Joystick(MOTOR_JOYSTICK_ID) VirtualJoystickTest.motors = Wheelbase(left=LEFT_MOTOR_ID, right=RIGHT_MOTOR_ID) VirtualJoystickTest.motors.source = steering_mixer( VirtualJoystickTest.joystick0.values) #VirtualJoystickTest.motors.source_delay = 0.1 VirtualJoystickTest.joystick1 = Joystick(PANTILT_JOYSTICK_ID) VirtualJoystickTest.pan_tilt = PanTilt(pan=PAN_SERVO_ID, tilt=TILT_SERVO_ID) VirtualJoystickTest.pan_tilt.source = scaled_pair( VirtualJoystickTest.joystick1.values, MAX_ANGLE, MIN_ANGLE, JOY_AXIS_MIN, JOY_AXIS_MAX) #VirtualJoystickTest.pan_tilt.source_delay = 0.1 # Setup Selenium capabilities = DesiredCapabilities.CHROME capabilities['loggingPrefs'] = {'browser': 'ALL'} if VirtualJoystickTest.IS_CI_BUILD: username = environ["SAUCE_USERNAME"] access_key = environ["SAUCE_ACCESS_KEY"] capabilities["tunnel-identifier"] = environ["TRAVIS_JOB_NUMBER"] capabilities["build"] = environ["TRAVIS_BUILD_NUMBER"] capabilities["tags"] = [environ["TRAVIS_PYTHON_VERSION"], "CI"] hub_url = "%s:%s@localhost:4445" % (username, access_key) VirtualJoystickTest.driver = webdriver.Remote( desired_capabilities=capabilities, command_executor="http://%s/wd/hub" % hub_url) else: #DRIVER = webdriver.Safari() # see: http://elementalselenium.com/tips/69-safari #DRIVER = webdriver.Chrome() # see: https://sites.google.com/a/chromium.org/chromedriver/downloads VirtualJoystickTest.driver = webdriver.Chrome( desired_capabilities=capabilities) VirtualJoystickTest.driver.implicitly_wait(BROWSER_WAIT_SECONDS) VirtualJoystickTest.driver.maximize_window() VirtualJoystickTest.driver.get("http://localhost:8000/") VirtualJoystickTest.canvas = VirtualJoystickTest.driver.find_element_by_id( "camera_view") VirtualJoystickTest.fake_set_speed_called_values = [ OccuranceRecorder(allow_repeating_items=False), OccuranceRecorder(allow_repeating_items=False) ] VirtualJoystickTest.fake_set_angle_called_values = [ OccuranceRecorder(allow_repeating_items=False), OccuranceRecorder(allow_repeating_items=False) ]
#!/usr/bin/python3 from picraftzero import Joystick, Wheelbase, steering_mixer, start # Joystick axis range is: (left/down) -100 .. 100 (right/up) # Motors value range is: (full speed backwards) -100 .. 100 (full speed forwards) joystick = Joystick( ) # use the first available controller (e.g. Rock Candy, XBox360) or web client tiny4wd_motors = Wheelbase( left=1, right=0 ) # left,right = logical id of i2c motor (auto-detected Explorer pHAT or PiConZero) # Connect the motor speeds (left, right) to the joysticks axes (x,y), via a 'steering mixer' tiny4wd_motors.source = steering_mixer(joystick.values) start()
#!/usr/bin/env python # coding: Latin-1 # Load library functions we want # based on an example from https://github.com/thymjan from picraftzero import Joystick, Wheelbase, steering_mixer, start from picraftzero.thirdparty.pimoroni.explorerhat import output # instead of: from explorerhat import output joystick = Joystick( ) # use the first available controller (e.g. Rock Candy, XBox360) or web client motors = Wheelbase( left=1, right=0 ) # left,right = logical id of i2c motor (auto-detected Explorer pHAT or PiConZero) motors.source = steering_mixer( joystick.values) # convert joystick axis to motor speeds output.one.on() output.two.on() try: print('Press CTRL+C to quit') start() except KeyboardInterrupt: output.one.off() output.two.off() print("bye")
#!/usr/bin/python3 # To install and setup pairing see: http://bluedot.readthedocs.io/en/latest/gettingstarted.html # Add the following to either: ~/.picraftzero.cfg or /etc/picraftzero.cfg # [joystick] # use_bluedot=yes # The following is exactly the same as the tiny4wd.py example, just with much less commenting here. from picraftzero import Joystick, Wheelbase, steering_mixer, start # use the first available controller joypad, webclient or BlueDot if installed and enabled in config joystick = Joystick() motors = Wheelbase(left=1, right=0) motors.source = steering_mixer(joystick.values) start()
from picraftzero.config import get_config config = get_config() script_file = config.get('service', 'script', fallback=None) if script_file: logger.info("Running user script: {}".format(script_file)) with open(script_file) as f: code = compile(f.read(), script_file, 'exec') exec(code) # user script is expected to exit with an error code or 0, so shouldnt reach here exit(1) # see the `pantilt.py` example for more info. from picraftzero import Wheelbase, PanTilt, Joystick, steering_mixer, scaled_pair, start, filter_messages, MessageReceiver, join_values joystick_right = Joystick(0) joystick_left = Joystick(1) messages = MessageReceiver(port=8001) wheelbase = Wheelbase(left=1, right=0) pan_tilt = PanTilt(pan=0, tilt=1) wheelbase.source = steering_mixer(joystick_right.values) pan_tilt.source = join_values( filter_messages(messages.values, type='PANTILT', id=0), scaled_pair(joystick_left.values, 180, 0, -100, 100)) if __name__ == '__main__': start()
# The (WebSocket) Messages are a simple dictionary with keys of: # 'type' => message type, e.g. 'JOYSTICK' # 'id' => a logical numeric identifier, e.g. 0 = 1st (or right hand side) joystick, 1 = 2nd etc.... # 'data' => an array so it can easily be used as a tuple for later source/value processing #messages = MessageReceiver() # Find joysticks/thumbsticks for speed controll and pan/tilt control # First parameter is a logical id where 0 = right stick, 1 = left stick # Defaults to joysticks/thumbpads on the first connected controller found joystick_right= Joystick(0) joystick_left = Joystick(1) #joystick_messages = MessageEmitter(messages, type='JOYSTICK', id=0) wheelbase = Wheelbase(left=0, right=1) # left/right: logical id of i2c motor (auto-detected Explorer pHAT or PiConZero) pan_tilt = PanTilt(pan=0, tilt=1) # pan/tilt : logical id of i2c servo (auto-detected PanTilt HAT or PiConZero) # The demo Web app has 2 virtual joysticks (id's 0 & 1) that support mouse (desktop) & touch (mobile) # Joystick axis values are (left/down) -100 .. 100 (right/up) # testing printer = SourcePrinter() printer2 = SourcePrinter() def print_local_joystick():
# Find joysticks/thumbsticks for speed controll and pan/tilt control # First parameter is a logical id where 0 = right stick, 1 = left stick # Defaults to joysticks/thumbpads on the first controller found # The joysticks could be on a 'physical' controller (e.g. Rock Candy) or a virtual joystick on the webapp # The demo Web app has 2 virtual joysticks (id's 0 & 1) that support mouse (desktop) & touch (mobile) # Joystick axis values are (left/down) -100 .. 100 (right/up) joystick_right = Joystick(0) joystick_left = Joystick(1) messages = MessageReceiver(port=8001) # Motor assume for left and right: (full speed backwards) -100 .. 100 (full speed forwards) wheelbase = Wheelbase( left=1, right=0 ) # left/right= logical id of i2c motor (auto-detected Explorer pHAT or PiConZero) pan_tilt = PanTilt( pan=0, tilt=1 ) # pan/tilt = logical id of i2c servo (auto-detected PanTilt HAT or PiConZero) # Connect the motor speeds (a,b) to the joysticks axis (x,y), via conversion wheelbase.source = steering_mixer(joystick_right.values) pan_tilt.source = join_values( filter_messages(messages.values, type='PANTILT', id=0), scaled_pair(joystick_left.values, 180, 0, -100, 100)) start()