Fang-Robotics-MCB
Fang Robotics Team Codebase
Loading...
Searching...
No Matches
trap::motor::DjiMotor Class Reference

#include <dji_motor.hpp>

Inheritance diagram for trap::motor::DjiMotor:
Collaboration diagram for trap::motor::DjiMotor:

Classes

struct  Config
 

Public Member Functions

 DjiMotor (Drivers &drivers, const Config &config)
 
 DjiMotor (Drivers &drivers, tap::motor::MotorId motorId, tap::can::CanBus canBus, const char *name, bool inverted, double externalEncoderGearRatio, bool currentControl)
 
mockable ~DjiMotor ()
 
void initialize () override
 
void update () override
 left blank
 
Radians getAngularPosition () const override
 
RPM getAngularVelocity () const override
 
void setTargetOutput (const DjiMotorOutput &output) override
 
bool isMotorOnline () const
 
Celsius getTemperature () const
 
tap::can::CanBus getCanBus () const
 
const char * getName () const
 

Static Public Attributes

static constexpr DjiMotorOutput kMaxOutput {std::numeric_limits<DjiMotorOutput>::max()}
 

Detailed Description

Wrapper for DJI motor for the DJI M3508 on a CAN bus

Constructor & Destructor Documentation

◆ DjiMotor() [1/2]

trap::motor::DjiMotor::DjiMotor ( Drivers drivers,
const Config config 
)

Recommended constructor for storing settings in a config file due to the convenicence of structs

The

◆ DjiMotor() [2/2]

trap::motor::DjiMotor::DjiMotor ( Drivers drivers,
tap::motor::MotorId  motorId,
tap::can::CanBus  canBus,
const char *  name,
bool  inverted,
double  externalEncoderGearRatio,
bool  currentControl 
)

drivers - the drivers struct motorId - the motor controller id canBus - the can bus the motor controller is on. THIS CANNOT BE HIGHER THAN 4 name - the name of the motor for the controller menu gearRatio - this should be set to one if you do not use an external encoder in the taproot styyle!!!!! pid config: make sure the maxOutput does not exceed DjiM3508 k_maxOutput. This would lead to undefined behavior. An assertion has been placed to prevent the code from continuing.

IMPORTANT if you are using GM6020 Why an ID not more thn 4? The GM6020 motor have their id offset by + 4 for some unholy DJI reason. (Ask their sages.) Taproot decided to keep the regular motor ids, which meant that if you place MotorID::Motor1, it gets mapped to MotorID::Motor5 implicitly (irl, the GM6020 motor id needs to be set to 1, but the tapproot codewise motorId must be 5) the enum does not go above Motor8, which means in order to access a Gm6020 with irl MotorId::Motor5, the codewise motorId needs to be 9, which is not supported.

Fortunately, this ancient ritual does not need any blood sacrifice.

Long story short:: traproot currently uses the correct motor ID, taproot does not, so keep this in mind.

This oddity is a rite of passage as it is not really mentioned until the initiate tries to move a GM6020. Although, as this is Fang Robotic's first year, and we had no elders to warn us of the dangers, we lost 4 hours to this ordeal.

However, taproot ended up keeping the regular motorID

◆ ~DjiMotor()

mockable trap::motor::DjiMotor::~DjiMotor ( )
inline

Member Function Documentation

◆ getAngularPosition()

Radians trap::motor::DjiMotor::getAngularPosition ( ) const
override

Returns the last reported RPM from CAN

◆ getAngularVelocity()

RPM trap::motor::DjiMotor::getAngularVelocity ( ) const
override

Returns the last reported angular velocity in RPM

◆ getCanBus()

tap::can::CanBus trap::motor::DjiMotor::getCanBus ( ) const

◆ getName()

const char * trap::motor::DjiMotor::getName ( ) const

◆ getTemperature()

Celsius trap::motor::DjiMotor::getTemperature ( ) const

Returns the reported temperature in celsius. The temperature was provided in an int8_t

◆ initialize()

void trap::motor::DjiMotor::initialize ( )
override

It must be called for the motor to properly function.

◆ isMotorOnline()

bool trap::motor::DjiMotor::isMotorOnline ( ) const

true if a can message has been received within the last MOTOR_DISCONNECT_TIME.

◆ setTargetOutput()

void trap::motor::DjiMotor::setTargetOutput ( const DjiMotorOutput output)
override

The desired motor output. It must be limited to a 16 bit int.

This is an alias to interface with RAIL

◆ update()

void trap::motor::DjiMotor::update ( )
override

left blank

Member Data Documentation

◆ kMaxOutput

constexpr DjiMotorOutput trap::motor::DjiMotor::kMaxOutput {std::numeric_limits<DjiMotorOutput>::max()}
staticconstexpr

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