Skip to content

Commit dce7906

Browse files
committed
extension of the commander, + typo fix in pwm mag sensor
1 parent e68ca71 commit dce7906

File tree

8 files changed

+75
-15
lines changed

8 files changed

+75
-15
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ Therefore this is an attempt to:
2020
> - bugfixes commander
2121
> - bugfix `voltage_limit` when provided `phase_resistance`
2222
> - bugfix `hall_sensor` examples
23+
> - added examples fot the powershield
24+
> - added initial support for `MagneticSensorPWM`
25+
> - extension of the `Commander` interface
2326
2427

2528
## Arduino *SimpleFOCShield* v2.0.3

examples/utils/sensor_test/magnetic_sensors/magnetic_sensor_pwm_example/magnetic_sensor_pwm_software_interrupt/magnetic_sensor_pwm_software_interrupt.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ MagneticSensorPWM sensor = MagneticSensorPWM(A0, 4, 904);
1616
void doPWM(){sensor.handlePWM();}
1717

1818
// encoder interrupt init
19-
PciListenerImp listenerPWM(sensor.pinPWM, doPWM);}
19+
PciListenerImp listenerPWM(sensor.pinPWM, doPWM);
2020

2121
void setup() {
2222
// monitoring port

keywords.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ sensor_offset KEYWORD2
122122
zero_electric_angle KEYWORD2
123123
verbose KEYWORD2
124124
decimal_places KEYWORD2
125+
phase_resistance KEYWORD2
126+
modulation_centered KEYWORD2
125127

126128

127129

src/common/base_classes/FOCMotor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ class FOCMotor
169169
LowPassFilter LPF_current_q{DEF_CURR_FILTER_Tf};//!< parameter determining the current Low pass filter configuration
170170
LowPassFilter LPF_current_d{DEF_CURR_FILTER_Tf};//!< parameter determining the current Low pass filter configuration
171171
PIDController PID_velocity{DEF_PID_VEL_P,DEF_PID_VEL_I,DEF_PID_VEL_D,DEF_PID_VEL_RAMP,DEF_PID_VEL_LIMIT};//!< parameter determining the velocity PID configuration
172-
PIDController P_angle{DEF_P_ANGLE_P,0,0,1e10,DEF_VEL_LIM}; //!< parameter determining the position PID configuration
172+
PIDController P_angle{DEF_P_ANGLE_P,0,0,0,DEF_VEL_LIM}; //!< parameter determining the position PID configuration
173173
LowPassFilter LPF_velocity{DEF_VEL_FILTER_Tf};//!< parameter determining the velocity Low pass filter configuration
174174
LowPassFilter LPF_angle{0.0};//!< parameter determining the angle low pass filter configuration
175175
unsigned int motion_downsample = DEF_MOTION_DOWNSMAPLE; //!< parameter defining the ratio of downsampling for move commad

src/common/defaults.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#define DEF_PID_CURR_P 3 //!< default PID controller P value
2424
#define DEF_PID_CURR_I 300.0 //!< default PID controller I value
2525
#define DEF_PID_CURR_D 0.0 //!< default PID controller D value
26-
#define DEF_PID_CURR_RAMP 1e11 //!< default PID controller voltage ramp value
26+
#define DEF_PID_CURR_RAMP 0 //!< default PID controller voltage ramp value
2727
#define DEF_PID_CURR_LIMIT (DEF_POWER_SUPPLY) //!< default PID controller voltage limit
2828
#define DEF_CURR_FILTER_Tf 0.005 //!< default currnet filter time constant
2929
#endif

src/common/pid.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,15 @@ float PIDController::operator() (float error){
4040
// antiwindup - limit the output variable
4141
output = _constrain(output, -limit, limit);
4242

43-
// limit the acceleration by ramping the output
44-
float output_rate = (output - output_prev)/Ts;
45-
if (output_rate > output_ramp)
46-
output = output_prev + output_ramp*Ts;
47-
else if (output_rate < -output_ramp)
48-
output = output_prev - output_ramp*Ts;
49-
43+
// if output ramp defined
44+
if(output_ramp > 0){
45+
// limit the acceleration by ramping the output
46+
float output_rate = (output - output_prev)/Ts;
47+
if (output_rate > output_ramp)
48+
output = output_prev + output_ramp*Ts;
49+
else if (output_rate < -output_ramp)
50+
output = output_prev - output_ramp*Ts;
51+
}
5052
// saving for the next pass
5153
integral_prev = integral;
5254
output_prev = output;

src/communication/Commander.cpp

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,10 @@ void Commander::motor(FOCMotor* motor, char* user_command) {
170170
}
171171
break;
172172
case CMD_MOTION_TYPE:
173-
printVerbose(F("Motion: "));
173+
printVerbose(F("Motion:"));
174174
switch(sub_cmd){
175175
case SCMD_DOWNSAMPLE:
176-
printVerbose(F("downsample: "));
176+
printVerbose(F(" downsample: "));
177177
if(!GET) motor->motion_downsample = value;
178178
println((int)motor->motion_downsample);
179179
break;
@@ -224,6 +224,38 @@ void Commander::motor(FOCMotor* motor, char* user_command) {
224224
if(!GET) (bool)value ? motor->enable() : motor->disable();
225225
println(motor->enabled);
226226
break;
227+
case CMD_PWMMOD:
228+
// PWM modulation change
229+
printVerbose(F("PWM Mod | "));
230+
switch (sub_cmd){
231+
case SCMD_PWMMOD_TYPE: // zero offset
232+
printVerbose(F("type: "));
233+
if(!GET) motor->foc_modulation = (FOCModulationType)value;
234+
switch(motor->foc_modulation){
235+
case FOCModulationType::SinePWM:
236+
println(F("SinePWM"));
237+
break;
238+
case FOCModulationType::SpaceVectorPWM:
239+
println(F("SVPWM"));
240+
break;
241+
case FOCModulationType::Trapezoid_120:
242+
println(F("Trap 120"));
243+
break;
244+
case FOCModulationType::Trapezoid_150:
245+
println(F("Trap 150"));
246+
break;
247+
}
248+
break;
249+
case SCMD_PWMMOD_CENTER: // centered modulation
250+
printVerbose(F("center: "));
251+
if(!GET) motor->modulation_centered = value;
252+
println(motor->modulation_centered);
253+
break;
254+
default:
255+
printError();
256+
break;
257+
}
258+
break;
227259
case CMD_RESIST:
228260
// enable/disable
229261
printVerbose(F("R phase: "));
@@ -271,15 +303,15 @@ void Commander::motor(FOCMotor* motor, char* user_command) {
271303
break;
272304
case 2: // get voltage d
273305
printVerbose(F("Vd: "));
274-
println(motor->voltage.q);
306+
println(motor->voltage.d);
275307
break;
276308
case 3: // get current q
277309
printVerbose(F("Cq: "));
278310
println(motor->current.q);
279311
break;
280312
case 4: // get current d
281313
printVerbose(F("Cd: "));
282-
println(motor->current.q);
314+
println(motor->current.d);
283315
break;
284316
case 5: // get velocity
285317
printVerbose(F("vel: "));
@@ -289,6 +321,22 @@ void Commander::motor(FOCMotor* motor, char* user_command) {
289321
printVerbose(F("angle: "));
290322
println(motor->shaft_angle);
291323
break;
324+
case 7: // get all states
325+
printVerbose(F("all: "));
326+
print(motor->target);
327+
print(";");
328+
print(motor->voltage.q);
329+
print(";");
330+
print(motor->voltage.d);
331+
print(";");
332+
print(motor->current.q);
333+
print(";");
334+
print(motor->current.d);
335+
print(";");
336+
print(motor->shaft_velocity);
337+
print(";");
338+
println(motor->shaft_angle);
339+
break;
292340
default:
293341
printError();
294342
break;

src/communication/commands.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#define CMD_SENSOR 'S' //!< sensor offsets
1616
#define CMD_MONITOR 'M' //!< monitoring
1717
#define CMD_RESIST 'R' //!< motor phase resistance
18+
#define CMD_PWMMOD 'W' //!< pwm modulation
1819

1920
// commander configuration
2021
#define CMD_SCAN '?' //!< command scaning the network - only for commander
@@ -41,5 +42,9 @@
4142
#define SCMD_CLEAR 'C' //!< Clear all monitored variables
4243
#define SCMD_GET 'G' //!< Get variable only one value
4344
#define SCMD_SET 'S' //!< Set variables to be monitored
44-
45+
46+
#define SCMD_PWMMOD_TYPE 'T' //!<< Pwm modulation type
47+
#define SCMD_PWMMOD_CENTER 'C' //!<< Pwm modulation center flag
48+
49+
4550
#endif

0 commit comments

Comments
 (0)