Open FFBoard
Open source force feedback firmware
ODriveCAN Class Referenceabstract

#include <ODriveCAN.h>

Inheritance diagram for ODriveCAN:
MotorDriver PersistentStorage Encoder CanHandler CommandHandler cpp_freertos::Thread ChoosableClass ChoosableClass ODriveCAN1 ODriveCAN2

Public Member Functions

 ODriveCAN (uint8_t id)
 
virtual ~ODriveCAN ()
 
const ClassIdentifier getInfo ()=0
 Command handlers always have class infos. Works well with ChoosableClass. More...
 
void turn (int16_t power) override
 
void stopMotor () override
 
void startMotor () override
 
EncodergetEncoder () override
 
bool hasIntegratedEncoder ()
 
template<class T >
void sendMsg (uint8_t cmd, T value)
 
void sendMsg (uint8_t cmd, float value)
 
void requestMsg (uint8_t cmd)
 
bool motorReady () override
 
void startAnticogging ()
 
void Run ()
 
void setTorque (float torque)
 
void canRxPendCallback (CANPort *port, CAN_rx_msg &msg) override
 
void canErrorCallback (CANPort *port, uint32_t errcode)
 
float getPos_f () override
 
uint32_t getCpr () override
 
int32_t getPos () override
 
void setPos (int32_t pos) override
 
EncoderType getEncoderType () override
 
void setMode (ODriveControlMode controlMode, ODriveInputMode inputMode)
 
void setState (ODriveState state)
 
void readyCb ()
 
void saveFlash () override
 
void restoreFlash () override
 
CommandStatus command (const ParsedCommand &cmd, std::vector< CommandReply > &replies) override
 
void registerCommands ()
 
std::string getHelpstring ()
 
void setCanFilter ()
 
- Public Member Functions inherited from MotorDriver
 MotorDriver ()
 
virtual ~MotorDriver ()
 
const ClassType getClassType () override
 returns the used classchooser selection id of this instance More...
 
virtual void emergencyStop (bool reset=false)
 
virtual void setEncoder (std::shared_ptr< Encoder > &encoder)
 
- Public Member Functions inherited from ChoosableClass
virtual ~ChoosableClass ()
 
uint16_t getSelectionID ()
 
- Public Member Functions inherited from PersistentStorage
 PersistentStorage ()
 
virtual ~PersistentStorage ()
 
void restoreFlashDelayed ()
 
- Public Member Functions inherited from Encoder
 Encoder ()
 
virtual ~Encoder ()
 
virtual int32_t getPosAbs ()
 
virtual float getPosAbs_f ()
 
virtual const ClassType getClassType () override
 returns the used classchooser selection id of this instance More...
 
- Public Member Functions inherited from CanHandler
 CanHandler ()
 
virtual ~CanHandler ()
 
virtual void canRxFullCallback (CANPort *port, uint32_t fifo)
 
virtual void canTxCpltCallback (CANPort *port, uint32_t mailbox)
 
virtual void canTxAbortCallback (CANPort *port, uint32_t mailbox)
 
- Public Member Functions inherited from CommandHandler
virtual const ClassType getClassType ()
 
 CommandHandler (const char *clsname, uint16_t clsid, uint8_t instance=0)
 
virtual ~CommandHandler ()
 
virtual bool hasCommands ()
 
virtual void setCommandsEnabled (bool enable)
 
void registerCommands ()
 
virtual CommandStatus internalCommand (const ParsedCommand &cmd, std::vector< CommandReply > &replies)
 
virtual std::string getCommandsHelpstring ()
 
virtual std::string getCsvHelpstring ()
 
virtual uint8_t getCommandHandlerInstance ()
 
void broadcastCommandReply (CommandReply reply, uint32_t cmdId, CMDtype type)
 
void sendCommandReplyAsync (CommandReply reply, uint32_t cmdId, CMDtype type, CommandInterface *interface=nullptr)
 
virtual uint16_t getCommandHandlerID ()
 
virtual CmdHandlerInfogetCommandHandlerInfo ()
 
virtual bool isValidCommandId (uint32_t cmdid, uint32_t ignoredFlags=0, uint32_t requiredFlag=0)
 
virtual CmdHandlerCommanddefgetCommandFromName (const std::string &cmd, uint32_t ignoredFlags=0)
 
