|
TinyRobotics
|
Message source for remote control via a virtual gamepad. More...
#include <RCGamepadMessageSource.h>


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< MessageHandlerEntry > | messageHandlers_ |
Message source for remote control via a virtual gamepad.
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();
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.
|
inline |
Call this in your main loop to handle incoming gamepad messages and publish control messages