Open FFBoard
Open source force feedback firmware
RmdMotorCAN Class Referenceabstract

#include <RmdMotorCAN.h>

Inheritance diagram for RmdMotorCAN:
MotorDriver PersistentStorage Encoder CanHandler CommandHandler cpp_freertos::Thread ChoosableClass ChoosableClass RmdMotorCAN1 RmdMotorCAN2

Classes

union  ErrorStatus
 

Public Member Functions

 RmdMotorCAN (uint8_t instance)
 
virtual ~RmdMotorCAN ()
 
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 ()
 
void setTorque (int16_t torque)
 
bool motorReady ()
 
void Run ()
 
void saveFlash () override
 
void restoreFlash () override
 
uint32_t getCpr () override
 
int32_t getPos () override
 
void setPos (int32_t pos) override
 
EncoderType getEncoderType () override
 
void setCanFilter ()
 
void updateRequestMode (bool activerequests)
 
void sendMsg (std::array< uint8_t, 8 > &data, uint8_t len=8)
 
void sendCmd (uint8_t cmd)
 
void canRxPendCallback (CANPort *port, CAN_rx_msg &msg) override
 
void updateStatus ()
 
void requestConstantReports (uint8_t cmd, bool enable, uint16_t interval_10ms)
 
void registerCommands ()
 
CommandStatus command (const ParsedCommand &cmd, std::vector< CommandReply > &replies) override
 
- 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 float getPos_f ()
 
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 canErrorCallback (CANPort *port, uint32_t errcode)
 
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 getHelpstring ()
 
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)
 

Public Attributes

const uint32_t angleUpdateMs = 10
 

Private Member Functions

void errorCb (ErrorStatus &errors)
 
- 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)
 

Private Attributes

CANPortport = &canport
 
uint8_t nodeId = 1
 
uint8_t motorId = 0
 
bool active = false
 
bool nextAvailable = false
 
bool available = false
 
bool activerequests = false
 
bool requestConstantReportEnable = false
 
char modelName [8] = {0}
 
uint32_t lastAngleUpdate = 0
 
uint32_t lastTorqueStatusUpdate_us = 0
 
float lastPos = 0
 
uint16_t maxTorque = 1000
 
int32_t filterId = -2
 
int16_t curCurrent = 0
 
uint8_t curTemp = 0
 
uint16_t curVoltage = 0
 
ErrorStatus lastErrors = {0}
 
int32_t posOffset = 0
 

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
 
- Static Private Member Functions inherited from cpp_freertos::Thread
static void Yield ()
 
static void StartScheduler ()
 
static void EndScheduler ()
 

Detailed Description

Definition at line 28 of file RmdMotorCAN.h.

Constructor & Destructor Documentation

◆ RmdMotorCAN()

RmdMotorCAN::RmdMotorCAN ( uint8_t  instance)

Definition at line 42 of file RmdMotorCAN.cpp.

◆ ~RmdMotorCAN()

RmdMotorCAN::~RmdMotorCAN ( )
virtual

Definition at line 61 of file RmdMotorCAN.cpp.

Member Function Documentation

◆ canRxPendCallback()

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

New message received in fifo number

Reimplemented from CanHandler.

Definition at line 240 of file RmdMotorCAN.cpp.

◆ command()

CommandStatus RmdMotorCAN::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 334 of file RmdMotorCAN.cpp.

◆ errorCb()

void RmdMotorCAN::errorCb ( ErrorStatus errors)
private

Definition at line 223 of file RmdMotorCAN.cpp.

◆ getCpr()

uint32_t RmdMotorCAN::getCpr ( )
overridevirtual

Gets the amount of counts per full rotation of the encoder

Reimplemented from Encoder.

Definition at line 161 of file RmdMotorCAN.cpp.

◆ getEncoder()

Encoder * RmdMotorCAN::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 151 of file RmdMotorCAN.cpp.

◆ getEncoderType()

EncoderType RmdMotorCAN::getEncoderType ( )
overridevirtual

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

Reimplemented from Encoder.

Definition at line 219 of file RmdMotorCAN.cpp.

◆ getInfo()

const ClassIdentifier RmdMotorCAN::getInfo ( )
pure virtual

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

Implements CommandHandler.

Implemented in RmdMotorCAN1, and RmdMotorCAN2.

◆ getPos()

int32_t RmdMotorCAN::getPos ( )
overridevirtual

Returns the encoder position as raw counts

Reimplemented from Encoder.

Definition at line 165 of file RmdMotorCAN.cpp.

◆ hasIntegratedEncoder()

bool RmdMotorCAN::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 38 of file RmdMotorCAN.h.

◆ motorReady()

bool RmdMotorCAN::motorReady ( )
virtual

Reimplemented from MotorDriver.

Definition at line 155 of file RmdMotorCAN.cpp.

◆ registerCommands()

void RmdMotorCAN::registerCommands ( )

Definition at line 322 of file RmdMotorCAN.cpp.

◆ requestConstantReports()

void RmdMotorCAN::requestConstantReports ( uint8_t  cmd,
bool  enable,
uint16_t  interval_10ms 
)