virtual CmdHandlerCommanddefgetCommandFromId (const uint32_t id, uint32_t ignoredFlags=0)
 
template<typename ID >
void registerCommand (const char *cmd, const ID cmdid, const char *help=nullptr, uint32_t flags=0)
 

Private Attributes

CANPortport = &canport
 
float lastPos = 0
 
float lastSpeed = 0
 
float posOffset = 0
 
float lastVoltage = 0
 
uint32_t lastVoltageUpdate = 0
 
uint32_t lastCanMessage = 0
 
uint32_t lastPosTime = 0
 
bool posWaiting = false
 
bool reloadPosAfterStartup = false
 
int8_t nodeId = 0
 
int8_t motorId = 0
 
volatile ODriveState odriveCurrentState = ODriveState::AXIS_STATE_UNDEFINED
 
volatile uint32_t errors = 0
 
volatile uint32_t odriveMotorFlags = 0
 
volatile uint32_t odriveEncoderFlags = 0
 
volatile uint32_t odriveControllerFlags = 0
 
float maxTorque = 1.0
 
volatile bool waitReady = true
 
bool active = false
 
int32_t filterId = 0
 
volatile ODriveLocalState state = ODriveLocalState::IDLE
 
bool connected = false
 

Additional Inherited Members

- Static Public Member Functions inherited from ChoosableClass
static bool isCreatable ()
 
- Static Public Member Functions inherited from PersistentStorage
static std::vector< PersistentStorage * > & getFlashHandlers ()
 
static void restoreFlashStartupCb ()
 
- Static Public Member Functions inherited from CanHandler
static std::vector< CanHandler * > & getCANHandlers ()
 
- Static Public Member Functions inherited from CommandHandler
static void logSerial (std::string string)
 Send a log formatted sequence. More...
 
static void logSerialDebug (std::string string)
 Send a log formatted sequence if debug is on. More...
 
static bool logsEnabled ()
 
static void setLogsEnabled (bool enabled)
 
static uint32_t getClassIdFromName (const char *name)
 
static const char * getClassNameFromId (const uint32_t id)
 
static CommandHandlergetHandlerFromHandlerId (const uint16_t cmdhandlerID)
 
static CommandHandlergetHandlerFromId (const uint16_t id, const uint8_t instance=0xFF)
 
static CommandHandlergetHandlerFromClassName (const char *name, const uint8_t instance=0xFF)
 
static std::vector< CommandHandler * > getHandlersFromClassName (const char *name)
 
static std::vector< CommandHandler * > getHandlersFromId (const uint16_t id)
 
static bool isInHandlerList (CommandHandler *handler)
 
static std::string getAllHelpstrings ()
 
static std::vector< CommandHandler * > & getCommandHandlers ()
 
template<typename TVal >
static CommandStatus handleGetSet (const ParsedCommand &cmd, std::vector< CommandReply > &replies, TVal &value)
 
template<typename TVal , class cls , class cls1 >
static CommandStatus handleGetSetFunc (const ParsedCommand &cmd, std::vector< CommandReply > &replies, TVal &value, void(cls1::*setfunc)(TVal), cls *obj)
 
template<typename TVal , class cls , class cls1 , class cls2 >
static CommandStatus handleGetFuncSetFunc (const ParsedCommand &cmd, std::vector< CommandReply > &replies, TVal(cls1::*getfunc)(), void(cls2::*setfunc)(TVal), cls *obj)
 
template<typename TVal , class cls , class cls1 >
static CommandStatus handleGetFuncSet (const ParsedCommand &cmd, std::vector< CommandReply > &replies, TVal &value, TVal(cls1::*getfunc)(), cls *obj)
 
- Static Public Attributes inherited from MotorDriver
static ClassIdentifier info ={.name = "None" , .id=CLSID_MOT_NONE, .visibility = ClassVisibility::visible}
 
static const std::vector< class_entry< MotorDriver > > all_drivers
 
- Static Public Attributes inherited from ChoosableClass
static ClassIdentifier info
 
- Static Public Attributes inherited from Encoder
static ClassIdentifier info ={.name = "None" , .id=CLSID_ENCODER_NONE, .visibility = ClassVisibility::visible}
 
