![]() |
Open FFBoard
Open source force feedback firmware
|
#include <MotorSimplemotion.h>
Classes | |
struct | Sm2FastUpdate |
struct | Sm2FastUpdate_reply |
Public Member Functions | |
MotorSimplemotion (uint8_t instance) | |
virtual | ~MotorSimplemotion () |
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 |
Encoder * | getEncoder () override |
bool | hasIntegratedEncoder () |
int32_t | getPos () override |
void | setPos (int32_t pos) override |
EncoderType | getEncoderType () override |
uint32_t | getCpr () override |
CommandStatus | command (const ParsedCommand &cmd, std::vector< CommandReply > &replies) override |
void | registerCommands () |
std::string | getHelpstring () |
void | uartRcv (char &buf) |
void | sendFastUpdate (uint16_t val1, uint16_t val2=0) |
void | startUartTransfer (UARTPort *port, bool transmit) |
void | endUartTransfer (UARTPort *port, bool transmit) |
bool | sendCommand (uint8_t *buf, uint8_t len, uint8_t adr) |
uint8_t | queueCommand (uint8_t *buf, MotorSimplemotion_cmdtypes type, uint32_t data) |
bool | read1Parameter (MotorSimplemotion_param paramId, uint32_t *reply_p, MotorSimplemotion_cmdtypes replylen=MotorSimplemotion_cmdtypes::none) |
bool | set1Parameter (MotorSimplemotion_param paramId, int32_t value, uint32_t *reply_p=nullptr) |
bool | getSettings () |
uint32_t | getCumstat () |
bool | motorReady () |
int16_t | getTorque () |
int16_t | getVoltage () |
void | restart () |
![]() | |
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) |
![]() | |
virtual | ~ChoosableClass () |
uint16_t | getSelectionID () |
![]() | |
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... | |
![]() | |
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 CmdHandlerInfo * | getCommandHandlerInfo () |
virtual bool | isValidCommandId (uint32_t cmdid, uint32_t ignoredFlags=0, uint32_t requiredFlag=0) |
virtual CmdHandlerCommanddef * | getCommandFromName (const std::string &cmd, uint32_t ignoredFlags=0) |
virtual CmdHandlerCommanddef * | getCommandFromId (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) |
![]() | |
UARTDevice () | |
UARTDevice (UARTPort &port) | |
virtual | ~UARTDevice () |
Static Public Attributes | |
static const uint8_t | SMCMD_FAST_UPDATE_CYCLE = 2<<3 |
static const uint8_t | SMCMD_FAST_UPDATE_CYCLE_RET = (2<<3) | 1 |
static const uint8_t | SMP_FAST_UPDATE_CYCLE_FORMAT = 17 |
static const uint8_t | SMCMD_INSTANT_CMD = 0x24 |
static const uint8_t | SMCMD_INSTANT_CMD_RET = 0x25 |
static const uint8_t | SMPCMD_SETPARAMADDR = 2 |
![]() | |
static ClassIdentifier | info ={.name = "None" , .id=CLSID_MOT_NONE, .visibility = ClassVisibility::visible} |
static const std::vector< class_entry< MotorDriver > > | all_drivers |
![]() | |
static ClassIdentifier | info |
![]() | |
static ClassIdentifier | info ={.name = "None" , .id=CLSID_ENCODER_NONE, .visibility = ClassVisibility::visible} |
static const std::vector< class_entry< Encoder > > | all_encoders |
![]() | |
static bool | logEnabled = true |
Protected Attributes | |
const OutputPin & | writeEnablePin = gpMotor |
volatile char | rxbuf [RXBUF_SIZE] |
volatile uint8_t | rxbuf_i = 0 |
char | txbuf [TXBUF_SIZE] |
volatile uint8_t | replyidx = 0 |
volatile uint32_t | replyvalues [REPLYBUF_SIZE] |
volatile uint32_t | crcerrors = 0 |
int16_t | lastTorque = 0 |
volatile uint32_t | lastUpdateTime = 0 |
volatile uint32_t | uarterrors = 0 |
![]() | |
std::shared_ptr< Encoder > | drvEncoder = std::make_shared<Encoder>() |
![]() | |
uint16_t | selectionId |
Should only be written by ClassChooser during creation. More... | |
![]() | |
uint32_t | cpr = 0 |
![]() | |
bool | commandsEnabled = true |
std::vector< CmdHandlerCommanddef > | registeredCommands |
CmdHandlerInfo | cmdHandlerInfo |
![]() | |
UARTPort * | uartport = nullptr |
Static Protected Attributes | |
static std::array< uint8_t, 256 > | tableCRC8 |
static std::array< uint16_t, 256 > | tableCRC16 |
static const uint8_t | crcpoly = 0x07 |
static const uint16_t | crcpoly16 = 0x8005 |
static bool | crcTableInitialized = false |
static const uint8_t | crc8init = 0x52 |
static const uint8_t | RXBUF_SIZE = 32 |
static const uint8_t | TXBUF_SIZE = 32 |
static const uint8_t | REPLYBUF_SIZE = 32 |
Private Types | |
enum class | MotorSimplemotion_commands : uint8_t { crcerrors , uarterrors , voltage , torque , status , restart , reg , devtype } |
enum class | MotorSimplemotion_cmdtypes : uint8_t { param32b = 0 , param24b = 1 , setparamadr = 2 , status =3 , none = 0xff } |
enum class | MotorSimplemotion_param : uint16_t { FBD = 493 , FBR = 565 , ControlMode = 559 , Voltage = 900 , Torque = 901 , systemcontrol = 554 , status = 553 , CB1 = 2533 , cumstat = 13 , faults = 552 , devtype = 6020 } |
enum class | MotorSimplemotion_FBR : uint8_t { none = 0 , ABN1 , ABN2 , Resolver , Hall , Serial , Sincos16 , Sincos64 , Sincos256 } |
Private Member Functions | |
struct MotorSimplemotion::Sm2FastUpdate | __attribute__ ((packed)) |
struct MotorSimplemotion::Sm2FastUpdate_reply | __attribute__ ((packed)) |
void | updatePosition (uint16_t value) |
void | updateStatus (uint16_t value) |
void | resetBuffer () |
bool | prepareUartTransmit () |
template<size_t params, size_t replynum> | |
bool | readParameter (std::array< MotorSimplemotion_param, params > paramIds, std::array< uint32_t *, replynum > replies, MotorSimplemotion_cmdtypes replylen=MotorSimplemotion_cmdtypes::none, uint32_t timeout_ms=uartErrorTimeout) |
template<size_t params, size_t replynum> | |
bool | writeParameter (std::array< std::pair< MotorSimplemotion_param, int32_t >, params > paramIds_value, std::array< uint32_t *, replynum > replies, MotorSimplemotion_cmdtypes type, uint32_t timeout_ms=uartErrorTimeout) |
Static Private Member Functions | |
static uint16_t | calculateCrc16rev (std::array< uint16_t, 256 > &crctable, uint8_t *buf, uint16_t len, uint16_t crc) |
Private Attributes | |
uint8_t | address |
uint16_t | status |
uint16_t | devicetype =0 |
int32_t | position = 0 |
int32_t | position_offset = 0 |
uint16_t | lastPosRep = 0x7fff |
volatile bool | waitingFastUpdate = false |
volatile bool | waitingReply = false |
int32_t | overflows = 0 |
Sm2FastUpdate | fastbuffer |
volatile uint32_t | lastSentTime = 0 |
volatile uint32_t | lastStatusTime = 0 |
volatile uint32_t | lastTimeByteReceived = 0 |
volatile bool | uartErrorOccured = false |
bool | initialized = false |
bool | hardfault = false |
Error | configError = {ErrorCode::externalConfigurationError, ErrorType::critical, "Simplemotion device invalid configuration"} |
MotorSimplemotion_FBR | encodertype |
Static Private Attributes | |
static const uint32_t | uartErrorTimeout = 10 |
Additional Inherited Members | |
![]() | |
static bool | isCreatable () |
![]() | |
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 CommandHandler * | getHandlerFromHandlerId (const uint16_t cmdhandlerID) |
static CommandHandler * | getHandlerFromId (const uint16_t id, const uint8_t instance=0xFF) |
static CommandHandler * | getHandlerFromClassName (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) |
![]() | |
void | setInstance (uint8_t instance) |
virtual void | addCommandHandler () |
virtual void | removeCommandHandler () |
![]() | |
static std::vector< uint16_t > & | getCommandHandlerIds () |
Requires a uart port and one GPIO output for the transceiver
Definition at line 24 of file MotorSimplemotion.h.
|
strongprivate |
Enumerator | |
---|---|
param32b | |
param24b | |
setparamadr | |
status | |
none |
Definition at line 30 of file MotorSimplemotion.h.
|
strongprivate |
Enumerator | |
---|---|
crcerrors | |
uarterrors | |
voltage | |
torque | |
status | |
restart | |
reg | |
devtype |
Definition at line 26 of file MotorSimplemotion.h.
|
strongprivate |
Enumerator | |
---|---|
none | |
ABN1 | |
ABN2 | |
Resolver | |
Hall | |
Serial | |
Sincos16 | |
Sincos64 | |
Sincos256 |
Definition at line 38 of file MotorSimplemotion.h.
|
strongprivate |
Enumerator | |
---|---|
FBD | |
FBR | |
ControlMode | |
Voltage | |
Torque | |
systemcontrol | |
status | |
CB1 | |
cumstat | |
faults | |
devtype |
Definition at line 34 of file MotorSimplemotion.h.
MotorSimplemotion::MotorSimplemotion | ( | uint8_t | instance | ) |
Definition at line 30 of file MotorSimplemotion.cpp.
|
virtual |
Definition at line 54 of file MotorSimplemotion.cpp.
|
private |
|
private |
|
staticprivate |
|
overridevirtual |
[in] | cmd | The parsed command to be executed. |
[out] | replies | A 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 485 of file MotorSimplemotion.cpp.
|
virtual |
Reimplemented from UARTDevice.
Definition at line 462 of file MotorSimplemotion.cpp.
|
overridevirtual |
This is requested always before position so we need to make sure we have the cpr
Reimplemented from Encoder.
Definition at line 128 of file MotorSimplemotion.cpp.
uint32_t MotorSimplemotion::getCumstat | ( | ) |
Definition at line 140 of file MotorSimplemotion.cpp.
|
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 106 of file MotorSimplemotion.cpp.
|
overridevirtual |
Returns the type of the encoder. Must override this and NOT return NONE in other classes
Reimplemented from Encoder.
Definition at line 450 of file MotorSimplemotion.cpp.
|
inlinevirtual |
Returns a description of this class
Reimplemented from CommandHandler.
Definition at line 78 of file MotorSimplemotion.h.
|
pure virtual |
Command handlers always have class infos. Works well with ChoosableClass.
Implements CommandHandler.
Implemented in MotorSimplemotion1, and MotorSimplemotion2.
|
overridevirtual |
In order to get a position update the fast update must be sent first by updating a torque value
Reimplemented from Encoder.
Definition at line 114 of file MotorSimplemotion.cpp.
bool MotorSimplemotion::getSettings | ( | ) |
Definition at line 148 of file MotorSimplemotion.cpp.
int16_t MotorSimplemotion::getTorque | ( | ) |
Definition at line 248 of file MotorSimplemotion.cpp.
int16_t MotorSimplemotion::getVoltage | ( | ) |
Definition at line 239 of file MotorSimplemotion.cpp.
|
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 68 of file MotorSimplemotion.h.
|
virtual |
Reimplemented from MotorDriver.
Definition at line 135 of file MotorSimplemotion.cpp.
|
private |
Checks for a failed transfer and takes the semaphore for uart port
Definition at line 289 of file MotorSimplemotion.cpp.
uint8_t MotorSimplemotion::queueCommand | ( | uint8_t * | buf, |
MotorSimplemotion_cmdtypes | type, | ||
uint32_t | data | ||
) |
Appends a subpacket to a buffer. Buffer must be 0 initialized returns appended length
Definition at line 331 of file MotorSimplemotion.cpp.
bool MotorSimplemotion::read1Parameter | ( | MotorSimplemotion_param | paramId, |
uint32_t * | reply_p, | ||
MotorSimplemotion_cmdtypes | replylen = MotorSimplemotion_cmdtypes::none |
||
) |
Definition at line 226 of file MotorSimplemotion.cpp.
|
inlineprivate |
Templated function to read multiple parameters TODO: support more than 1 request at once
Definition at line 173 of file MotorSimplemotion.h.
void MotorSimplemotion::registerCommands | ( | ) |
Definition at line 472 of file MotorSimplemotion.cpp.
|
private |
Resets the buffer and ends a transfer. must be called after every receive
Definition at line 344 of file MotorSimplemotion.cpp.
void MotorSimplemotion::restart | ( | ) |
Definition at line 256 of file MotorSimplemotion.cpp.
bool MotorSimplemotion::sendCommand | ( | uint8_t * | buf, |
uint8_t | len, | ||
uint8_t | adr | ||
) |
Sends a command buffer
Definition at line 300 of file MotorSimplemotion.cpp.
void MotorSimplemotion::sendFastUpdate | ( | uint16_t | val1, |
uint16_t | val2 = 0 |
||
) |
Sends a fast cycle packet. Driver will reply with status and position
Definition at line 62 of file MotorSimplemotion.cpp.
bool MotorSimplemotion::set1Parameter | ( | MotorSimplemotion_param | paramId, |
int32_t | value, | ||
uint32_t * | reply_p = nullptr |
||
) |
Definition at line 232 of file MotorSimplemotion.cpp.
|
overridevirtual |
Change the position of the encoder Can be used to reset the center
Reimplemented from Encoder.
Definition at line 121 of file MotorSimplemotion.cpp.
|
overridevirtual |
Enable the motor driver
Reimplemented from MotorDriver.
Definition at line 441 of file MotorSimplemotion.cpp.
|
virtual |
Reimplemented from UARTDevice.
Definition at line 454 of file MotorSimplemotion.cpp.
|
overridevirtual |
Disable the motor driver
Reimplemented from MotorDriver.
Definition at line 445 of file MotorSimplemotion.cpp.
|
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 101 of file MotorSimplemotion.cpp.
|
virtual |
Reimplemented from UARTDevice.
Definition at line 353 of file MotorSimplemotion.cpp.
|
private |
Definition at line 261 of file MotorSimplemotion.cpp.
|
private |
Definition at line 277 of file MotorSimplemotion.cpp.
|
inlineprivate |
Definition at line 219 of file MotorSimplemotion.h.
|
private |
Definition at line 137 of file MotorSimplemotion.h.
|
private |
Definition at line 163 of file MotorSimplemotion.h.
|
staticprotected |
Definition at line 116 of file MotorSimplemotion.h.
|
protected |
Definition at line 131 of file MotorSimplemotion.h.
|
staticprotected |
Definition at line 113 of file MotorSimplemotion.h.
|
staticprotected |
Definition at line 114 of file MotorSimplemotion.h.
|
staticprotected |
Definition at line 115 of file MotorSimplemotion.h.
|
private |
Definition at line 142 of file MotorSimplemotion.h.
|
private |
Definition at line 164 of file MotorSimplemotion.h.
|
private |
Definition at line 150 of file MotorSimplemotion.h.
|
private |
Definition at line 162 of file MotorSimplemotion.h.
|
private |
Definition at line 161 of file MotorSimplemotion.h.
|
private |
Definition at line 146 of file MotorSimplemotion.h.
|
private |
Definition at line 151 of file MotorSimplemotion.h.
|
private |
Definition at line 152 of file MotorSimplemotion.h.
|
private |
Definition at line 155 of file MotorSimplemotion.h.
|
protected |
Definition at line 132 of file MotorSimplemotion.h.
|
protected |
Definition at line 133 of file MotorSimplemotion.h.
|
private |
Definition at line 149 of file MotorSimplemotion.h.
|
private |
Definition at line 144 of file MotorSimplemotion.h.
|
private |
Definition at line 145 of file MotorSimplemotion.h.
|
staticprotected |
Definition at line 128 of file MotorSimplemotion.h.
|
protected |
Definition at line 127 of file MotorSimplemotion.h.
|
protected |
Definition at line 129 of file MotorSimplemotion.h.
|
protected |
Definition at line 120 of file MotorSimplemotion.h.
|
protected |
Definition at line 121 of file MotorSimplemotion.h.
|
staticprotected |
Definition at line 119 of file MotorSimplemotion.h.
|
static |
Definition at line 100 of file MotorSimplemotion.h.
|
static |
Definition at line 101 of file MotorSimplemotion.h.
|
static |
Definition at line 103 of file MotorSimplemotion.h.
|
static |
Definition at line 104 of file MotorSimplemotion.h.
|
static |
Definition at line 102 of file MotorSimplemotion.h.
|
static |
Definition at line 105 of file MotorSimplemotion.h.
|
private |
Definition at line 141 of file MotorSimplemotion.h.
|
staticprotected |
Definition at line 112 of file MotorSimplemotion.h.
|
staticprotected |
Definition at line 111 of file MotorSimplemotion.h.
|
protected |
Definition at line 125 of file MotorSimplemotion.h.
|
staticprotected |
Definition at line 124 of file MotorSimplemotion.h.
|
private |
Definition at line 156 of file MotorSimplemotion.h.
|
protected |
Definition at line 134 of file MotorSimplemotion.h.
|
staticprivate |
Definition at line 154 of file MotorSimplemotion.h.
|
private |
Definition at line 147 of file MotorSimplemotion.h.
|
private |
Definition at line 148 of file MotorSimplemotion.h.
Definition at line 108 of file MotorSimplemotion.h.