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

#include <dji_motor_encoder.hpp>

Inheritance diagram for tap::motor::DjiMotorEncoder:
Collaboration diagram for tap::motor::DjiMotorEncoder:

Public Member Functions

 DjiMotorEncoder (bool isInverted, float gearRatio=1, uint32_t encoderHomePosition=0)
 
void initialize () override
 
bool isOnline () const override
 
float getVelocity () const override
 
mockable int16_t getShaftRPM () const
 
mockable void processMessage (const modm::can::Message &message)
 
- Public Member Functions inherited from tap::encoder::WrappedEncoder
 WrappedEncoder (bool isInverted, uint32_t encoderResolution, float gearRatio=1, uint32_t encoderHomePosition=0)
 
void initialize () override
 
tap::algorithms::WrappedFloat getPosition () const override
 
mockable tap::algorithms::WrappedFloat getEncoder () const
 
float getVelocity () const override
 
void alignWith (EncoderInterface *other) override
 
void resetEncoderValue () override
 

Static Public Attributes

static constexpr uint16_t ENC_RESOLUTION = 8192
 
static constexpr float GEAR_RATIO_M3508 = 3591.0f / 187.0f
 
static constexpr float GEAR_RATIO_GM3510_L1 = 3.7f / 1.0f
 
static constexpr float GEAR_RATIO_GM3510_L2 = 5.2f / 1.0f
 
static constexpr float GEAR_RATIO_GM3510_L3 = 19.0f / 1.0f
 
static constexpr float GEAR_RATIO_GM3510_L4 = 27.0f / 1.0f
 
static constexpr float GEAR_RATIO_M2006 = 36.0f / 1.0f
 
static constexpr float GEAR_RATIO_GM6020 = 1.0f / 1.0f
 

Additional Inherited Members

- Protected Member Functions inherited from tap::encoder::WrappedEncoder
void updateEncoderValue (uint32_t encoderActual)
 
- Protected Attributes inherited from tap::encoder::WrappedEncoder
tap::algorithms::WrappedFloat encoder
 
tap::algorithms::WrappedFloat position
 
bool inverted
 
const uint32_t encoderResolution
 
const float gearRatio
 

Detailed Description

A class designed to interface with the encoder for 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).

DJI motor encoders store a consistent encoding for a given angle across power-cycles. This means the encoder angle reported by the motor can have meaning if the encoding for an angle is unique as it is for the GM6020s. However for geared motors like the M3508 where a full encoder revolution does not correspond 1:1 to a shaft revolution, it is impossible to know the orientation of the shaft given just the encoder value.

Combining them with some form of absolute encoder on the output shaft would give you knowledge of the orientation of the output shaft.

Constructor & Destructor Documentation

◆ DjiMotorEncoder()

tap::motor::DjiMotorEncoder::DjiMotorEncoder ( bool  isInverted,
float  gearRatio = 1,
uint32_t  encoderHomePosition = 0 
)
Parameters
isInvertedif false the positive rotation direction of the shaft is counter-clockwise when looking at the shaft from. If true then the positive rotation direction will be clockwise.
encoderResolutionthe number of encoder ticks before the value wraps.
gearRatiothe ratio of input revolutions to output revolutions of this encoder.
encoderHomePositionthe zero position for the encoder in encoder ticks.

Member Function Documentation

◆ getShaftRPM()

int16_t tap::motor::DjiMotorEncoder::getShaftRPM ( ) const

The current RPM reported by the motor controller.

◆ getVelocity()

float tap::motor::DjiMotorEncoder::getVelocity ( ) const
overridevirtual

Gets the current velocity reported by the encoder. Returned in a value of radians / second

Implements tap::encoder::EncoderInterface.

◆ initialize()

void tap::motor::DjiMotorEncoder::initialize ( )
inlineoverridevirtual

Initialize the encoder. For instance: attaching a can receiver.

Implements tap::encoder::EncoderInterface.

◆ isOnline()

bool tap::motor::DjiMotorEncoder::isOnline ( ) const
overridevirtual

Returns true when the encoder is online and reporting valid values.

Implements tap::encoder::EncoderInterface.

◆ processMessage()

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

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.

Member Data Documentation

◆ ENC_RESOLUTION

constexpr uint16_t tap::motor::DjiMotorEncoder::ENC_RESOLUTION = 8192
staticconstexpr

◆ GEAR_RATIO_GM3510_L1

constexpr float tap::motor::DjiMotorEncoder::GEAR_RATIO_GM3510_L1 = 3.7f / 1.0f
staticconstexpr

◆ GEAR_RATIO_GM3510_L2

constexpr float tap::motor::DjiMotorEncoder::GEAR_RATIO_GM3510_L2 = 5.2f / 1.0f
staticconstexpr

◆ GEAR_RATIO_GM3510_L3

constexpr float tap::motor::DjiMotorEncoder::GEAR_RATIO_GM3510_L3 = 19.0f / 1.0f
staticconstexpr

◆ GEAR_RATIO_GM3510_L4

constexpr float tap::motor::DjiMotorEncoder::GEAR_RATIO_GM3510_L4 = 27.0f / 1.0f
staticconstexpr

◆ GEAR_RATIO_GM6020

constexpr float tap::motor::DjiMotorEncoder::GEAR_RATIO_GM6020 = 1.0f / 1.0f
staticconstexpr

◆ GEAR_RATIO_M2006

constexpr float tap::motor::DjiMotorEncoder::GEAR_RATIO_M2006 = 36.0f / 1.0f
staticconstexpr

◆ GEAR_RATIO_M3508

constexpr float tap::motor::DjiMotorEncoder::GEAR_RATIO_M3508 = 3591.0f / 187.0f
staticconstexpr

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