static const std::vector< class_entry< Encoder > > all_encoders
 
- Static Public Attributes inherited from CommandHandler
static bool logEnabled = true
 
- Protected Member Functions inherited from CommandHandler
void setInstance (uint8_t instance)
 
virtual void addCommandHandler ()
 
virtual void removeCommandHandler ()
 
- Static Protected Member Functions inherited from CommandHandler
static std::vector< uint16_t > & getCommandHandlerIds ()
 
- Protected Attributes inherited from MotorDriver
std::shared_ptr< EncoderdrvEncoder = std::make_shared<Encoder>()
 
- Protected Attributes inherited from ChoosableClass
uint16_t selectionId
 Should only be written by ClassChooser during creation. More...
 
- Protected Attributes inherited from PersistentStorage
bool restoreDelayedFlag = false
 
- Protected Attributes inherited from Encoder
uint32_t cpr = 0
 
- Protected Attributes inherited from CommandHandler
bool commandsEnabled = true
 
std::vector< CmdHandlerCommanddefregisteredCommands
 
CmdHandlerInfo cmdHandlerInfo
 
- Static Protected Attributes inherited from PersistentStorage
static bool startupComplete = false
 
- Private Member Functions inherited from cpp_freertos::Thread
 Thread (const std::string Name, uint16_t StackDepth, UBaseType_t Priority)
 
 Thread (const char *Name, uint16_t StackDepth, UBaseType_t Priority)
 
 Thread (uint16_t StackDepth, UBaseType_t Priority)
 
bool Start ()
 
virtual ~Thread ()
 
TaskHandle_t GetHandle ()
 
void Suspend ()
 
void Resume ()
 
void ResumeFromISR ()
 
void Notify ()
 
void NotifyFromISR ()
 
uint32_t WaitForNotification (TickType_t Timeout=portMAX_DELAY)
 
UBaseType_t GetPriority ()
 
UBaseType_t GetPriorityFromISR ()
 
void SetPriority (UBaseType_t NewPriority)
 
std::string GetName ()
 
char * GetName ()
 
virtual void Cleanup ()
 
void Delay (const TickType_t Delay)
 
void DelayUntil (const TickType_t Period)
 
void ResetDelayUntil ()
 
bool Wait (ConditionVariable &Cv, Mutex &CvLock, TickType_t Timeout=portMAX_DELAY)
 
- Static Private Member Functions inherited from cpp_freertos::Thread
static void Yield ()
 
static void StartScheduler ()
 
static void EndScheduler ()
 

Detailed Description

Definition at line 35 of file ODriveCAN.h.

Constructor & Destructor Documentation

◆ ODriveCAN()

ODriveCAN::ODriveCAN ( uint8_t  id)

Definition at line 40 of file ODriveCAN.cpp.

◆ ~ODriveCAN()

ODriveCAN::~ODriveCAN ( )
virtual

Definition at line 61 of file ODriveCAN.cpp.

Member Function Documentation

◆ canErrorCallback()

void ODriveCAN::canErrorCallback ( CANPort port,
uint32_t  errcode 
)
virtual

Error during can transfer

Reimplemented from CanHandler.

Definition at line 385 of file ODriveCAN.cpp.

◆ canRxPendCallback()

void ODriveCAN::canRxPendCallback ( CANPort port,
CAN_rx_msg msg 
)
overridevirtual

New message received in fifo number

Reimplemented from CanHandler.

Definition at line 389 of file ODriveCAN.cpp.

◆ command()

CommandStatus ODriveCAN::command ( const ParsedCommand cmd,
std::vector< CommandReply > &  replies 
)
overridevirtual
Parameters
[in]cmdThe parsed command to be executed.
[out]repliesA vector to return one or multiple reply objects into. Replies to the interface will be generated based on the reply objects. A string reply may not contain start, end and separation markers: [,],| Other characters are allowed.

Reimplemented from CommandHandler.

Definition at line 306 of file ODriveCAN.cpp.

◆ getCpr()

uint32_t ODriveCAN::getCpr ( )
overridevirtual

Gets the amount of counts per full rotation of the encoder

Reimplemented from Encoder.

Definition at line 268 of file ODriveCAN.cpp.

◆ getEncoder()

