:param my_board: an pymata express instance :param trigger_pin: Arduino pin number :param echo_pin: Arduino pin number :param callback: The callback function """ # set the pin mode for the trigger and echo pins await my_board.set_pin_mode_sonar(trigger_pin, echo_pin, callback) # wait forever while True: try: await asyncio.sleep(.01) except KeyboardInterrupt: await my_board.shutdown() sys.exit(0) # get the event loop loop = asyncio.get_event_loop() # instantiate pymata_express board = telemetrix_aio.TelemetrixAIO() try: # start the main function loop.run_until_complete(sonar(board, TRIGGER_PIN, ECHO_PIN, the_callback)) except KeyboardInterrupt: loop.run_until_complete(board.shutdown()) sys.exit(0)
This function will request that the supplied characters be sent to the board and looped back and printed out to the console. :param my_board: a pymata4 instance :param loop_back_data: A list of characters to have looped back """ try: for data in loop_back_data: await my_board.loop_back(data, callback=the_callback) print(f'Sending: {data}') await asyncio.sleep(1) except KeyboardInterrupt: my_board.shutdown() sys.exit(0) # get the event loop loop = asyncio.get_event_loop() # instantiate pymata_express board = telemetrix_aio.TelemetrixAIO(ip_address='192.168.2.220') char_list = ['A', 'B', 'Z'] try: # start the main function loop.run_until_complete(loop_back(board, char_list)) loop.run_until_complete(board.shutdown()) except KeyboardInterrupt: loop.run_until_complete(board.shutdown()) sys.exit(0)
os.kill(os.getpid(), signal.SIGINT) if __name__ == "__main__": loop = asyncio.get_event_loop() # Catch signals to exit properly # We need to do it this way instead of usgin the try/catch # as in the telemetrix examples signals = (signal.SIGHUP, signal.SIGTERM, signal.SIGINT) for s in signals: loop.add_signal_handler( s, lambda: asyncio.ensure_future(shutdown(s, loop, board))) # Initialize the telemetrix board board = telemetrix_aio.TelemetrixAIO(loop=loop) # Initialize the ROS node as anonymous since there # should only be one instnace running. rospy.init_node("zoef_telemetrix", anonymous=False, disable_signals=False) rospy.on_shutdown(send_sigint) # Start all tasks for sensors and actuators device = "zoef" sensor_tasks = sensors(loop, board, device) actuator_tasks = actuators(loop, board, device) all_tasks = sensor_tasks + actuator_tasks for task in all_tasks: loop.run_until_complete(task) # Should not be: loop.run_forever() or rospy.spin()