Class DjiMotor

Inheritance Relationships

Base Types

Class Documentation

class DjiMotor : public tap::can::CanRxListener, public tap::motor::MotorInterface

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).

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.

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

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).

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.

Public Functions

DjiMotor(Drivers *drivers, MotorId desMotorIdentifier, tap::can::CanBus motorCanBus, bool isInverted, const char *name, uint16_t encoderWrapped = ENC_RESOLUTION / 2, int64_t encoderRevolutions = 0, bool currentControl = false)
Parameters:
  • drivers – a pointer to the drivers struct

  • desMotorIdentifier – the ID of this motor controller

  • motorCanBus – the CAN bus the motor is on

  • isInverted – if 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.

  • name – a name to associate with the motor for use in the motor menu

  • encoderWrapped – the starting encoderValue to store for this motor. Will be overwritten by the first reported encoder value from the motor

  • encoderRevolutions – the starting number of encoder revolutions to store. See comment for DjiMotor::encoderRevolutions for more details.

~DjiMotor()
virtual void initialize() override
virtual float getPositionUnwrapped() const override
virtual float getPositionWrapped() const override
virtual int64_t getEncoderUnwrapped() const override
virtual uint16_t getEncoderWrapped() const override
virtual void resetEncoderValue() override

Resets this motor’s current encoder home position to the current encoder position reported by CAN messages, and resets this motor’s encoder revolutions to 0.

virtual void processMessage(const modm::can::Message &message) override

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:

message[in] the message to be processed.

virtual void setDesiredOutput(int32_t desiredOutput) override

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

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.

Parameters:

desiredOutput[in] the desired motor output. Limited to the range of a 16-bit int.

virtual bool isMotorOnline() const override
Returns:

true if a CAN message has been received from the motor within the last MOTOR_DISCONNECT_TIME ms, false otherwise.

void serializeCanSendData(modm::can::Message *txMessage) const

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

virtual int16_t getOutputDesired() const override
Returns:

the raw desiredOutput value which will be sent to the motor controller (specified via setDesiredOutput())

uint32_t getMotorIdentifier() const
virtual int8_t getTemperature() const override
Returns:

the temperature of the motor as reported by the motor in degrees Celsius

virtual int16_t getTorque() const override
virtual int16_t getShaftRPM() const override

For interpreting the sign of return value see class comment.

bool isMotorInverted() const
tap::can::CanBus getCanBus() const
const char *getName() const
bool isInCurrentControl() const

Public Static Functions

template<typename T>
static inline void assertEncoderType()
template<typename T>
static inline T degreesToEncoder(float angle)
template<typename T>
static inline float encoderToDegrees(T encoder)

Public Static Attributes

static uint16_t ENC_RESOLUTION = 8192
static uint16_t MAX_OUTPUT_C610 = 10000
static uint16_t MAX_OUTPUT_C620 = 16384
static uint16_t MAX_OUTPUT_820R = 32767
static uint16_t MAX_OUTPUT_GM6020 = 25000
static uint16_t MAX_OUTPUT_GM3510 = 29000
static float GEAR_RATIO_M3508 = 3591.0f / 187.0f
static float GEAR_RATIO_M3510_L1 = 3.7f / 1.0f
static float GEAR_RATIO_M3510_L2 = 5.2f / 1.0f
static float GEAR_RATIO_M3510_L3 = 19.0f / 1.0f
static float GEAR_RATIO_M3510_L4 = 27.0f / 1.0f
static float GEAR_RATIO_M2006 = 36.0f / 1.0f