Encoder * ODriveCAN::getEncoder ( )
overridevirtual

Returns the encoder of this motor driver. Either the integrated encoder or an external encoder assigned to this motor driver passed externally

Reimplemented from MotorDriver.

Definition at line 230 of file ODriveCAN.cpp.

◆ getEncoderType()

EncoderType ODriveCAN::getEncoderType ( )
overridevirtual

Returns the type of the encoder. Must override this and NOT return NONE in other classes

Reimplemented from Encoder.

Definition at line 277 of file ODriveCAN.cpp.

◆ getHelpstring()

std::string ODriveCAN::getHelpstring ( )
inlinevirtual

Returns a description of this class

Reimplemented from CommandHandler.

Definition at line 94 of file ODriveCAN.h.

◆ getInfo()

const ClassIdentifier ODriveCAN::getInfo ( )
pure virtual

Command handlers always have class infos. Works well with ChoosableClass.

Implements CommandHandler.

Implemented in ODriveCAN1, and ODriveCAN2.

◆ getPos()

int32_t ODriveCAN::getPos ( )
overridevirtual

Returns the encoder position as raw counts

Reimplemented from Encoder.

Definition at line 263 of file ODriveCAN.cpp.

◆ getPos_f()

float ODriveCAN::getPos_f ( )
overridevirtual

Returns a float position in rotations

Reimplemented from Encoder.

Definition at line 251 of file ODriveCAN.cpp.

◆ hasIntegratedEncoder()

bool ODriveCAN::hasIntegratedEncoder ( )
inlinevirtual

If returned true it signals that this motor driver contains its own encoder and does not require an external encoder

Reimplemented from MotorDriver.

Definition at line 49 of file ODriveCAN.h.

◆ motorReady()

bool ODriveCAN::motorReady ( )
overridevirtual

Reimplemented from MotorDriver.

Definition at line 260 of file ODriveCAN.cpp.

◆ readyCb()

void ODriveCAN::readyCb ( )

◆ registerCommands()

void ODriveCAN::registerCommands ( )

Definition at line 79 of file ODriveCAN.cpp.

◆ requestMsg()

void ODriveCAN::requestMsg ( uint8_t  cmd)

Definition at line 243 of file ODriveCAN.cpp.

◆ restoreFlash()

void ODriveCAN::restoreFlash ( )
overridevirtual

Should be implemented to restore settings. This is not automatically called and should be called when appropriate.

Reimplemented from PersistentStorage.

Definition at line 92 of file ODriveCAN.cpp.

◆ Run()

void ODriveCAN::Run ( )
virtual

Implementation of your actual thread code. You must override this function.

Note
If INCLUDE_vTaskDelete is defined, then you may return from your Run method. This will cause the task to be deleted from FreeRTOS, however you are still responsible to delete the task object. If this is not defined, then retuning from your Run() method will result in an assert.

Implements cpp_freertos::Thread.

Definition at line 150 of file ODriveCAN.cpp.

◆ saveFlash()

void ODriveCAN::saveFlash ( )
overridevirtual

Called when the user uses the "save" command and presses the save button in the configurator Automatically called by the command parser thread for every class that inherits from PersistentStorage

Reimplemented from PersistentStorage.

Definition at line 121 of file ODriveCAN.cpp.

◆ sendMsg() [1/2]

void ODriveCAN::sendMsg ( uint8_t  cmd,
float  value 
)

◆ sendMsg() [2/2]

template<class T >
void ODriveCAN::sendMsg ( uint8_t  cmd,
value 
)
inline

Definition at line 52 of file ODriveCAN.h.

◆ setCanFilter()

void ODriveCAN::setCanFilter ( )

Definition at line 67 of file ODriveCAN.cpp.

◆ setMode()

void ODriveCAN::setMode ( ODriveControlMode  controlMode,
ODriveInputMode  inputMode 
)

Definition at line 282 of file ODriveCAN.cpp.

◆ setPos()

void ODriveCAN::setPos ( int32_t  pos)
overridevirtual

Must be in encoder cpr if not just used to zero the axis

Reimplemented from Encoder.

Definition at line 237 of file ODriveCAN.cpp.

◆ setState()

void ODriveCAN::setState ( ODriveState  state)

Definition at line 287 of file ODriveCAN.cpp.

