|
|
| MotionController2D (IMotionState2D &motionState, float maxSpeedKmh=10, float maxSteeringAngleDeg=30.0f, float accelDistanceM=2.0f) |
| |
|
| MotionController2D (IMotionState2D &motionState, Speed maxSpeedKmh, Angle maxSteeringAngle, Distance accelDistanceM) |
| |
| void | configureSpeedPID (float minOut, float maxOut, float kp, float ki, float kd) |
| | Configure the PID controller for speed-to-throttle mapping.
|
| |
| void | configureSteeringPID (float minOut, float maxOut, float kp, float ki, float kd) |
| | Configure the PID controller for steering.
|
| |
|
void | setPath (Path< Coordinate< DistanceM > > path) |
| | Defines the path to follow as a sequence of waypoints.
|
| |
|
void | addWaypoint (Coordinate< DistanceM > target) |
| | Adds a single waypoint to the path (appended to the end)
|
| |
| void | setTargetAccuracy (float accuracyM) |
| | Set the target accuracy (meters) for reaching waypoints.
|
| |
|
bool | begin () |
| | Start the controller and initialize state.
|
| |
|
void | end () |
| | Stop the controller and the vehicle.
|
| |
|
void | update () |
| | Main control loop to be called periodically (e.g., in a timer or main loop)
|
| |
|
void | setOnGoalCallback (bool(*callback)(void *), void *ref=nullptr) |
| | Set a custom callback to be called when reaching the goal. The callback should return true if it handled the goal action, or false to allow default handling.
|
| |
|
float | getThrottlePercent () const |
| | Get the last computed throttle percent.
|
| |
|
float | getSteeringAngleDeg () const |
| | Get the last computed steering angle in degrees.
|
| |
|
Angle | getSteeringAngle () const |
| | Get the last computed steering angle as an Angle object.
|
| |
| float | getTargetAccuracy (DistanceUnit unit) const |
| | Get the Target Accuracy object.
|
| |
|
bool | isGoalReached () const |
| | Returns true if the goal has been reached.
|
| |
| void | setThrottleMode (ThrottleMode mode) |
| | Set the throttle control mode.
|
| |
| void | setInvertedSteering (bool inverted) |
| | Set the Inverted Steering logic: by default we use ROS logic for steering correction (positive angle = turn left), but some vehicles may require the opposite. Set to true to invert the steering direction.
|
| |
| 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.
|
| |
|
|
float | getDesiredSpeed (float distanceFromStartM, float distanceToTarget, float currentSpeedKmh) |
| | Calculate desired speed based on distance to target and start.
|
| |
|
bool | handleWaypoint (const Coordinate< DistanceM > ¤tPos, Coordinate< DistanceM > &targetPos, float &distanceToTargetM, float &desiredHeadingDeg) |
| | Handle the current waypoint: calculate distance and desired heading.
|
| |
|
float | computeHeadingError (float desiredHeading, float currentHeading) |
| | Compute angle difference range [-180, 180].
|
| |
|
float | feedforwardThrottle (float desiredSpeedKmh) const |
| | Model-based feedforward throttle estimate: 100% throttle = maxSpeedKmh.
|
| |
|
float | getThrottlePercent (float currentSpeedKmh) |
| | Compute the throttle percent based on the selected mode.
|
| |
|
void | sendControlMessages (float throttlePercent, float steeringAngleDeg) |
| | Send control messages for throttle and steering angle.
|
| |
|
bool | initializeDtFromUpdates () |
| | Handles dt initialization from first 10 updates.
|
| |
template<typename T = float>
class tinyrobotics::MotionController2D< T >
2D motion controller for path following and vehicle control.
This class implements a flexible 2D motion controller for robotic vehicles, supporting both model-based (feedforward) and feedback (PID) control for speed (throttle) and steering. It is designed for path following, smooth acceleration/deceleration, and robust integration with IMU and odometry sensors.
Features:
- Configurable PID controllers for both speed (throttle) and steering angle correction.
- Multiple throttle control strategies: Feedforward (model-based), PID (feedback), or Combined (feedforward + feedback).
- Path following with a sequence of waypoints, including automatic waypoint advancement and goal detection.
- Smooth acceleration and deceleration profiles based on distance to target and from start.
- Dynamic time step (dt) initialization for PID controllers based on update frequency.
- Modular design for use with different vehicle types, IMU sensors, and coordinate systems.
- Integration with the TinyRobotics message system for sending throttle and steering commands.
- Customizable goal callback for user-defined actions upon reaching the final waypoint.
Usage Example:
controller.setPath(path);
controller.begin();
controller.update();
2D motion controller for path following and vehicle control.
Definition: MotionController2D.h:72
@ Combined
Feedforward + PID feedback.
Integration:
- Use as a standalone controller for path following and vehicle control.
- Integrate with a message bus to receive and send control messages.
- Extend or customize by overriding protected methods or providing custom callbacks.
- Template Parameters
-
| T | Numeric type for calculations (default: float) |
- Author
- Phil Schatzmann