def triple_input_pantilt_scaling_no_conversion():

    pan_tilt.source = join_values(
        filter_messages(messages.values, type='JOYSTICK', id=1),
        filter_messages(messages.values, type='PANTILT', id=0),
        scaled_pair(joystick_left.values, 0, 180, -100, 100),
    )
def triple_input_filter():
    printer.name = "triple_input_filter"

    printer.source = join_values(
        joystick_left.values,
        filter_messages(messages.values, type='JOYSTICK', id=1),
        filter_messages(messages.values, type='PANTILT', id=0),
    )
def simple_robot_dual_joystick():
    wheelbase.source = steering_mixer(join_values(
        joystick_right.values,
        filter_messages(messages.values, type='JOYSTICK', id=0))
    )
    pan_tilt.source  = pantilt_converter(join_values(
        joystick_left.values,
        filter_messages(messages.values, type='JOYSTICK', id=1)))
def triple_input_filter_all_input_scaled():
    printer.name = "triple_input_filter_all_input_scaled"

    printer.source = join_values(
        scaled_pair(joystick_left.values, -10, 10, -100, 100),
        scaled_pair(filter_messages(messages.values, type='JOYSTICK', id=0), -50, 50, -100, 100),
        scaled_pair(filter_messages(messages.values, type='JOYSTICK', id=1), -10, 10, -100, 100),
    )
def print_pantilt_three_combined_streams():
    # Map input values from local and remote joysticks (scaled)
    # Accepts remote 'PANTILT' messages that  (scaling not required)
    printer.name = "print_pantilt_three_combined_streams"
    printer.source = join_values(
        scaled_pair(joystick_left.values, 0, 180, -100, 100),
        scaled_pair(filter_messages(messages.values, type='JOYSTICK', id=1), 0, 180, -100, 100),
        filter_messages(messages.values, type='PANTILT', id=0)
    )
def dual_joystick_wheelbase_pantilt():
    wheelbase.source = join_values(
        joystick_right.values,
        filter_messages(messages.values, type='JOYSTICK', id=0),
    )

    pan_tilt.source = join_values(
        joystick_left.values,
        filter_messages(messages.values, type='JOYSTICK', id=1),
    )
def robot():
    wheelbase.source = steering_mixer(
        join_values(
            filter_messages(messages.values, type='JOYSTICK', id=0),
            joystick_right.values
        )
    )

    pan_tilt.source = join_values(
        filter_messages(messages.values, type='PANTILT', id=0),
        scaled_pair(
            join_values(joystick_left.values, filter_messages(messages.values, type='JOYSTICK', id=1)), 180, 0, -100, 100),
        # filter_messages(messages.values, type='PANTILT', id=0),
        # scaled_pair(joystick_left.values, 0, 180, -100, 100),
        # scaled_pair(filter_messages(messages.values, type='JOYSTICK', id=1), 0, 180, -100, 100),
    )
def mock_robot():
    printer.name = "mock_robot___WHEELS"

    printer.source = steering_mixer(
        join_values(
            filter_messages(messages.values, type='JOYSTICK', id=0),
            joystick_right.values
        )
    )

    printer2.name = "mock_robot__PANTILT"

    printer2.source = join_values(
        filter_messages(messages.values, type='PANTILT', id=0),
        scaled_pair(
            join_values(joystick_left.values, filter_messages(messages.values, type='JOYSTICK', id=1)), 180, 0, -100, 100),
        )
def dual_triple_input_filter_all_input_scaled_pantilt_conversion():
    printer.name = "dual_triple_input_filter_all_input_scaled_pantilt_conversion__ONE"

    printer.source = pantilt_converter(
        join_values(
            scaled_pair(joystick_left.values, -10, 10, -100, 100),
            scaled_pair(filter_messages(messages.values, type='JOYSTICK', id=0), -50, 50, -100, 100),
            scaled_pair(filter_messages(messages.values, type='JOYSTICK', id=1), -10, 10, -100, 100),
        )
    )

    printer2.name = "dual_triple_input_filter_all_input_scaled_pantilt_conversion__TWO"
    printer2.source = pantilt_converter(
        join_values(
            scaled_pair(joystick_left.values, -10, 10, -100, 100),
            scaled_pair(filter_messages(messages.values, type='JOYSTICK', id=0), -50, 50, -100, 100),
            scaled_pair(filter_messages(messages.values, type='JOYSTICK', id=1), -10, 10, -100, 100),
        )
    )
def mock_robot_builtin_pantilt_conversion():
    printer.name = "mock_robot_builtin_pantilt_conversion___WHEELS"

    printer.source = steering_mixer(
        join_values(
            filter_messages(messages.values, type='JOYSTICK', id=0),
            joystick_right.values
        )
    )

    printer2.name = "mock_robot_builtin_pantilt_conversion__PANTILT"

    printer2.source = join_values(
        filter_messages(messages.values, type='PANTILT', id=0),
        pantilt_converter(
            join_values(
                scaled_pair(joystick_left.values, -10, 10, -100, 100),
                filter_messages(messages.values, type='JOYSTICK', id=1),
            )
        )
    )
Beispiel #11
0
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()
def print_combined_joysticks(joystick_id = 0):
    printer.name = "print_combined_joysticks"
    printer.source = join_values(filter_messages(messages.values, type='JOYSTICK', id=joystick_id),  joystick_right.values)
def print_remote_joystick(joystick_id = 0):
    printer.name = "print_remote_joystick"
    printer.source = filter_messages(messages.values, type='JOYSTICK', id=joystick_id)
def dual_joystick_pantilt():

    pan_tilt.source = join_values(
        joystick_left.values,
        filter_messages(messages.values, type='JOYSTICK', id=1),
    )
def dual_joystick_wheelbase():
    wheelbase.source = join_values(
        joystick_right.values,
        filter_messages(messages.values, type='JOYSTICK', id=0),
    )
def remote_joystick_pantilt():
    pan_tilt.source = pantilt_converter(filter_messages(messages.values, type='JOYSTICK', id=1))
def remote_joystick_wheelbase():
    wheelbase.source = steering_mixer(filter_messages(messages.values, type='JOYSTICK', id=0) )