Skip to content

Commit 2cf533b

Browse files
committed
Merge branch 'dev'
2 parents a56ef53 + 11a2f12 commit 2cf533b

File tree

11 files changed

+47
-27
lines changed

11 files changed

+47
-27
lines changed

.github/workflows/ccpp.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ jobs:
1010
arduino-boards-fqbn:
1111
- arduino:avr:uno # arudino uno
1212
- arduino:sam:arduino_due_x # arduino due
13+
- arduino:avr:mega # arduino mega2650
14+
- arduino:avr:leonardo # arduino leonardo
1315
- arduino:samd:nano_33_iot # samd21
1416
- adafruit:samd:adafruit_metro_m4 # samd51
1517
- esp32:esp32:esp32doit-devkit-v1 # esp32
@@ -29,6 +31,12 @@ jobs:
2931
- arduino-boards-fqbn: arduino:sam:arduino_due_x # arduino due - one full example
3032
sketch-names: single_full_control_example.ino
3133

34+
- arduino-boards-fqbn: arduino:avr:leonardo # arduino leonardo - one full example
35+
sketch-names: open_loop_position_example.ino
36+
37+
- arduino-boards-fqbn: arduino:avr:mega # arduino mega2660 - one full example
38+
sketch-names: single_full_control_example.ino
39+
3240
- arduino-boards-fqbn: arduino:samd:nano_33_iot # samd21
3341
sketch-names: nano33IoT_velocity_control.ino, smartstepper_control.ino
3442

@@ -54,6 +62,9 @@ jobs:
5462
- arduino-boards-fqbn: STMicroelectronics:stm32:Disco:pnum=B_G431B_ESC1 # B-G431-ESC1
5563
platform-url: https://github.com/stm32duino/BoardManagerFiles/raw/main/package_stmicroelectronics_index.json
5664
sketch-names: B_G431B_ESC1.ino
65+
build-properties:
66+
B_G431B_ESC1:
67+
-DHAL_OPAMP_MODULE_ENABLED
5768

5869
- arduino-boards-fqbn: STMicroelectronics:stm32:GenF4:pnum=GENERIC_F405RGTX # stm32f405 - odrive
5970
platform-url: https://github.com/stm32duino/BoardManagerFiles/raw/main/package_stmicroelectronics_index.json
@@ -63,7 +74,6 @@ jobs:
6374
platform-url: https://github.com/stm32duino/BoardManagerFiles/raw/main/package_stmicroelectronics_index.json
6475
sketch-names: single_full_control_example.ino, stm32_spi_alt_example.ino, sdouble_full_control_example.ino
6576

66-
6777

6878
# Do not cancel all jobs / architectures if one job fails
6979
fail-fast: false
@@ -78,3 +88,4 @@ jobs:
7888
platform-url: ${{ matrix.platform-url }}
7989
sketch-names: ${{ matrix.sketch-names }}
8090
sketches-exclude: ${{ matrix.sketches-exclude }}
91+
build-properties: ${{ toJson(matrix.build-properties) }}

examples/motion_control/velocity_motion_control/magnetic_sensor/velocity_control/velocity_control.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void setup() {
7777
motor.initFOC();
7878

7979
// add target command T
80-
command.add('T', doTarget, "target voltage");
80+
command.add('T', doTarget, "target velocity");
8181

8282
Serial.println(F("Motor ready."));
8383
Serial.println(F("Set the target velocity using serial terminal:"));
@@ -103,4 +103,4 @@ void loop() {
103103

104104
// user communication
105105
command.run();
106-
}
106+
}

examples/utils/sensor_test/hall_sensors/hall_sensor_example/hall_sensor_example.ino

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// HallSensor(int hallA, int hallB , int cpr, int index)
1212
// - hallA, hallB, hallC - HallSensor A, B and C pins
1313
// - pp - pole pairs
14-
HallSensor sensor = HallSensor(2, 3, 4, 11);
14+
HallSensor sensor = HallSensor(2, 3, 4, 14);
1515

