Skip to content

Commit 832cc07

Browse files
committed
Update theta angle calib and gripper tuning
1 parent 17300a9 commit 832cc07

File tree

7 files changed

+502
-185
lines changed

7 files changed

+502
-185
lines changed

Spectral BLDC Firmware/src/EEPROM.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ void read_config()
169169
controller.Max_temperature = readInt(TEMPERATURE_ERROR);
170170
controller.Max_Vbus = readInt(VOLTAGE_ERROR);
171171
PID.Voltage_limit = readInt(VOLTAGE_LIMIT);
172+
controller.theta_offset = readFloat(THETA_OFFSET);
173+
172174
}
173175

174176
/// @brief Clean the config that is saved in the EEPROM
@@ -228,19 +230,20 @@ void Write_config()
228230

229231
writeInt(TEMPERATURE_ERROR,controller.Max_temperature);
230232
writeInt(VOLTAGE_ERROR,controller.Max_Vbus);
233+
writeFloat(THETA_OFFSET, controller.theta_offset);
231234
writeInt(VOLTAGE_LIMIT,PID.Voltage_limit);
232235

233236
}
234237

235238
/// @brief Reset to default config. First write to EEPROM then read it back.
236239
void Set_Default_config(){
237240

238-
writeInt(SERIAL_NUMBER_EEPROM,1);
241+
writeInt(SERIAL_NUMBER_EEPROM,1111);
239242
writeInt(HARDWARE_VERSION_EEPROM, 1);
240-
writeInt(BATCH_DATA_EEPROM, 2732024);
243+
writeInt(BATCH_DATA_EEPROM, 24092024);
241244

242245
writeInt(CAN_ID_EEPROM, 0);
243-
writeInt(SOFTWARE_VERSION_EEPROM, 100);
246+
writeInt(SOFTWARE_VERSION_EEPROM, 101);
244247
writeInt(LED_ON_OFF_EEPROM, 1);
245248
writeInt(THERMISTOR_ON_OFF_EEPROM, 0);
246249
writeInt(POLE_PAIR, 7);
@@ -280,6 +283,7 @@ void Set_Default_config(){
280283

281284
writeInt(TEMPERATURE_ERROR,75);
282285
writeInt(VOLTAGE_ERROR,29000);
286+
writeFloat(THETA_OFFSET, 0);
283287
writeInt(VOLTAGE_LIMIT,0);
284288

285289
read_config();

Spectral BLDC Firmware/src/SerialPacketParser.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,18 @@ bool SerialPacketParser::parse(char c, char *command, char *argument)
366366
{
367367
return true;
368368
}
369+
else if (strcmp(command, "Calangle") == 0)
370+
{
371+
return true;
372+
}
373+
else if (strcmp(command, "Offset") == 0)
374+
{
375+
return true;
376+
}
377+
else if (strcmp(command, "Iqoffset") == 0)
378+
{
379+
return true;
380+
}
369381

370382
else
371383
{
@@ -701,6 +713,18 @@ bool SerialPacketParser::parse(char c, char *command, char *argument)
701713
{
702714
return true;
703715
}
716+
else if (strcmp(command, "Calangle") == 0)
717+
{
718+
return true;
719+
}
720+
else if (strcmp(command, "Offset") == 0)
721+
{
722+
return true;
723+
}
724+
else if (strcmp(command, "Iqoffset") == 0)
725+
{
726+
return true;
727+
}
704728

705729
else
706730
{

Spectral BLDC Firmware/src/common.h

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
/* USER CODE END Header */
2121
/* Includes ------------------------------------------------------------------*/
2222

23-
2423
#ifndef COMMON_H
2524
#define COMMON_H
2625

@@ -57,6 +56,8 @@ typedef struct
5756
volatile int Old_Position_Ticks; // position with multiple rotations from previous cycle
5857
volatile float Position_RAD; // Raw position but in radians
5958
volatile float Electric_Angle; // Electrical angle - depends on number of pole pairs
59+
volatile float theta_offset = 0.0f; // will be determined at calibration
60+
6061
volatile int ROTATIONS; // Number of full rotations that motor did
6162
volatile int Velocity_Filter; // Filtered velocity of the motor
6263
volatile int Velocity; // velocity of the motor
@@ -88,7 +89,7 @@ typedef struct
8889
volatile float flux_linkage = 0; // Flux linkage of your BLDC motor
8990
volatile float KV = 0;
9091

91-
volatile int Max_temperature = 75; // Max temperature in degrees
92+
volatile int Max_temperature = 75; // Max temperature in degrees
9293
volatile int Min_temperature = -20; // Min temperature in degrees
9394

9495
volatile int Max_Vbus = 29500; // Max vbus voltage in mV
@@ -98,9 +99,9 @@ typedef struct
9899

99100
volatile int watchdog_time_ms = 0;
100101
volatile bool watchdog_reset = 1;
101-
volatile int watchdog_action = 0; // Hold position, Idle, brake
102+
volatile int watchdog_action = 0; // Hold position, Idle, brake
102103
volatile int Heartbeat_rate_ms = 0; // Motor controller will send data every Heartbeat_rate_ms
103-
volatile bool Send_heartbeat = 0;
104+
volatile bool Send_heartbeat = 0;
104105

105106
volatile bool Activated = 0; // If controller is activated or not
106107
volatile bool Error = 0; // General error
@@ -123,7 +124,7 @@ typedef struct
123124
volatile int Open_loop_voltage = 5000; // Voltage to use when spinning the motor open loop. In mV
124125
volatile float Open_loop_speed = 20.0; // Speed to be used when spinning the motor open loop. In RAD/s
125126
volatile int Number_of_rotations = 8; // Number of open loop electrical rotations during calibration
126-
volatile int Phase_voltage = 5000; // Max voltage to be used during Kv calculation
127+
volatile int Phase_voltage = 5000; // Max voltage to be used during Kv calculation
127128

128129
// Calibration steps
129130
// 0 is neutral, 1 is error, 2 is success
@@ -156,6 +157,27 @@ typedef struct
156157

157158
volatile bool handle_can = 0;
158159

160+
volatile bool hall_trigger = 1; // used to record if hall sensor was triggered or not, normal state of hall is high (1)
161+
volatile bool trigger_value = 0;
162+
163+
// temp / testing ?
164+
volatile int calibration_offset_current = 300;
165+
volatile int temp_var_offset_calib = 0;
166+
volatile int align_state = 0;
167+
volatile int align_counter = 0;
168+
volatile float aligned_angle = 0;
169+
volatile bool align_done = false;
170+
volatile bool calib_done = false;
171+
volatile bool calib_reset = false;
172+
volatile int Velocity_fwd = 0;
173+
volatile int Velocity_bwd = 0;
174+
175+
// Open loop movements
176+
volatile int microstep = 16;
177+
volatile int gosteps = 0;
178+
volatile int step_interval = 1000; // step interval in microseconds
179+
volatile int open_loop_move_done = 0; // 1 = finished, cleared by user
180+
159181
} Measure;
160182

161183
extern Measure controller;
@@ -211,11 +233,10 @@ extern _FOC FOC;
211233
typedef struct
212234
{
213235

214-
215236
volatile int Voltage_limit = 0; // Voltage limit for Ud and Uq voltages. If 0 value of controller.VBUS_mV will be used
216237
// if != 0 it will use that number (if bigger than controller.VBUS_mV it will use controller.VBUS_mV)
217238
// This is extremely important for proper operation of BLDC motor loops since their resistances can be less
218-
// than 1 ohm and using full range of 24V makes the loop unstable.
239+
// than 1 ohm and using full range of 24V makes the loop unstable.
219240
// Usually it setting this to 0 is good (so using full controller.VBUS_mV range)
220241
// Use smaller numbers if you have really small phase resistances like 1 ohm or less
221242

@@ -228,25 +249,25 @@ typedef struct
228249
volatile float P_errSum = 0;
229250

230251
// Speed loop PID
231-
volatile float Kp_v = 0.03; // 0.006 basic values that work for most motors but not optimal
252+
volatile float Kp_v = 0.03; // 0.006 basic values that work for most motors but not optimal
232253
volatile float Ki_v = 0.0003; // 0.0001 basic values that work for most motors but not optimal
233254
volatile float V_errSum = 0;
234255
volatile float Feedforward_speed = 0;
235256
volatile float Velocity_setpoint = 0; // -1.5
236257

237-
volatile float Velocity_limit = 80000; // Clamp integrals to this [TICKS/s]
258+
volatile float Velocity_limit = 80000; // Clamp integrals to this [TICKS/s]
238259
volatile float Velocity_limit_error = 20000000; // [TICKS/s] ; Velocity when we will report error
239260

240261
// current loop PID
241262
volatile float Ki = 0; // zero location
242263

243-
volatile float Kp_id = 2.67; // 2.67
264+
volatile float Kp_id = 2.67; // 2.67
244265
volatile float Ki_id = 1.93; // 1.93
245266
volatile float Id_errSum;
246267
volatile float Id_setpoint = 0;
247268

248269
volatile float Kp_iq = 2.67; // 2.67 // 12.8
249-
volatile float Ki_iq = 1.93; // 1.93 // 9
270+
volatile float Ki_iq = 1.93; // 1.93 // 9
250271
volatile float Iq_errSum;
251272
volatile float Iq_setpoint;
252273

@@ -263,16 +284,15 @@ typedef struct
263284
volatile int Uq_setpoint = 0;
264285
volatile int Ud_setpoint = 0;
265286

266-
267287
} PID_par;
268288

269289
extern PID_par PID;
270290

271291
typedef struct
272292
{
273293

274-
volatile uint8_t previousBytes[5] = {0,0,0,0,0};
275-
volatile bool Same_command = 0;
294+
volatile uint8_t previousBytes[5] = {0, 0, 0, 0, 0};
295+
volatile bool Same_command = 0;
276296
volatile bool At_position = 0;
277297

278298
volatile uint8_t position_setpoint = 0;
@@ -288,11 +308,11 @@ typedef struct
288308
volatile bool activated = 0;
289309

290310
// 0 in motion, 1 object detected closing, 2 object detected opening, 3 at positon
291-
volatile int object_detection_status = 3;
311+
volatile int object_detection_status = 3;
292312
volatile bool temperature_error = 0;
293313
volatile bool timeout_error = 0;
294314
volatile bool estop_error = 0;
295-
315+
296316
volatile bool release_direction = 0;
297317
volatile bool estop_status = 0;
298318

@@ -302,7 +322,7 @@ typedef struct
302322

303323
volatile int position_ticks = 0;
304324

305-
// Map this to 255 and 0
325+
// Map this to 255 and 0
306326
volatile int max_speed = 80000;
307327
volatile int min_speed = 40;
308328

0 commit comments

Comments
 (0)