Skip to content

Commit 30510c7

Browse files
committed
intermediate commit for reaftoring of current sense
1 parent 5889c49 commit 30510c7

File tree

27 files changed

+374
-307
lines changed

27 files changed

+374
-307
lines changed

examples/hardware_specific_examples/B_G431B_ESC1/B_G431B_ESC1.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ void setup() {
4040
driver.init();
4141
// link the motor and the driver
4242
motor.linkDriver(&driver);
43+
// link current sense and the driver
44+
currentSense.linkDriver(&driver);
4345

4446
// current sensing
4547
currentSense.init();

examples/hardware_specific_examples/DRV8302_driver/esp32_current_control_low_side/esp32_current_control_low_side.ino

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ void setup() {
7979
driver.init();
8080
// link the motor and the driver
8181
motor.linkDriver(&driver);
82+
// link current sense and the driver
83+
cs.linkDriver(&driver);
84+
85+
// align voltage
8286
motor.voltage_sensor_align = 0.5;
8387

8488
// control loop type and torque mode
@@ -124,7 +128,6 @@ void setup() {
124128
motor.init();
125129

126130
cs.init();
127-
cs.driverSync(&driver);
128131
// driver 8302 has inverted gains on all channels
129132
cs.gain_a *=-1;
130133
cs.gain_b *=-1;

examples/hardware_specific_examples/SimpleFOC-PowerShield/version_v02/single_full_control_example/single_full_control_example.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ void setup() {
3333
driver.init();
3434
// link driver
3535
motor.linkDriver(&driver);
36+
// link current sense and the driver
37+
current_sense.linkDriver(&driver);
3638

3739
motor.voltage_sensor_align = 1;
3840
// set control loop type to be used

examples/hardware_specific_examples/SimpleFOCShield/version_v2/double_full_control_example/double_full_control_example.ino

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,16 @@ void setup() {
5656
driver1.init();
5757
// link driver
5858
motor1.linkDriver(&driver1);
59+
// link current sense and the driver
60+
current_sense1.linkDriver(&driver1);
61+
5962
// power supply voltage [V]
6063
driver2.voltage_power_supply = 12;
6164
driver2.init();
6265
// link driver
6366
motor2.linkDriver(&driver2);
67+
// link current sense and the driver
68+
current_sense2.linkDriver(&driver2);
6469

6570
// set control loop type to be used
6671
motor1.controller = MotionControlType::torque;

examples/hardware_specific_examples/SimpleFOCShield/version_v2/single_full_control_example/single_full_control_example.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ void setup() {
3434
driver.init();
3535
// link driver
3636
motor.linkDriver(&driver);
37+
// link current sense and the driver
38+
current_sense.linkDriver(&driver);
3739

3840
// set control loop type to be used
3941
motor.controller = MotionControlType::torque;

examples/motion_control/torque_control/encoder/current_control/current_control.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ void setup() {
3939
driver.init();
4040
// link driver
4141
motor.linkDriver(&driver);
42+
// link current sense and the driver
43+
current_sense.linkDriver(&driver);
4244

4345
// current sense init hardware
4446
current_sense.init();

keywords.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ getFOCCurrents KEYWORD2
9191
getDCCurrent KEYWORD2
9292
setPwm KEYWORD2
9393
driverAlign KEYWORD2
94-
driverSync KEYWORD2
94+
linkDriver KEYWORD2
9595
add KEYWORD2
9696
run KEYWORD2
9797
attach KEYWORD2

src/BLDCMotor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ int BLDCMotor::alignCurrentSense() {
143143
if(monitor_port) monitor_port->println(F("MOT: Align current sense."));
144144

145145
// align current sense and the driver
146-
exit_flag = current_sense->driverAlign(driver, voltage_sensor_align);
146+
exit_flag = current_sense->driverAlign(voltage_sensor_align);
147147
if(!exit_flag){
148148
// error in current sense - phase either not measured or bad connection
149149
if(monitor_port) monitor_port->println(F("MOT: Align error!"));

src/common/base_classes/CurrentSense.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,11 @@ DQCurrent_s CurrentSense::getFOCCurrents(float angle_el){
6464
return_current.d = i_alpha * ct + i_beta * st;
6565
return_current.q = i_beta * ct - i_alpha * st;
6666
return return_current;
67+
}
68+
69+
/**
70+
Driver linking to the current sense
71+
*/
72+
void CurrentSense::linkDriver(BLDCDriver* _driver) {
73+
driver = _driver;
6774
}

src/common/base_classes/CurrentSense.h

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,24 @@ class CurrentSense{
1313

1414
/**
1515
* Function intialising the CurrentSense class
16-
* All the necessary intialisations of adc and sync should be implemented here
16+
* - All the necessary intialisations of adc and sync should be implemented here
17+
*
18+
* @returns - 0 - for failure & 1 - for success
1719
*/
18-
virtual void init() = 0;
20+
virtual int init() = 0;
1921

2022
/**
21-
* Function intended to implement all that is needed to sync and current sensing with the driver.
22-
* If no such thing is needed it can be left empty (return 1)
23-
* @returns - 0 - for failure & 1 - for success
23+
* Linking the current sense with the motor driver
24+
* Only necessary if synchronisation in between the two is required
2425
*/
25-
virtual int driverSync(BLDCDriver *driver) = 0;
26+
void linkDriver(BLDCDriver *driver);
2627

27-
// calibration variables
28+
// variables
2829
bool skip_align = false; //!< variable signaling that the phase current direction should be verified during initFOC()
30+
31+
BLDCDriver* driver; //!< driver link
32+
void* params = 0; //!< pointer to hardware specific parameters of current sensing
33+
2934
/**
3035
* Function intended to verify if:
3136
* - phase current are oriented properly
@@ -34,7 +39,7 @@ class CurrentSense{
3439
* This function corrects the alignment errors if possible ans if no such thing is needed it can be left empty (return 1)
3540
* @returns - 0 - for failure & positive number (with status) - for success
3641
*/
37-
virtual int driverAlign(BLDCDriver *driver, float voltage) = 0;
42+
virtual int driverAlign(float align_voltage) = 0;
3843

3944
/**
4045
* Function rading the phase currents a, b and c
@@ -62,6 +67,8 @@ class CurrentSense{
6267
* @param angle_el - motor electrical angle
6368
*/
6469
DQCurrent_s getFOCCurrents(float angle_el);
70+
71+
6572
};
6673

6774
#endif

0 commit comments

Comments
 (0)