Skip to content

Commit c5d01e7

Browse files
committed
RMD MyActuator CAN motor class
1 parent cc47be6 commit c5d01e7

File tree

9 files changed

+604
-2
lines changed

9 files changed

+604
-2
lines changed

Firmware/FFBoard/Src/Axis.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "VescCAN.h"
1313
#include "ODriveCAN.h"
1414
#include "MotorSimplemotion.h"
15+
#include "RmdMotorCAN.h"
1516

1617
//////////////////////////////////////////////
1718
/*
@@ -48,6 +49,9 @@ const std::vector<class_entry<MotorDriver>> Axis::axis1_drivers =
4849
#ifdef SIMPLEMOTION
4950
add_class<MotorSimplemotion1,MotorDriver>(9),
5051
#endif
52+
#ifdef RMDCAN
53+
add_class<RmdMotorCAN1,MotorDriver>(11),
54+
#endif
5155
};
5256

5357
/**
@@ -69,6 +73,9 @@ const std::vector<class_entry<MotorDriver>> Axis::axis2_drivers =
6973
#ifdef VESC
7074
add_class<VESC_2,MotorDriver>(8),
7175
#endif
76+
#ifdef RMDCAN
77+
add_class<RmdMotorCAN2,MotorDriver>(12),
78+
#endif
7279
//#ifdef SIMPLEMOTION
7380
// add_class<MotorSimplemotion2,MotorDriver>(10), // TODO this likely does not work reliably with a single uart port and multiple devices
7481
//#endif

Firmware/FFBoard/Src/MotorDriver.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "MotorPWM.h"
1414
#include "VescCAN.h"
1515
#include "MotorSimplemotion.h"
16+
#include "RmdMotorCAN.h"
1617

1718
ClassIdentifier MotorDriver::info ={.name = "None" , .id=CLSID_MOT_NONE, .visibility = ClassVisibility::visible};
1819

@@ -46,6 +47,10 @@ const std::vector<class_entry<MotorDriver>> MotorDriver::all_drivers =
4647
add_class<MotorSimplemotion1,MotorDriver>(9),
4748
add_class<MotorSimplemotion2,MotorDriver>(10),
4849
#endif
50+
#ifdef RMDCAN
51+
add_class<RmdMotorCAN1,MotorDriver>(11),
52+
add_class<RmdMotorCAN2,MotorDriver>(12),
53+
#endif
4954
};
5055

5156
/**

Firmware/FFBoard/UserExtensions/Inc/ClassIDs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ enum class ClassType : uint16_t {
7878
#define CLSID_MOT_VESC1 0x88
7979
#define CLSID_MOT_SM1 0x89
8080
#define CLSID_MOT_SM2 0x8A
81+
#define CLSID_MOT_RMD1 0x8B
82+
#define CLSID_MOT_RMD2 0x8C
8183

8284
// Internal classes
8385
#define CLSID_AXIS 0xA01
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
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"
19+
20+
#ifdef RMDCAN
21+
#define RMD_THREAD_MEM 256
22+
#define RMD_THREAD_PRIO 25 // Must be higher than main thread
23+
24+
enum class RmdCAN_commands : uint32_t{
25+
canid,errors,maxtorque,current,temperature,voltage,activerequests,modelname
26+
};
27+
28+
class RmdMotorCAN : public MotorDriver,public PersistentStorage, public Encoder, public CanHandler, public CommandHandler, cpp_freertos::Thread {
29+
public:
30+
RmdMotorCAN(uint8_t instance);
31+
virtual ~RmdMotorCAN();
32+
33+
const ClassIdentifier getInfo() = 0;
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();
54+
void updateRequestMode(bool activerequests);
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+
69+
union ErrorStatus {
70+
struct ErrorStatur_s{
71+
uint16_t res1 : 1,
72+
stall : 1,
73+
undervoltage : 1,
74+
overvoltage : 1,
75+
overcurrent : 1,
76+
overpower : 1,
77+
calibrationWriteErr : 1,
78+
overspeed : 1,
79+
overtemp : 1,
80+
calibrationErr : 1,
81+
res2 : 6;
82+
};
83+
uint16_t asInt;
84+
ErrorStatur_s flags;
85+
};
86+
private:
87+
CANPort* port = &canport;
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;
94+
bool requestConstantReportEnable = false;
95+
96+
char modelName[8] = {0};
97+
98+
uint32_t lastAngleUpdate = 0;
99+
uint32_t lastTorqueStatusUpdate_us = 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+
110+
ErrorStatus lastErrors = {0};
111+
112+
int32_t posOffset = 0;
113+
114+
void errorCb(ErrorStatus &errors);
115+
};
116+
117+
118+
/**
119+
* Instance 1 of RMD motor
120+
*/
121+
class RmdMotorCAN1 : public RmdMotorCAN{
122+
public:
123+
RmdMotorCAN1() : RmdMotorCAN{0} {inUse = true;}
124+
const ClassIdentifier getInfo();
125+
~RmdMotorCAN1(){inUse = false;}
126+
static bool isCreatable();
127+
static ClassIdentifier info;
128+
static bool inUse;
129+
};
130+
131+
/**
132+
* Instance 2 of RMD motor
133+
*/
134+
class RmdMotorCAN2 : public RmdMotorCAN{
135+
public:
136+
RmdMotorCAN2() : RmdMotorCAN{1} {inUse = true;}
137+
const ClassIdentifier getInfo();
138+
~RmdMotorCAN2(){inUse = false;}
139+
static bool isCreatable();
140+
static ClassIdentifier info;
141+
static bool inUse;
142+
};
143+
#endif
144+
#endif /* USEREXTENSIONS_SRC_RMDMOTORCAN_H_ */

Firmware/FFBoard/UserExtensions/Inc/eeprom_addresses.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313

1414
#include "main.h"
1515
// Change this to the amount of currently registered variables
16-
#define NB_OF_VAR 153
16+
#define NB_OF_VAR 159
1717
extern const uint16_t VirtAddVarTab[NB_OF_VAR];
1818

1919
// Amount of variables in exportable list
20-
#define NB_EXPORTABLE_ADR 138
20+
#define NB_EXPORTABLE_ADR 144
2121
extern const uint16_t exportableFlashAddresses[NB_EXPORTABLE_ADR];
2222

2323

@@ -164,6 +164,13 @@ uint16_t EE_ReadVariable(uint16_t VirtAddress, uint16_t* Data) will return 1 if
164164
#define ADR_TMC3_FLUX_I 0x3AA
165165
#define ADR_TMC3_PHIE_OFS 0x3AB
166166
#define ADR_TMC3_TRQ_FILT 0x3AC
167+
// RMD CAN Motor
168+
#define ADR_RMD1_DATA1 0x3C0 //0-4 CAN ID
169+
#define ADR_RMD1_TORQUE 0x3C1 //Maximum current
170+
#define ADR_RMD1_OFFSET 0x3C2 //Position offset
171+
#define ADR_RMD2_DATA1 0x3C3
172+
#define ADR_RMD2_TORQUE 0x3C4
173+
#define ADR_RMD2_OFFSET 0x3C5
167174
// Odrive
168175
#define ADR_ODRIVE_CANID 0x3D0 //0-6 ID M0, 7-12 ID M1, 13-15 can speed
169176
#define ADR_ODRIVE_SETTING1_M0 0x3D1

0 commit comments

Comments
 (0)