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

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

See also

DjiMotorEncoder

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, bool currentControl = false, float gearRatio = 1, uint32_t encoderHomePosition = 0, tap::encoder::EncoderInterface *externalEncoder = nullptr)
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

  • gearRatio – the ratio of input revolutions to output revolutions of this encoder.

  • encoderHomePosition – the zero position for the encoder in encoder ticks.

  • externalEncoder – a pointer to an external encoder to average with the internal encoder.

mockable ~DjiMotor()
virtual void initialize() override
inline virtual tap::encoder::EncoderInterface *getEncoder() const override
inline mockable const Encoder & getInternalEncoder () const

Returns the builtin encoder associated with the motor.

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.

mockable 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())

mockable 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
mockable bool isMotorInverted () const
mockable tap::can::CanBus getCanBus () const
mockable const char * getName () const
mockable bool isInCurrentControl () const

Public Static 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