TinyRobotics
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
CarAckerman< T, MotorMT, ServoMT > Class Template Reference

Car with Ackerman steering and single drive motor. More...

#include <CarAckerman.h>

Inheritance diagram for CarAckerman< T, MotorMT, ServoMT >:
Inheritance graph
[legend]
Collaboration diagram for CarAckerman< T, MotorMT, ServoMT >:
Collaboration graph
[legend]

Public Member Functions

void setPins (int in1, int in2, int steeringPin)
 Set the pins for the drive motor and steering servo.
 
void setSpeed (float percent)
 Set drive speed (percent, -100 to 100). Positive = forward.
 
void setSteeringAngle (float angle)
 Set steering angle (degrees, left positive, right negative).
 
void setSteeringAngle (Angle angle)
 
Angle getSteeringAngle () const
 
float getSpeed () const
 
void end () override
 
bool isPinsSet () const
 Check if the necessary pins for the vehicle's actuators have been set (pure virtual).
 
bool onMessage (const Message< float > &msg) override
 Handle an incoming message (pure virtual).
 
std::vector< MessageContent > getControls () const override
 
MotorMT & getMotor ()
 
ServoMT & getServo ()
 
std::vector< IMotor< T > * > getMotors () override
 
- Public Member Functions inherited from Vehicle< MotorT >
bool begin ()
 Initialize the vehicle.
 
virtual void end ()=0
 Reset the vehicle to a safe or neutral state (pure virtual).
 
virtual bool isPinsSet () const =0
 Check if the necessary pins for the vehicle's actuators have been set (pure virtual).
 
virtual std::vector< MessageContent > getControls () const =0
 
float getSpeedFactor () const
 Get the speed factor (scaling for speed commands).
 
void setSpeedFactor (float factor)
 Set the speed factor (scaling for speed commands).
 
virtual std::vector< IMotor< MotorT > * > getMotors ()=0
 
- 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)
 
- 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 Attributes

MotorMT motor_
 
ServoMT steering_
 
float speed_ = 0
 
float angleDeg_ = 0
 
- Protected Attributes inherited from Vehicle< MotorT >
float speedFactor_ = 1.0f
 
- Protected Attributes inherited from MessageSource
std::vector< MessageHandlerEntrymessageHandlers_
 

Detailed Description

template<typename T = float, typename MotorMT = BrushedMotor<T>, typename ServoMT = ServoMotor<T>>
class tinyrobotics::CarAckerman< T, MotorMT, ServoMT >

Car with Ackerman steering and single drive motor.

This class abstracts a simple car:

Usage Example:

car.setPins(5, 6, 9); // in1, in2, steeringPin
car.setSpeed(60); // 60% forward
car.setSteering(30); // 30 degrees left
car.end(); // brake
Car with Ackerman steering and single drive motor.
Definition: CarAckerman.h:29
void setSpeed(float percent)
Set drive speed (percent, -100 to 100). Positive = forward.
Definition: CarAckerman.h:48
void setPins(int in1, int in2, int steeringPin)
Set the pins for the drive motor and steering servo.
Definition: CarAckerman.h:40
void end() override
Definition: CarAckerman.h:78

Member Function Documentation

◆ end()

void end ( )
inlineoverridevirtual

Stop the car (brake motor)

Implements Vehicle< MotorT >.

◆ getControls()

std::vector< MessageContent > getControls ( ) const
inlineoverridevirtual

Implements Vehicle< MotorT >.

◆ getMotors()

std::vector< IMotor< T > * > getMotors ( )
inlineoverridevirtual

Implements Vehicle< MotorT >.

◆ isPinsSet()

bool isPinsSet ( ) const
inlinevirtual

Check if the necessary pins for the vehicle's actuators have been set (pure virtual).

Implements Vehicle< MotorT >.

◆ onMessage()

bool onMessage ( const Message< float > &  msg)
inlineoverridevirtual

Handle an incoming message (pure virtual).

This method should be implemented by derived classes to process messages.

Parameters
msgThe message to handle.
Returns
true if the message was handled successfully, false otherwise.

Implements MessageHandler.

◆ setPins()

void setPins ( int  in1,
int  in2,
int  steeringPin 
)
inline

Set the pins for the drive motor and steering servo.

Parameters
in1HBridge IN1
in2HBridge IN2
pwmHBridge PWM
steeringPinServo pin for steering

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