1616
// Interrupt routine intialisation
1717
// channel A and B callbacks
@@ -44,4 +44,5 @@ void loop() {
4444
Serial.print(sensor.getAngle());
4545
Serial.print("\t");
4646
Serial.println(sensor.getVelocity());
47+
delay(100);
4748
}

src/BLDCMotor.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,7 @@ class BLDCMotor: public FOCMotor
7070
float Ua, Ub, Uc;//!< Current phase voltages Ua,Ub and Uc set to motor
7171
float Ualpha, Ubeta; //!< Phase voltages U alpha and U beta used for inverse Park and Clarke transform
7272

73-
74-
private:
75-
// FOC methods
76-
/**
73+
/**
7774
* Method using FOC to set Uq to the motor at the optimal angle
7875
* Heart of the FOC algorithm
7976
*
@@ -82,6 +79,10 @@ class BLDCMotor: public FOCMotor
8279
* @param angle_el current electrical angle of the motor
8380
*/
8481
void setPhaseVoltage(float Uq, float Ud, float angle_el);
82+
83+
private:
84+
// FOC methods
85+
8586
/** Sensor alignment to electrical 0 angle of the motor */
8687
int alignSensor();
8788
/** Current sense and motor phase alignment */

src/common/base_classes/Sensor.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include "../foc_utils.h"
33
#include "../time_utils.h"
44

5-
// TODO add an init method to make the startup smoother by initializing internal variables to current values rather than 0
5+
66

