TinyRobotics
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
RCGamepadMessageSource Class Reference

Message source for remote control via a virtual gamepad. More...

#include <RCGamepadMessageSource.h>

Inheritance diagram for RCGamepadMessageSource:
Inheritance graph
[legend]
Collaboration diagram for RCGamepadMessageSource:
Collaboration graph
[legend]

Public Member Functions

 RCGamepadMessageSource (NetworkServer &server)
 
bool begin (ControlScenario scenario=ControlScenario::Car)
 Start the message source and connect to the gamepad server.
 
void end ()
 Stop the message source and disconnect from the gamepad server.
 
void update ()
 
void setCallback (bool(*cb)(const GamepadState &, MessageSource &source))
 Add a callback to receive and publish additional messages.
 
- Public Member Functions inherited from MessageSource
void subscribe (MessageHandler &handler, MessageOrigin origin=MessageOrigin::Undefined, MessageContent content=MessageContent::Undefined)
 Subscribe a message handler to this source, with optional filtering.
 
void unsubscribeAll ()
 Remove all registered message handlers.
 
void sendMessage (Message< float > &msg)
 Publish a message to all registered handlers.
 
void sendMessage (const Message< Coordinate< float > > &msg)
 Publish a message to all registered handlers.
 
void sendMessage (const Message< GPSCoordinate > &msg)
 Publish a message to all registered handlers.
 
void sendMessage (const Message< MotionState3D > &msg)
 Overload for MotionState3D messages.
 

Protected Member Functions

void publish (const GamepadState &state)
 
void publish (const Message< float > &msg)
 
void publishCar (const GamepadState &state)
 
void publishDrone (const GamepadState &state)
 
void publishPlane (const GamepadState &state)
 
void publishBoat (const GamepadState &state)
 

Protected Attributes

GamepadServer gamepad
 
ControlScenario scenario
 
bool(* callback )(const GamepadState &, MessageSource &source) = nullptr
 
bool is_active_ = false
 
- Protected Attributes inherited from MessageSource
std::vector< MessageHandlerEntrymessageHandlers_
 

Detailed Description

Message source for remote control via a virtual gamepad.

Note
This class depends on the VirtualGamePadArduino library: https://github.com/pschatzmann/VirtualGamePadArduino
this is an optional class, so it must be included in your sketch with: #include "TinyRobotics/communication/RCGamepadMessageSource.h"

This class connects to a GamepadServer and translates gamepad input into TinyRobotics Message objects for remote control scenarios (Car, Boat, etc). It supports different navigation scenarios and publishes control messages (steering, throttle, turn, etc) based on the selected scenario.

Usage: RCGamepadMessageSource source(server); source.begin(NaviationScenario::Car); // In loop: source.update();

Callback Mechanism

You can register a custom callback using setCallback(). The callback is invoked whenever a new GamepadState is received. If the callback returns false, the default message publishing is skipped, allowing you to publish custom messages instead. If the callback returns true (or is not set), the default messages for the selected scenario are published.

Example: source.setCallback([](const GamepadState& state, MessageSource& src) { // Custom message publishing logic return false; // skip default publishing });

The class is designed for integration with the TinyRobotics message bus and remote control framework.

Member Function Documentation

◆ update()

void update ( )
inline

Call this in your main loop to handle incoming gamepad messages and publish control messages


The documentation for this class was generated from the following file: