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

#include <dji_motor.hpp>

Inheritance diagram for tap::motor::DjiMotor:
Collaboration diagram for tap::motor::DjiMotor:

Public Member Functions

 DjiMotor (Drivers *drivers, MotorId desMotorIdentifier, tap::can::CanBus motorCanBus, bool isInverted, const char *name, bool currentControl=false, float gearRatio=1, uint32_t encoderHomePosition=0, tap::encoder::EncoderInterface *externalEncoder=nullptr)
 
mockable ~DjiMotor ()
 
void initialize () override
 
tap::encoder::EncoderInterfacegetEncoder () const override
 
mockable const EncodergetInternalEncoder () const
 
void processMessage (const modm::can::Message &message) override
 
void setDesiredOutput (int32_t desiredOutput) override
 
bool isMotorOnline () const override
 
mockable void serializeCanSendData (modm::can::Message *txMessage) const
 
int16_t getOutputDesired () const override
 
mockable uint32_t getMotorIdentifier () const
 
int8_t getTemperature () const override
 
int16_t getTorque () const override
 
mockable bool isMotorInverted () const
 
mockable tap::can::CanBus getCanBus () const
 
mockable const char * getName () const
 
mockable bool isInCurrentControl () const
 
- Public Member Functions inherited from tap::can::CanRxListener
 CanRxListener (Drivers *drivers, uint32_t id, CanBus cB)
 
 ~CanRxListener ()
 
mockable void attachSelfToRxHandler ()
 
- Public Member Functions inherited from tap::motor::MotorInterface
virtual void resetEncoderValue ()
 
virtual float getPositionUnwrapped () const
 
virtual float getPositionWrapped () const
 
virtual int16_t getShaftRPM () const
 

Static Public Attributes

static constexpr uint16_t MAX_OUTPUT_C610 = 10000
 
static constexpr uint16_t MAX_OUTPUT_C620 = 16384
 
static constexpr uint16_t MAX_OUTPUT_820R = 32767
 
static constexpr uint16_t MAX_OUTPUT_GM6020 = 25000
 
static constexpr uint16_t MAX_OUTPUT_GM3510 = 29000
 

Additional Inherited Members

- Public Attributes inherited from tap::can::CanRxListener
const uint32_t canIdentifier
 
const CanBus canBus
 
Driversdrivers
 

Detailed Description

A class designed to interface with DJI brand motors and motor controllers over CAN. This includes the C610 and C620 motor controllers and the GM6020 motor (that has a built-in motor controller).

Note
: the default positive rotation direction (i.e.: when this->isMotorInverted() == false) is counter clockwise when looking at the shaft from the side opposite the motor. This is specified in the C620 user manual (page 18).
See also
DjiMotorEncoder

Extends the CanRxListener class to attach a message handler for feedback data from the motor to the CAN Rx dispatch handler.

Note
Currently there is no error handling for using a motor without having it be properly initialize. You must call the initialize function in order for this class to work properly.

Constructor & Destructor Documentation

◆ DjiMotor()

tap::motor::DjiMotor::DjiMotor ( Drivers drivers,
MotorId  desMotorIdentifier,
tap::can::CanBus  motorCanBus,
bool  isInverted,
const char *  name,
bool  currentControl = false,
float  gearRatio = 1,
uint32_t  encoderHomePosition = 0,
tap::encoder::EncoderInterface externalEncoder = nullptr 
)
Parameters
driversa pointer to the drivers struct
desMotorIdentifierthe ID of this motor controller
motorCanBusthe CAN bus the motor is on
isInvertedif false the positive rotation direction of the shaft is counter-clockwise when looking at the shaft from the side opposite the motor. If true then the positive rotation direction will be clockwise.
namea name to associate with the motor for use in the motor menu
gearRatiothe ratio of input revolutions to output revolutions of this encoder.
encoderHomePositionthe zero position for the encoder in encoder ticks.
externalEncodera pointer to an external encoder to average with the internal encoder.

◆ ~DjiMotor()

tap::motor::DjiMotor::~DjiMotor ( )

Member Function Documentation

◆ getCanBus()

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

◆ getEncoder()

tap::encoder::EncoderInterface * tap::motor::DjiMotor::getEncoder ( ) const
inlineoverridevirtual

◆ getInternalEncoder()

mockable const Encoder & tap::motor::DjiMotor::getInternalEncoder ( ) const
inline

Returns the builtin encoder associated with the motor.

◆ getMotorIdentifier()

uint32_t tap::motor::DjiMotor::getMotorIdentifier ( ) const

◆ getName()

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

◆ getOutputDesired()

int16_t tap::motor::DjiMotor::getOutputDesired ( ) const
overridevirtual
Returns
the raw desiredOutput value which will be sent to the motor controller (specified via setDesiredOutput())

Implements tap::motor::MotorInterface.

◆ getTemperature()

int8_t tap::motor::DjiMotor::getTemperature ( ) const
overridevirtual
Returns
the temperature of the motor as reported by the motor in degrees Celsius

Implements tap::motor::MotorInterface.

◆ getTorque()

int16_t tap::motor::DjiMotor::getTorque ( ) const
overridevirtual

◆ initialize()

void tap::motor::DjiMotor::initialize ( )
overridevirtual

◆ isInCurrentControl()

bool tap::motor::DjiMotor::isInCurrentControl ( ) const

◆ isMotorInverted()

bool tap::motor::DjiMotor::isMotorInverted ( ) const

◆ isMotorOnline()

bool tap::motor::DjiMotor::isMotorOnline ( ) const
overridevirtual
Returns
true if a CAN message has been received from the motor within the last MOTOR_DISCONNECT_TIME ms, false otherwise.

Implements tap::motor::MotorInterface.

◆ processMessage()

void tap::motor::DjiMotor::processMessage ( const modm::can::Message &  message)
overridevirtual

Overrides virtual method in the can class, called every time a message with the CAN message id this class is attached to is received by the can receive handler. Parses the data in the message and updates this class's fields accordingly.

Parameters
[in]messagethe message to be processed.

Implements tap::can::CanRxListener.

◆ serializeCanSendData()

void tap::motor::DjiMotor::serializeCanSendData ( modm::can::Message *  txMessage) const

Serializes send data and deposits it in a message to be sent.

◆ setDesiredOutput()

void tap::motor::DjiMotor::setDesiredOutput ( int32_t  desiredOutput)
overridevirtual

Set the desired output for the motor. The meaning of this value is motor controller specific.

Parameters
[in]desiredOutputthe desired motor output. Limited to the range of a 16-bit int.
Note
: desiredOutput is cast to an int16_t and limited to an int16_t's range! The user should make sure their value is in range. The declaration takes an int32_t in hopes to mitigate overflow.

Implements tap::motor::MotorInterface.

Member Data Documentation

◆ MAX_OUTPUT_820R

constexpr uint16_t tap::motor::DjiMotor::MAX_OUTPUT_820R = 32767
staticconstexpr

◆ MAX_OUTPUT_C610

constexpr uint16_t tap::motor::DjiMotor::MAX_OUTPUT_C610 = 10000
staticconstexpr

◆ MAX_OUTPUT_C620

constexpr uint16_t tap::motor::DjiMotor::MAX_OUTPUT_C620 = 16384
staticconstexpr

◆ MAX_OUTPUT_GM3510

constexpr uint16_t tap::motor::DjiMotor::MAX_OUTPUT_GM3510 = 29000
staticconstexpr

◆ MAX_OUTPUT_GM6020

constexpr uint16_t tap::motor::DjiMotor::MAX_OUTPUT_GM6020 = 25000
staticconstexpr

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