Measures wheel rotation and computes per-wheel distance and speed using encoder ticks for mobile robots.
More...
|
|
| WheelEncoder (size_t numWheels=1) |
| | Default constructor. Wheel diameter and ticks per revolution must be set before use.
|
| |
| | WheelEncoder (Distance wheelDiameterM, int ticksPerRevolution=1, size_t numWheels=1) |
| | Constructor with wheel diameter and ticks per revolution.
|
| |
| void | setWheelDiameter (Distance wheelDiameter) |
| | Set the wheel diameter using a Distance object.
|
| |
| void | setWheelDiameter (float diameter, DistanceUnit unit=DistanceUnit::M) |
| | Set the wheel diameter using a float value and unit.
|
| |
| void | setTicksPerRevolution (int ticks) |
| | Set the number of encoder ticks per wheel revolution.
|
| |
| void | setReportingFrequencyMs (uint16_t ms) |
| | Defines the reporint frequency for distance and speed messages.
|
| |
| float | getDistanceM (size_t motor=0) const |
| | Get the total distance traveled since last reset.
|
| |
| float | getDistance (DistanceUnit unit, size_t motor=0) const |
| | Get the total distance traveled in the specified unit.
|
| |
| float | getDistanceForTicksM (size_t ticks) const |
| | Get the distance corresponding to a given number of ticks (in meters).
|
| |
| float | getDistanceForTicks (size_t ticks, DistanceUnit unit) const |
| | Get the distance for a given number of ticks in the specified unit.
|
| |
| bool | begin () |
| | Resets the encoder counts and distance.
|
| |
| void | setTick (size_t motor=0) |
| | To be called by the pin interrupt handler when a tick is detected.
|
| |
| Speed | getSpeed (uint8_t motor=0) const override |
| | Get the current speed.
|
| |
| Speed | updateSpeed (uint32_t deltaTimeMs, uint8_t motor=0) override |
| | Just provide the last reported speed without inertia modeling.
|
| |
| void | sendMessage () |
| | Trigger sending messages for distance and speed.
|
| |
| void | setSlipFactor (float slipFactor) |
| | Set the slip correction factor.
|
| |
| void | calibrateSlip (float actualDistanceM) |
| | Calibrate slip by providing a known actual distance.
|
| |
| float | getSlipFactor () const |
| | Get the slip correction factor.
|
| |
| float | getRawDistanceM (size_t motor=0) const |
| | Get the raw (uncorrected) distance in meters from the encoder.
|
| |
| void | setThrottlePercent (float value, uint8_t motor=0) override |
| | Not used.
|
| |
| size_t | getMotorCount () const override |
| |
| 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.
|
| |
| 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 |
| |
Measures wheel rotation and computes per-wheel distance and speed using encoder ticks for mobile robots.
The WheelEncoder class provides a multi-wheel, vectorized interface for tracking the movement of a robot's wheels using incremental encoders. It accumulates encoder ticks for each wheel to estimate the distance traveled and calculates speed based on tick timing, supporting robust odometry for differential, skid-steer, and multi-motor vehicles.
Key features:
- Supports any number of wheels (configurable at construction).
- Vectorized state for distance, speed, and tick timing per wheel.
- Interface-compliant with ISpeedSource for modular odometry integration.
- Configurable wheel diameter and ticks per revolution for accurate distance estimation.
- Periodic reporting of distance and speed via the MessageSource interface.
- Slip calibration support to compensate for wheel slip or surface effects.
- Designed for use with interrupt-driven tick updates (call setTick() in your ISR, specifying the wheel index).
Usage:
- Create a WheelEncoder instance, specifying the number of wheels if needed, and configure the wheel diameter and ticks per revolution.
- Call begin() to reset and start periodic reporting.
- In your encoder interrupt handler, call setTick(motor) to update the encoder state for the correct wheel.
- Use getDistanceM(motor), getSpeedMPS(motor), or getDistance(unit, motor) to retrieve odometry data for each wheel.
- Optionally, calibrate slip using calibrateSlip() if you observe systematic odometry errors.
Example:
encoder.setWheelDiameter(0.065);
encoder.setTicksPerRevolution(20);
encoder.begin();
encoder.setTick(0);
encoder.setTick(1);
float leftDistance = encoder.getDistanceM(0);
float rightDistance = encoder.getDistanceM(1);
float leftSpeed = encoder.getSpeedMPS(0);
float rightSpeed = encoder.getSpeedMPS(1);
Measures wheel rotation and computes per-wheel distance and speed using encoder ticks for mobile robo...
Definition: WheelEncoder.h:69
This class is intended for embedded robotics applications (Arduino, ESP32, etc.) and integrates with the TinyRobotics messaging framework. It is suitable for use as a modular speed/distance source in extensible odometry pipelines.