Request constant automatic replies interval 0 = 10ms, 1= 20ms...

Definition at line 233 of file RmdMotorCAN.cpp.

◆ restoreFlash()

void RmdMotorCAN::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 67 of file RmdMotorCAN.cpp.

◆ Run()

void RmdMotorCAN::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 98 of file RmdMotorCAN.cpp.

◆ saveFlash()

void RmdMotorCAN::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 85 of file RmdMotorCAN.cpp.

◆ sendCmd()

void RmdMotorCAN::sendCmd ( uint8_t  cmd)

Definition at line 187 of file RmdMotorCAN.cpp.

◆ sendMsg()

void RmdMotorCAN::sendMsg ( std::array< uint8_t, 8 > &  data,
uint8_t  len = 8 
)

Definition at line 177 of file RmdMotorCAN.cpp.

◆ setCanFilter()

void RmdMotorCAN::setCanFilter ( )

Definition at line 123 of file RmdMotorCAN.cpp.

◆ setPos()

void RmdMotorCAN::setPos ( int32_t  pos)
overridevirtual

Change the position of the encoder Can be used to reset the center

Reimplemented from Encoder.

Definition at line 173 of file RmdMotorCAN.cpp.

◆ setTorque()

void RmdMotorCAN::setTorque ( int16_t  torque)

Torque 0.01A * torque

Definition at line 205 of file RmdMotorCAN.cpp.

◆ startMotor()

void RmdMotorCAN::startMotor ( )
overridevirtual

Enable the motor driver

Reimplemented from MotorDriver.

Definition at line 144 of file RmdMotorCAN.cpp.

◆ stopMotor()

void RmdMotorCAN::stopMotor ( )
overridevirtual

Disable the motor driver

Reimplemented from MotorDriver.

Definition at line 138 of file RmdMotorCAN.cpp.

◆ turn()

void RmdMotorCAN::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 210 of file RmdMotorCAN.cpp.

◆ updateRequestMode()

void RmdMotorCAN::updateRequestMode ( bool  activerequests)

Definition at line 305 of file RmdMotorCAN.cpp.

◆ updateStatus()

void RmdMotorCAN::updateStatus ( )

Requests Status1 update Contains voltage, errors and temperature

Definition at line 198 of file RmdMotorCAN.cpp.

Member Data Documentation

◆ active

bool RmdMotorCAN::active = false
private

Definition at line 90 of file RmdMotorCAN.h.

◆ activerequests

bool RmdMotorCAN::activerequests = false
private

Definition at line 93 of file RmdMotorCAN.h.

◆ angleUpdateMs

const uint32_t RmdMotorCAN::angleUpdateMs = 10

Definition at line 67 of file RmdMotorCAN.h.

◆ available

bool RmdMotorCAN::available = false
private

Definition at line 92 of file RmdMotorCAN.h.

◆ curCurrent

int16_t RmdMotorCAN::curCurrent = 0
private

Definition at line 106 of file RmdMotorCAN.h.

◆ curTemp

uint8_t RmdMotorCAN::curTemp = 0
private

Definition at line 107 of file RmdMotorCAN.h.

◆ curVoltage

uint16_t RmdMotorCAN::curVoltage = 0
private

Definition at line 108 of file RmdMotorCAN.h.

◆ filterId

int32_t RmdMotorCAN::filterId = -2
private

Definition at line 104 of file RmdMotorCAN.h.

◆ lastAngleUpdate

uint32_t RmdMotorCAN::lastAngleUpdate = 0
private

Definition at line 98 of file RmdMotorCAN.h.

◆ lastErrors

ErrorStatus RmdMotorCAN::lastErrors = {0}
private

Definition at line 110 of file RmdMotorCAN.h.

◆ lastPos

float RmdMotorCAN::lastPos = 0
private

Definition at line 101 of file RmdMotorCAN.h.

◆ lastTorqueStatusUpdate_us

uint32_t RmdMotorCAN::lastTorqueStatusUpdate_us = 0
private

Definition at line 99 of file RmdMotorCAN.h.

◆ maxTorque

uint16_t RmdMotorCAN::maxTorque = 1000
private

Definition at line 102 of file RmdMotorCAN.h.

◆ modelName

char RmdMotorCAN::modelName[8] = {0}
private

Definition at line 96 of file RmdMotorCAN.h.

◆ motorId

uint8_t RmdMotorCAN::motorId = 0
private

Definition at line 89 of file RmdMotorCAN.h.

◆ nextAvailable

bool RmdMotorCAN::nextAvailable = false
private

Definition at line 91 of file RmdMotorCAN.h.

◆ nodeId

uint8_t RmdMotorCAN::nodeId = 1
private

Definition at line 88 of file RmdMotorCAN.h.

◆ port

CANPort* RmdMotorCAN::port = &canport
private

Definition at line 87 of file RmdMotorCAN.h.

◆ posOffset

int32_t RmdMotorCAN::posOffset = 0
private

Definition at line 112 of file RmdMotorCAN.h.

◆ requestConstantReportEnable

bool RmdMotorCAN::requestConstantReportEnable = false
private

Definition at line 94 of file RmdMotorCAN.h.


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