◆ setTorque()

void ODriveCAN::setTorque ( float  torque)

Definition at line 271 of file ODriveCAN.cpp.

◆ startAnticogging()

void ODriveCAN::startAnticogging ( )

Sends the start anticogging command

Definition at line 301 of file ODriveCAN.cpp.

◆ startMotor()

void ODriveCAN::startMotor ( )
overridevirtual

Enable the motor driver

Reimplemented from MotorDriver.

Definition at line 224 of file ODriveCAN.cpp.

◆ stopMotor()

void ODriveCAN::stopMotor ( )
overridevirtual

Disable the motor driver

Reimplemented from MotorDriver.

Definition at line 217 of file ODriveCAN.cpp.

◆ turn()

void ODriveCAN::turn ( int16_t  val)
overridevirtual

Turn the motor with positive/negative power. Range should be full signed 16 bit A value of 0 should have no torque. The sign is the direction.

Reimplemented from MotorDriver.

Definition at line 292 of file ODriveCAN.cpp.

Member Data Documentation

◆ active

bool ODriveCAN::active = false
private

Definition at line 124 of file ODriveCAN.h.

◆ connected

bool ODriveCAN::connected = false
private

Definition at line 128 of file ODriveCAN.h.

◆ errors

volatile uint32_t ODriveCAN::errors = 0
private

Definition at line 115 of file ODriveCAN.h.

◆ filterId

int32_t ODriveCAN::filterId = 0
private

Definition at line 126 of file ODriveCAN.h.

◆ lastCanMessage

uint32_t ODriveCAN::lastCanMessage = 0
private

Definition at line 105 of file ODriveCAN.h.

◆ lastPos

float ODriveCAN::lastPos = 0
private

Definition at line 100 of file ODriveCAN.h.

◆ lastPosTime

uint32_t ODriveCAN::lastPosTime = 0
private

Definition at line 107 of file ODriveCAN.h.

◆ lastSpeed

float ODriveCAN::lastSpeed = 0
private

Definition at line 101 of file ODriveCAN.h.

◆ lastVoltage

float ODriveCAN::lastVoltage = 0
private

Definition at line 103 of file ODriveCAN.h.

◆ lastVoltageUpdate

uint32_t ODriveCAN::lastVoltageUpdate = 0
private

Definition at line 104 of file ODriveCAN.h.

◆ maxTorque

float ODriveCAN::maxTorque = 1.0
private

Definition at line 121 of file ODriveCAN.h.

◆ motorId

int8_t ODriveCAN::motorId = 0
private

Definition at line 112 of file ODriveCAN.h.

◆ nodeId

int8_t ODriveCAN::nodeId = 0
private

Definition at line 111 of file ODriveCAN.h.

◆ odriveControllerFlags

volatile uint32_t ODriveCAN::odriveControllerFlags = 0
private

Definition at line 119 of file ODriveCAN.h.

◆ odriveCurrentState

volatile ODriveState ODriveCAN::odriveCurrentState = ODriveState::AXIS_STATE_UNDEFINED
private

Definition at line 114 of file ODriveCAN.h.

◆ odriveEncoderFlags

volatile uint32_t ODriveCAN::odriveEncoderFlags = 0
private

Definition at line 118 of file ODriveCAN.h.

◆ odriveMotorFlags

volatile uint32_t ODriveCAN::odriveMotorFlags = 0
private

Definition at line 117 of file ODriveCAN.h.

◆ port

CANPort* ODriveCAN::port = &canport
private

Definition at line 99 of file ODriveCAN.h.

◆ posOffset

float ODriveCAN::posOffset = 0
private

Definition at line 102 of file ODriveCAN.h.

◆ posWaiting

bool ODriveCAN::posWaiting = false
private

Definition at line 108 of file ODriveCAN.h.

◆ reloadPosAfterStartup

bool ODriveCAN::reloadPosAfterStartup = false
private

Definition at line 109 of file ODriveCAN.h.

◆ state

volatile ODriveLocalState ODriveCAN::state = ODriveLocalState::IDLE
private

Definition at line 127 of file ODriveCAN.h.

◆ waitReady

volatile bool ODriveCAN::waitReady = true
private

Definition at line 122 of file ODriveCAN.h.


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