print format % tuple(vs_l) def print_help(): print "R1: Depth up R2: Depth down" print "Button1: Zero thrusters Button3: Print variables" print "Button4: Emergency breech (requires confirmation)" print "Left Joystick: Navigate" print "Button9: Help Button10: Quit" print sw.loadConfig("../conf/seawolf.conf") sw.init("Joystick Controller") yaw_heading = sw3.data.imu.yaw() devices = joystick.get_devices() if len(devices) == 0: sys.stderr.write("No joysticks found\n") sys.exit(1) depth_heading = 0 forward_heading = 0 rate_limiter = ratelimit.RateLimiter(10, update_axis) js = joystick.Joystick(devices[0], joystick.LOGITECH) print_help() while True: event = js.poll() if isinstance(event, joystick.Axis):
for vs in values: vs_l = reduce(lambda x, y: x + list(y), zip(max_widths, vs), []) print format % tuple(vs_l) def print_help(): print "Look at the button labels for help." print sw.loadConfig("../conf/seawolf.conf") sw.init("Steering Wheel Controller") yaw_heading = sw3.data.imu.yaw() devices = joystick.get_devices() if len(devices) == 0: sys.stderr.write("No joysticks found\n") sys.exit(1) depth_heading = 0 rate_limiter = ratelimit.RateLimiter(10, update_axis) js = joystick.Joystick(devices[0], joystick.STEERINGWHEEL) print_help() while True: event = js.poll() if isinstance(event, joystick.Axis): if event.name == "wheelAndThrottle":
def main(): sw.loadConfig("../conf/seawolf.conf") sw.init("Joystick Controller") # parse arguments global DEPTH_HOLD global ORIENTATION_HOLD parser = setup_parser() args = parser.parse_args() joystick_name = args.selected_controller DEPTH_HOLD = args.depth_hold ORIENTATION_HOLD= args.orientation_hold # get heading initial heading values yaw_heading = sw3.data.imu.yaw() depth_heading = 0 forward_heading = 0 # instantiate pnuematics controller peripheral = Peripherals() # instantiate joystick class devices = joystick.get_devices() if len(devices) == 0: sys.stderr.write("No joysticks found\n") sys.exit(1) js = joystick.Joystick(devices[0], joystick.LOGITECH) # attach functions to analog sticks Lrate_limiter = ratelimit.RateLimiter(10, update_Laxis) Rrate_limiter = ratelimit.RateLimiter(10, update_Raxis) # splash screen usage-prints print_help() peripheral.printActive() while True: event = js.poll() if isinstance(event, joystick.Axis): if (event.name == "leftStick") : Lrate_limiter.provide(event) elif (event.name=="rightStick"): Rrate_limiter.provide(event) elif event.name == "hat": if event.x < 0: # yaw_heading = sw3.util.add_angle(yaw_heading, -2.5) # sw3.pid.yaw.heading = yaw_heading pass elif event.x > 0: # yaw_heading = sw3.util.add_angle(yaw_heading, 2.5) # sw3.pid.yaw.heading = yaw_heading pass elif event.y < 0: # forward_heading = FORWARD_SPEED # sw3.nav.do(sw3.Forward(forward_heading)) pass elif event.y > 0: # forward_heading = -FORWARD_SPEED # sw3.nav.do(sw3.Forward(forward_heading)) pass else: # forward_heading = 0 # sw3.nav.do(sw3.Forward(forward_heading)) pass elif event.value == 1: if event.name == "button1": print "Zeroing thrusters (and depth heading)" sw3.nav.do(sw3.ZeroThrusters()) depth_heading = 0 elif event.name == "button2": peripheral.fire() elif event.name == "button3": variables = "Depth", "DepthPID.Heading", "SEA.Yaw", "YawPID.Heading" print_table(variables, ["%.2f" % sw.var.get(v) for v in variables]) print variables = "Port", "Star", "Bow", "Stern", "StrafeT", "StrafeB" print_table(variables, ["%.2f" % sw.var.get(v) for v in variables]) print elif event.name == "button4": while js.poll().name != "button4": pass print "Press again to confirm breech" if js.poll().name == "button4": print "Breeching!" sw3.nav.do(sw3.EmergencyBreech()) depth_heading = 0 else: print "Canceled." elif event.name == "button5": peripheral.next() peripheral.printActive() elif event.name == "button6": if DEPTH_HOLD: depth_heading = max(0, depth_heading - 0.50) sw3.pid.depth.heading = depth_heading else: print("Depth holding disabled!!! ignoring depth-change command.") elif event.name == "button7": peripheral.prev() peripheral.printActive() elif event.name == "button8": if DEPTH_HOLD: depth_heading = min(16, depth_heading + 0.50) sw3.pid.depth.heading = depth_heading else: print("Depth holding disabled!!! ignoring depth-change command.") elif event.name == "button9": print_help() elif event.name == "button10": print "Quitting" sw3.nav.do(sw3.ZeroThrusters()) break elif event.name == "leftStickButton": if ORIENTATION_HOLD: print "Reseting Orientation" thruster_request('Yaw', 0, hold_orientation=True) thruster_request('Pitch', 0, hold_orientation=True, auto_level=True) thruster_request('Roll', 0, hold_orientation=True, auto_level=True) sw.close()
def main(): sw.loadConfig("../conf/seawolf.conf") sw.init("Joystick Controller") yaw_heading = sw3.data.imu.yaw() devices = joystick.get_devices() peripheral = Peripherals() if len(devices) == 0: sys.stderr.write("No joysticks found\n") sys.exit(1) depth_heading = 0 forward_heading = 0 Lrate_limiter = ratelimit.RateLimiter(10, update_Laxis) Rrate_limiter = ratelimit.RateLimiter(10, update_Raxis) js = joystick.Joystick(devices[0], joystick.LOGITECH) print_help() peripheral.printActive() while True: event = js.poll() if isinstance(event, joystick.Axis): if (event.name == "leftStick") : Lrate_limiter.provide(event) elif (event.name=="rightStick"): Rrate_limiter.provide(event) elif event.name == "hat": if event.x < 0: yaw_heading = sw3.util.add_angle(yaw_heading, -2.5) sw3.pid.yaw.heading = yaw_heading elif event.x > 0: yaw_heading = sw3.util.add_angle(yaw_heading, 2.5) sw3.pid.yaw.heading = yaw_heading elif event.y < 0: forward_heading = FORWARD_SPEED sw3.nav.do(sw3.Forward(forward_heading)) elif event.y > 0: forward_heading = -FORWARD_SPEED sw3.nav.do(sw3.Forward(forward_heading)) else: forward_heading = 0 sw3.nav.do(sw3.Forward(forward_heading)) elif event.value == 1: if event.name == "button8": depth_heading = min(8, depth_heading + 0.50) sw3.pid.depth.heading = depth_heading elif event.name == "button6": depth_heading = max(0, depth_heading - 0.50) sw3.pid.depth.heading = depth_heading elif event.name == "button1": print "Zeroing thrusters" sw3.nav.do(sw3.ZeroThrusters()) depth_heading = 0 elif event.name == "button4": while js.poll().name != "button4": pass print "Press again to confirm breech" if js.poll().name == "button4": print "Breeching!" sw3.nav.do(sw3.EmergencyBreech()) depth_heading = 0 else: print "Canceled." elif event.name == "button9": print_help() elif event.name == "button3": variables = "Depth", "DepthPID.Heading", "SEA.Yaw", "YawPID.Heading" print_table(variables, ["%.2f" % sw.var.get(v) for v in variables]) print variables = "Port", "Star", "Bow", "Stern", "StrafeT", "StrafeB" print_table(variables, ["%.2f" % sw.var.get(v) for v in variables]) print elif event.name == "button10": print "Quitting" sw3.nav.do(sw3.ZeroThrusters()) break elif event.name == "button5": peripheral.next() peripheral.printActive() elif event.name == "button7": peripheral.prev() peripheral.printActive() elif event.name == "button2": peripheral.fire() sw.close()
def main(): sw.loadConfig("../conf/seawolf.conf") sw.init("Joystick Controller") # parse arguments global DEPTH_HOLD global ORIENTATION_HOLD parser = setup_parser() args = parser.parse_args() joystick_name = args.selected_controller DEPTH_HOLD = args.depth_hold ORIENTATION_HOLD = args.orientation_hold # get heading initial heading values yaw_heading = sw3.data.imu.yaw() depth_heading = 0 forward_heading = 0 # instantiate pnuematics controller peripheral = Peripherals() # instantiate joystick class devices = joystick.get_devices() if len(devices) == 0: sys.stderr.write("No joysticks found\n") sys.exit(1) js = joystick.Joystick(devices[0], joystick.LOGITECH) # attach functions to analog sticks Lrate_limiter = ratelimit.RateLimiter(10, update_Laxis) Rrate_limiter = ratelimit.RateLimiter(10, update_Raxis) # splash screen usage-prints print_help() peripheral.printActive() while True: event = js.poll() if isinstance(event, joystick.Axis): if (event.name == "leftStick"): Lrate_limiter.provide(event) elif (event.name == "rightStick"): Rrate_limiter.provide(event) elif event.name == "hat": if event.x < 0: # yaw_heading = sw3.util.add_angle(yaw_heading, -2.5) # sw3.pid.yaw.heading = yaw_heading pass elif event.x > 0: # yaw_heading = sw3.util.add_angle(yaw_heading, 2.5) # sw3.pid.yaw.heading = yaw_heading pass elif event.y < 0: # forward_heading = FORWARD_SPEED # sw3.nav.do(sw3.Forward(forward_heading)) pass elif event.y > 0: # forward_heading = -FORWARD_SPEED # sw3.nav.do(sw3.Forward(forward_heading)) pass else: # forward_heading = 0 # sw3.nav.do(sw3.Forward(forward_heading)) pass elif event.value == 1: if event.name == "button1": print "Zeroing thrusters (and depth heading)" sw3.nav.do(sw3.ZeroThrusters()) depth_heading = 0 elif event.name == "button2": peripheral.fire() elif event.name == "button3": variables = "Depth", "DepthPID.Heading", "SEA.Yaw", "YawPID.Heading" print_table(variables, ["%.2f" % sw.var.get(v) for v in variables]) print variables = "Port", "Star", "Bow", "Stern", "StrafeT", "StrafeB" print_table(variables, ["%.2f" % sw.var.get(v) for v in variables]) print elif event.name == "button4": while js.poll().name != "button4": pass print "Press again to confirm breech" if js.poll().name == "button4": print "Breeching!" sw3.nav.do(sw3.EmergencyBreech()) depth_heading = 0 else: print "Canceled." elif event.name == "button5": peripheral.next() peripheral.printActive() elif event.name == "button6": if DEPTH_HOLD: depth_heading = max(0, depth_heading - 0.50) sw3.pid.depth.heading = depth_heading else: print( "Depth holding disabled!!! ignoring depth-change command." ) elif event.name == "button7": peripheral.prev() peripheral.printActive() elif event.name == "button8": if DEPTH_HOLD: depth_heading = min(16, depth_heading + 0.50) sw3.pid.depth.heading = depth_heading else: print( "Depth holding disabled!!! ignoring depth-change command." ) elif event.name == "button9": print_help() elif event.name == "button10": print "Quitting" sw3.nav.do(sw3.ZeroThrusters()) break elif event.name == "leftStickButton": if ORIENTATION_HOLD: print "Reseting Orientation" thruster_request('Yaw', 0, hold_orientation=True) thruster_request('Pitch', 0, hold_orientation=True, auto_level=True) thruster_request('Roll', 0, hold_orientation=True, auto_level=True) sw.close()