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

Simple quadrotor (quadcopter) model with 4-motor control. More...

#include <Quadrotor.h>

Inheritance diagram for Quadrotor< T, DriverT >:
Inheritance graph
[legend]
Collaboration diagram for Quadrotor< T, DriverT >:
Collaboration graph
[legend]

Public Member Functions

void setPins (QuadrotorMotorNo motor, int in1, int in2)
 Set the pins for a specific motor (0=front left, 1=front right, 2=rear left, 3=rear right)
 
void setThrottle (float percent)
 
void setRoll (float percent)
 
void setPitch (float percent)
 
void setYaw (float percent)
 
void end () override
 
void setMotorGain (QuadrotorMotorNo motor, float gain)
 Set a calibration gain for a specific motor (default 1.0).
 
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
 
DriverT & getMotor (QuadrotorMotorNo motor)
 
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 Member Functions

void updateMotors ()
 Update all motors based on throttle, roll, pitch, and yaw.
 

Protected Attributes

DriverT motors_ [4]
 
float motorGain_ [4] = {1.0f, 1.0f, 1.0f, 1.0f}
 
float throttle_ = 0
 
float roll_ = 0
 
float pitch_ = 0
 
float yaw_ = 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 DriverT = BrushedMotor<T>>
class tinyrobotics::Quadrotor< T, DriverT >

Simple quadrotor (quadcopter) model with 4-motor control.

This class abstracts the control of a basic quadcopter:

Usage Example (with setPins):

Quadrotor quad;
quad.setPins(FRONT_LEFT, m1_in1, m1_in2); // front left
quad.setPins(FRONT_RIGHT, m2_in1, m2_in2); // front right
quad.setPins(REAR_LEFT, m3_in1, m3_in2); // rear left
quad.setPins(REAR_RIGHT, m4_in1, m4_in2); // rear right
quad.setThrottle(60); // 60% throttle
quad.setRoll(10); // roll right
quad.setPitch(-5); // pitch down
quad.setYaw(15); // yaw right
Simple quadrotor (quadcopter) model with 4-motor control.
Definition: Quadrotor.h:41
void setPitch(float percent)
Definition: Quadrotor.h:67
void setRoll(float percent)
Definition: Quadrotor.h:61
void setThrottle(float percent)
Definition: Quadrotor.h:55
void setYaw(float percent)
Definition: Quadrotor.h:73
void setPins(QuadrotorMotorNo motor, int in1, int in2)
Set the pins for a specific motor (0=front left, 1=front right, 2=rear left, 3=rear right)
Definition: Quadrotor.h:49

Member Function Documentation

◆ end()

void end ( )
inlineoverridevirtual

Stop all motors and reset state

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.

◆ setMotorGain()

void setMotorGain ( QuadrotorMotorNo  motor,
float  gain 
)
inline

Set a calibration gain for a specific motor (default 1.0).

Parameters
motorMotor index (QuadrotorMotorNo)
gainGain factor (e.g., 1.05 for +5% output)

◆ setPitch()

void setPitch ( float  percent)
inline

Set pitch (-100 to 100): positive = forward, negative = backward

◆ setRoll()

void setRoll ( float  percent)
inline

Set roll (-100 to 100): positive = right, negative = left

◆ setThrottle()

void setThrottle ( float  percent)
inline

Set throttle (0-100%) for all motors

◆ setYaw()

void setYaw ( float  percent)
inline

Set yaw (-100 to 100): positive = right, negative = left

◆ updateMotors()

void updateMotors ( )
inlineprotected

Update all motors based on throttle, roll, pitch, and yaw.

This is a simple mixer for an X-configuration quadrotor:

  • m1: front left
  • m2: front right
  • m3: rear left
  • m4: rear right

Each control input is in percent (-100 to 100).


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