77
void Sensor::update() {
88
float val = getSensorAngle();
@@ -18,17 +18,17 @@ void Sensor::update() {
1818
float Sensor::getVelocity() {
1919
// calculate sample time
2020
float Ts = (angle_prev_ts - vel_angle_prev_ts)*1e-6;
21-
// quick fix for strange cases (micros overflow)
22-
if(Ts <= 0) Ts = 1e-3f;
23-
// velocity calculation
24-
float vel = ( (float)(full_rotations - vel_full_rotations)*_2PI + (angle_prev - vel_angle_prev) ) / Ts;
25-
// save variables for future pass
21+
if (Ts<minDeltaT) return velocity; // don't update velocity if deltaT is too small
22+
23+
velocity = ( (float)(full_rotations - vel_full_rotations)*_2PI + (angle_prev - vel_angle_prev) ) / Ts;
2624
vel_angle_prev = angle_prev;
2725
vel_full_rotations = full_rotations;
2826
vel_angle_prev_ts = angle_prev_ts;
29-
return vel;
27+
return velocity;
3028
}
3129

30+
31+
3232
void Sensor::init() {
3333
// initialize all the internal variables of Sensor to ensure a "smooth" startup (without a 'jump' from zero)
3434
getSensorAngle(); // call once

src/common/base_classes/Sensor.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ class Sensor{
101101
* 1 - ecoder with index (with index not found yet)
102102
*/
103103
virtual int needsSearch();
104+
105+
/**
106+
* Minimum time between updates to velocity. If time elapsed is lower than this, the velocity is not updated.
107+
*/
108+
float minDeltaT = 0.000100; // default is 100 microseconds, or 10kHz
109+
104110
protected:
105111
/**
106112
* Get current shaft angle from the sensor hardware, and
@@ -120,9 +126,10 @@ class Sensor{
120126
virtual void init();
121127

122128
// velocity calculation variables
123-
float angle_prev=0; // result of last call to getSensorAngle(), used for full rotations and velocity
129+
float velocity=0.0f;
130+
float angle_prev=0.0f; // result of last call to getSensorAngle(), used for full rotations and velocity
124131
long angle_prev_ts=0; // timestamp of last call to getAngle, used for velocity
125-
float vel_angle_prev=0; // angle at last call to getVelocity, used for velocity
132+
float vel_angle_prev=0.0f; // angle at last call to getVelocity, used for velocity
126133
long vel_angle_prev_ts=0; // last velocity calculation timestamp
127134
int32_t full_rotations=0; // full rotation tracking
128135
int32_t vel_full_rotations=0; // previous full rotation value for velocity calculation

src/current_sense/hardware_specific/stm32/stm32f1/stm32f1_hal.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ uint32_t _timerToRegularTRGO(HardwareTimer* timer){
3333
return ADC_EXTERNALTRIGCONV_T3_TRGO;
3434
#ifdef TIM8 // if defined timer 8
3535
else if(timer->getHandle()->Instance == TIM8)
36-
return ADC_EXTERNALTRIGINJECCONV_T8_TRGO;
36+
return ADC_EXTERNALTRIGCONV_T8_TRGO;
3737
#endif
3838
else
3939
return _TRGO_NOT_AVAILABLE;

src/drivers/hardware_specific/atmega2560_mcu.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ void* _configure4PWM(long pwm_frequency,const int pin1A, const int pin1B, const
8686
_pinHighFrequency(pin2A);
8787
_pinHighFrequency(pin2B);
8888
GenericDriverParams* params = new GenericDriverParams {
89-
.pins = { pin1A, pin2A, pin2A, pin2B },
89+
.pins = { pin1A, pin1B, pin2A, pin2B },
9090
.pwm_frequency = pwm_frequency
9191
};
9292
return params;
@@ -146,8 +146,8 @@ void* _configure6PWM(long pwm_frequency, float dead_zone, const int pinA_h, cons
146146
ret_flag += _configureComplementaryPair(pinC_h, pinC_l);
147147
if (ret_flag!=0) return SIMPLEFOC_DRIVER_INIT_FAILED;
148148
GenericDriverParams* params = new GenericDriverParams {
149-
.pins = { pinA_h,, pinA_l, pinB_h, pinB_l, pinC_h, pinC_l },
150-
.pwm_frequency = pwm_frequency
149+
.pins = { pinA_h, pinA_l, pinB_h, pinB_l, pinC_h, pinC_l },
150+
.pwm_frequency = pwm_frequency,
151151
.dead_zone = dead_zone
152152
};
153153
return params;

src/drivers/hardware_specific/atmega328_mcu.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void* _configure4PWM(long pwm_frequency,const int pin1A, const int pin1B, const
8181
_pinHighFrequency(pin2A);
8282
_pinHighFrequency(pin2B);
8383
GenericDriverParams* params = new GenericDriverParams {
84-
.pins = { pin1A, pin2A, pin2A, pin2B },
84+
.pins = { pin1A, pin1B, pin2A, pin2B },
8585
.pwm_frequency = pwm_frequency
8686
};
8787
return params;
@@ -170,4 +170,4 @@ void _writeDutyCycle6PWM(float dc_a, float dc_b, float dc_c, void* params){
170170
_setPwmPair(((GenericDriverParams*)params)->pins[4], ((GenericDriverParams*)params)->pins[5], dc_c*255.0, ((GenericDriverParams*)params)->dead_zone*255.0);
171171
}
172172

173-
#endif
173+
#endif

src/drivers/hardware_specific/atmega32u4_mcu.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ void* _configure4PWM(long pwm_frequency,const int pin1A, const int pin1B, const
8989
_pinHighFrequency(pin2A);
9090
_pinHighFrequency(pin2B);
9191
GenericDriverParams* params = new GenericDriverParams {
92-
.pins = { pin1A, pin2A, pin2A, pin2B },
92+
.pins = { pin1A, pin1B, pin2A, pin2B },
9393
.pwm_frequency = pwm_frequency
9494
};
9595
return params;
@@ -158,8 +158,8 @@ void* _configure6PWM(long pwm_frequency, float dead_zone, const int pinA_h, cons
158158
ret_flag += _configureComplementaryPair(pinC_h, pinC_l);
159159
if (ret_flag!=0) return SIMPLEFOC_DRIVER_INIT_FAILED;
160160
GenericDriverParams* params = new GenericDriverParams {
161-
.pins = { pinA_h,, pinA_l, pinB_h, pinB_l, pinC_h, pinC_l },
162-
.pwm_frequency = pwm_frequency
161+
.pins = { pinA_h, pinA_l, pinB_h, pinB_l, pinC_h, pinC_l },
162+
.pwm_frequency = pwm_frequency,
163163
.dead_zone = dead_zone
164164
};
165165
return params;

0 commit comments

Comments
 (0)