Skip to content

Commit 4934aae

Browse files
author
Richard Unger
committed
add currentsense.enable/disable
1 parent b7300fe commit 4934aae

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

src/BLDCMotor.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ void BLDCMotor::init() {
111111
// disable motor driver
112112
void BLDCMotor::disable()
113113
{
114+
// disable the current sense
115+
if(current_sense) current_sense->disable();
114116
// set zero to PWM
115117
driver->setPwm(0, 0, 0);
116118
// disable the driver
@@ -125,6 +127,13 @@ void BLDCMotor::enable()
125127
driver->enable();
126128
// set zero to PWM
127129
driver->setPwm(0, 0, 0);
130+
// enable the current sense
131+
if(current_sense) current_sense->enable();
132+
// reset the pids
133+
PID_velocity.reset();
134+
P_angle.reset();
135+
PID_current_q.reset();
136+
PID_current_d.reset();
128137
// motor status update
129138
enabled = 1;
130139
}

src/common/base_classes/CurrentSense.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,12 @@ DQCurrent_s CurrentSense::getDQCurrents(ABCurrent_s current, float angle_el){
100100
void CurrentSense::linkDriver(BLDCDriver* _driver) {
101101
driver = _driver;
102102
}
103+
104+
105+
void enable(){
106+
// nothing is done here, but you can override this function
107+
};
108+
109+
void disable(){
110+
// nothing is done here, but you can override this function
111+
};

src/common/base_classes/CurrentSense.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,17 @@ class CurrentSense{
8787
*/
8888
DQCurrent_s getDQCurrents(ABCurrent_s current,float angle_el);
8989

90+
/**
91+
* enable the current sense. default implementation does nothing, but you can
92+
* override it to do something useful.
93+
*/
94+
virtual void enable();
9095

96+
/**
97+
* disable the current sense. default implementation does nothing, but you can
98+
* override it to do something useful.
99+
*/
100+
virtual void disable();
91101
};
92102

93103
#endif

0 commit comments

Comments
 (0)