TeensyNanoExoCode
Loading...
Searching...
No Matches
Motor.h
Go to the documentation of this file.
1
11#ifndef Motor_h
12#define Motor_h
13
14// Arduino compiles everything in the src folder even if not included so it causes and error for the nano if this is not included.
15#if defined(ARDUINO_TEENSY36) || defined(ARDUINO_TEENSY41)
16
17#include "Arduino.h"
18
19#include "ExoData.h"
20#include "ParseIni.h"
21#include "Board.h"
22#include "Utilities.h"
23
24
25#include <stdint.h>
26
27// TODO: Create base motor class with interface read_data(), send_cmd(), motor_on_off(bool), get_is_left()
28
42class _Motor
43{
44 public:
45 _Motor(config_defs::joint_id id, ExoData* exo_data, int enable_pin);
46 virtual ~_Motor(){};
47
48 //Pure virtual functions, these will have to be defined for each one.
49
53 virtual void read_data() = 0;
54
60 virtual void send_data(float torque) = 0;
61
67 virtual void transaction(float torque) = 0;
68 //void set_controller(int controller); // Changes the low level controller for an individual joint
69
73 virtual void on_off() = 0;
74
79 virtual bool enable() = 0;
80
84 virtual bool enable(bool overide) = 0;
85
89 virtual void zero() = 0;
90
91
97 virtual bool get_is_left(); //
98
104 virtual config_defs::joint_id get_id();
105
106 virtual float get_Kt() = 0;
108 protected:
109 config_defs::joint_id _id; //motor id
110 bool _is_left;
111 ExoData* _data;
112 MotorData* _motor_data;
113 int _enable_pin;
114 bool _prev_motor_enabled;
115 bool _prev_on_state;
116 float _Kt; // Torque constant of the motor, at the motor output. [Nm/A]
117};
118
122class NullMotor : public _Motor
123{
124 public:
125 NullMotor(config_defs::joint_id id, ExoData* exo_data, int enable_pin):_Motor(id, exo_data, enable_pin) {};
126 void read_data() {};
127 void send_data(float torque) {};
128 void transaction(float torque) {};
129 void on_off() {};
130 bool enable() {return true;};
131 bool enable(bool overide) {return true;};
132 void zero() {};
133 float get_Kt() {return 0.0;};
134};
135
136
140class _CANMotor : public _Motor
141{
142 public:
143 _CANMotor(config_defs::joint_id id, ExoData* exo_data, int enable_pin);
144 virtual ~_CANMotor(){};
145 void transaction(float torque);
146 void read_data();
147 void send_data(float torque);
148 void on_off();
149 bool enable();
150 bool enable(bool overide);
151 void zero();
152 float get_Kt();
153 void check_response();
154
155 protected:
156
157 void set_Kt(float Kt);
158
169 //TODO Chance : change the return to uint and check that stuff still works
170 float _float_to_uint(float x, float x_min, float x_max, int bits);
171
182 float _uint_to_float(unsigned int x_int, float x_min, float x_max, int bits);
183
188 void _handle_read_failure();
189
190 float _KP_MIN;
191 float _KP_MAX;
192 float _KD_MIN;
193 float _KD_MAX;
194 float _P_MAX;
195 float _I_MAX;
196 float _V_MAX;
197 int _timeout_count = 0;
198 bool _enable_response;
199 const uint32_t _timeout = 500;
200 const uint32_t _timeout_count_max = 40;
202 std::queue<float> _measured_current;
203 const int _current_queue_size = 25;
204 const float _variance_threshold = 0.01;
206};
207
211class AK60 : public _CANMotor
212{
213 public:
214 AK60(config_defs::joint_id id, ExoData* exo_data, int enable_pin); // constructor: type is the motor type
215 ~AK60(){};
216};
217
221class AK60_v1_1 : public _CANMotor
222{
223 public:
224 AK60_v1_1(config_defs::joint_id id, ExoData* exo_data, int enable_pin); // constructor: type is the motor type
225 ~AK60_v1_1(){};
226};
227
231class AK60_v1_1_T : public _CANMotor
232{
233public:
234 AK60_v1_1_T(config_defs::joint_id id, ExoData* exo_data, int enable_pin); // constructor: type is the motor type
235 ~AK60_v1_1_T() {};
236};
237
241class AK80 : public _CANMotor
242{
243 public:
244 AK80(config_defs::joint_id id, ExoData* exo_data, int enable_pin); // constructor: type is the motor type
245 ~AK80(){};
246};
247
248#endif
249#endif
Declares a class used to store data for the Exo to access.
Declares the functions needed and defines mapping between the INI keys and the exo components.
Class to store all the data related to the exo.
Definition ExoData.h:38
Definition MotorData.h:25
joint_id
Definition ParseIni.h:106
bool get_is_left(config_defs::joint_id id)
Takes in the joint id and returns if the left indicator bit is set as a bool.
Definition Utilities.cpp:10