Open FFBoard
Open source force feedback firmware
Loading...
Searching...
No Matches
RmdMotorCAN.h
Go to the documentation of this file.
1/*
2 * RmdMotorCAN.h
3 *
4 * Created on: Dec 7, 2024
5 * Author: Yannick
6 */
7
8#ifndef USEREXTENSIONS_SRC_RMDMOTORCAN_H_
9#define USEREXTENSIONS_SRC_RMDMOTORCAN_H_
10
11#include "MotorDriver.h"
12#include "cpp_target_config.h"
13#include "CAN.h"
14#include "Encoder.h"
15#include "thread.hpp"
16#include "CanHandler.h"
17#include "CommandHandler.h"
18#include "PersistentStorage.h"
20#ifdef RMDCAN
21#define RMD_THREAD_MEM 256
22#define RMD_THREAD_PRIO 25 // Must be higher than main thread
23
27
29public:
30 RmdMotorCAN(uint8_t instance);
31 virtual ~RmdMotorCAN();
32
34 void turn(int16_t power) override;
35 void stopMotor() override;
36 void startMotor() override;
37 Encoder* getEncoder() override;
38 bool hasIntegratedEncoder() {return true;}
39 void setTorque(int16_t torque);
40 bool motorReady();
41
42 void Run();
43
44 void saveFlash() override; // Write to flash here
45 void restoreFlash() override; // Load from flash
46
47// float getPos_f() override;
48 uint32_t getCpr() override;
49 int32_t getPos() override;
50 void setPos(int32_t pos) override;
51 EncoderType getEncoderType() override;
52
53 void setCanFilter();
55
56 void sendMsg(std::array<uint8_t,8> &data,uint8_t len = 8);
57 void sendCmd(uint8_t cmd);
58
59 void canRxPendCallback(CANPort* port,CAN_rx_msg& msg) override;
60 void updateStatus();
61
62 void requestConstantReports(uint8_t cmd,bool enable,uint16_t interval_10ms);
63
64 void registerCommands();
65 CommandStatus command(const ParsedCommand& cmd,std::vector<CommandReply>& replies) override;
66
67 const uint32_t angleUpdateMs = 10;
68
86private:
88 uint8_t nodeId = 1; // can ID 1-32
89 uint8_t motorId = 0;
90 bool active = false;
91 bool nextAvailable = false;
92 bool available = false;
93 bool activerequests = false;
95
96 char modelName[8] = {0};
97
98 uint32_t lastAngleUpdate = 0;
100
101 float lastPos = 0;
102 uint16_t maxTorque = 1000; // in 0.01A, max 0x7fff
103
104 int32_t filterId = -2;
105
106 int16_t curCurrent = 0;
107 uint8_t curTemp = 0;
108 uint16_t curVoltage = 0;
109
111
112 int32_t posOffset = 0;
113
115};
116
117
122public:
124 const ClassIdentifier getInfo();
126 static bool isCreatable();
127 static ClassIdentifier info;
128 static bool inUse;
129};
130
135public:
137 const ClassIdentifier getInfo();
139 static bool isCreatable();
140 static ClassIdentifier info;
141 static bool inUse;
142};
143#endif
144#endif /* USEREXTENSIONS_SRC_RMDMOTORCAN_H_ */
CommandStatus
EncoderType
Definition Encoder.h:27
RmdCAN_commands
Definition RmdMotorCAN.h:24
Definition CAN.h:120
CommandHandler(const char *clsname, uint16_t clsid, uint8_t instance=0)
Encoder()
Definition Encoder.cpp:18
static bool inUse
static bool isCreatable()
const ClassIdentifier getInfo()
static bool isCreatable()
const ClassIdentifier getInfo()
static bool inUse
bool hasIntegratedEncoder()
Definition RmdMotorCAN.h:38
const uint32_t angleUpdateMs
Definition RmdMotorCAN.h:67
bool requestConstantReportEnable
Definition RmdMotorCAN.h:94
uint8_t curTemp
uint8_t nodeId
Definition RmdMotorCAN.h:88
bool nextAvailable
Definition RmdMotorCAN.h:91
RmdMotorCAN(uint8_t instance)
void sendCmd(uint8_t cmd)
int32_t getPos() override
uint32_t lastAngleUpdate
Definition RmdMotorCAN.h:98
uint16_t curVoltage
void sendMsg(std::array< uint8_t, 8 > &data, uint8_t len=8)
virtual ~RmdMotorCAN()
uint32_t getCpr() override
bool motorReady()
void registerCommands()
uint32_t lastTorqueStatusUpdate_us
Definition RmdMotorCAN.h:99
void updateStatus()
int32_t posOffset
uint16_t maxTorque
void stopMotor() override
void canRxPendCallback(CANPort *port, CAN_rx_msg &msg) override
CANPort * port
Definition RmdMotorCAN.h:87
void turn(int16_t power) override
void saveFlash() override
bool activerequests
Definition RmdMotorCAN.h:93
ErrorStatus lastErrors
void updateRequestMode(bool activerequests)
void errorCb(ErrorStatus &errors)
void setPos(int32_t pos) override
const ClassIdentifier getInfo()=0
void setTorque(int16_t torque)
void requestConstantReports(uint8_t cmd, bool enable, uint16_t interval_10ms)
void startMotor() override
CommandStatus command(const ParsedCommand &cmd, std::vector< CommandReply > &replies) override
char modelName[8]
Definition RmdMotorCAN.h:96
void setCanFilter()
Encoder * getEncoder() override
uint8_t motorId
Definition RmdMotorCAN.h:89
int16_t curCurrent
int32_t filterId
EncoderType getEncoderType() override
void restoreFlash() override
CANPort & canport
static struct @024127060247016123033304002117326322243354210111 data