whack_a_mole.arduino_hint module

Hint node that receives feedback from the Arduino on which button is lit.

class whack_a_mole.arduino_hint.Hint

Bases: Node

ROS2 Hint Node for serial communication and service interaction.

Responsibilities: - Communicates with an Arduino device over a serial port. - Handles client calls to start a game and process received messages. - Interfaces with the play and toggle_tf_publish services.

Services: - call_play (Empty): Initiates the game and reads serial input from the Arduino.

Clients: - play (TargetFrame): Sends color data for target frames to a service. - toggle_tf_publish (Empty): Toggles the transform publisher.

async call_play_callback(request, response)

Start playing. Callback function for the call_play service.

This function starts the game by: - Sending a start signal (‘s’) to the Arduino over the serial port. - Calling the toggle_tf_publish client asynchronously. - Continuously reading data from the Arduino and interpreting it as color frames. - Passing the interpreted frames to the play service.

Parameters:
  • request (Empty.Request) – An empty request from the call_play service.

  • response (Empty.Response) – An empty response returned to the service caller.

Raises:

Exception – If the game cannot be started or serial communication fails.

Returns:

The response to the service.

Return type:

Empty.Response

connect_serial_port(serial_port, baud_rate)

Configure and opens the serial port for communication with the Arduino device.

Parameters:
  • serial_port (str) – The name of the serial port to connect to.

  • baud_rate (int) – The baud rate for serial communication.

async read_serial_data()

Read serial data from the Arduino device.

This function continuously reads from the serial port until valid data (0, 1, 2, or 3) is received.

Returns:

A message containing the valid serial data read from the device.

Return type:

String

Raises:

Exception – If there is an error reading data from the serial port.

whack_a_mole.arduino_hint.hint_main(args=None)

Entry point for starting the Hint node.

Parameters:

args (list or NoneType) – Optional command-line arguments passed to the ROS2 program.