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

Estimates speed from throttle with acceleration/inertia modeling (for boats, etc). More...

#include <SpeedFromThrottleWithInertia.h>

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

Public Member Functions

 SpeedFromThrottleWithInertia (float maxSpeedMps, float accelerationMps2, uint8_t numMotors=1)
 
 SpeedFromThrottleWithInertia (Speed maxSpeed, float accelerationMps2, uint8_t numMotors=1)
 
void setAcceleration (float a)
 
float getAcceleration () const
 
void setThrottlePercent (float throttle, uint8_t motor=0) override
 Define the actual throttle value.
 
void setSpeedInstant (float speed, uint8_t motor=0)
 
Speed getSpeed (uint8_t motor=0) const override
 Get the actual speed based on the last throttle value.
 
Speed updateSpeed (uint32_t deltaTimeMs, uint8_t motor=0) override
 For sources with inertia, call this in your main loop with the elapsed time (in milliseconds) to update the speed estimate for a specific motor.
 
- Public Member Functions inherited from SpeedFromThrottle
 SpeedFromThrottle (float maxSpeedMps, uint8_t numMotors=1)
 
 SpeedFromThrottle (Speed maxSpeed, uint8_t numMotors=1)
 
void setMaxSpeed (Speed speed)
 
bool onMessage (const Message< float > &msg) override
 Handle Throttle messages to update speed.
 
void addSpeedCalibration (float throttlePercent, float speedMps)
 Add or update a calibration point (throttlePercent, speedMps)
 
void clearCalibration ()
 Clear all calibration data.
 
void setThrottlePercent (float throttlePercent, uint8_t motor=0) override
 Define the actual throttle value.
 
Speed getSpeed (uint8_t motor=0) const override
 Get the actual speed based on the last throttle value.
 
Speed updateSpeed (uint32_t deltaTimeMs, uint8_t motor=0) override
 For sources with inertia, call this in your main loop with the elapsed time (in milliseconds) to update the speed estimate for a specific motor.
 
size_t getMotorCount () const override
 
- 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.
 
- Public Member Functions inherited from MessageHandler
virtual bool onMessage (const Message< float > &msg)=0
 Handle an incoming message (pure virtual).
 
virtual bool onMessage (const Message< Coordinate< float > > &msg)
 
virtual bool onMessage (const Message< GPSCoordinate > &msg)
 
virtual bool onMessage (const Message< MotionState3D > &msg)
 
virtual Speed getSpeed (uint8_t motor=0) const =0
 Get the current speed.
 
virtual void setThrottlePercent (float value, uint8_t motor=0)=0
 Publish actual speed for a specific motor.
 
virtual Speed updateSpeed (uint32_t deltaTimeMs, uint8_t motor=0)=0
 For sources with inertia, call this in your main loop with the elapsed time (in milliseconds) to update the speed estimate for a specific motor.
 
virtual size_t getMotorCount () const =0
 

Protected Attributes

float acceleration
 
std::vector< float > throttlePercent
 
std::vector< unsigned long > lastUpdateMs
 
- Protected Attributes inherited from SpeedFromThrottle
std::vector< std::pair< float, float > > calibrationData
 
std::vector< float > speedMps
 
uint8_t numMotors = 1
 
float maxSpeedMps = 0.0f
 
- Protected Attributes inherited from MessageSource
std::vector< MessageHandlerEntrymessageHandlers_
 

Additional Inherited Members

- Protected Member Functions inherited from SpeedFromThrottle
bool init ()
 
void sendSpeedMessage (uint8_t motor=0)
 
float getSpeedMPS (float throttlePercent) const
 Get speed in meters per second by interpolating calibration data.
 

Detailed Description

Estimates speed from throttle with acceleration/inertia modeling (for boats, etc).

This class extends SpeedFromThrottle by simulating acceleration/inertia:

Example usage:

SpeedFromThrottleWithInertia speedMap(2.0f, 0.2f); // 2 m/s max, 0.2 m/s^2
// In your loop:
speedMap.updateSpeed(dt); // dt in seconds
float speed = speedMap.getSpeed();
Estimates speed from throttle with acceleration/inertia modeling (for boats, etc).
Definition: SpeedFromThrottleWithInertia.h:30

Member Function Documentation

◆ getSpeed()

Speed getSpeed ( uint8_t  motor = 0) const
inlineoverridevirtual

Get the actual speed based on the last throttle value.

Reimplemented from SpeedFromThrottle.

◆ setThrottlePercent()

void setThrottlePercent ( float  throttlePercent,
uint8_t  motor = 0 
)
inlineoverridevirtual

Define the actual throttle value.

Reimplemented from SpeedFromThrottle.

◆ updateSpeed()

Speed updateSpeed ( uint32_t  deltaTimeMs,
uint8_t  motor = 0 
)
inlineoverridevirtual

For sources with inertia, call this in your main loop with the elapsed time (in milliseconds) to update the speed estimate for a specific motor.

Reimplemented from SpeedFromThrottle.


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