Skip to content

Commit

Permalink
add currentsense.enable/disable
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Unger committed Jan 7, 2024
1 parent b7300fe commit 4934aae
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/BLDCMotor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ void BLDCMotor::init() {
// disable motor driver
void BLDCMotor::disable()
{
// disable the current sense
if(current_sense) current_sense->disable();
// set zero to PWM
driver->setPwm(0, 0, 0);
// disable the driver
Expand All @@ -125,6 +127,13 @@ void BLDCMotor::enable()
driver->enable();
// set zero to PWM
driver->setPwm(0, 0, 0);
// enable the current sense
if(current_sense) current_sense->enable();
// reset the pids
PID_velocity.reset();
P_angle.reset();
PID_current_q.reset();
PID_current_d.reset();
// motor status update
enabled = 1;
}
Expand Down
9 changes: 9 additions & 0 deletions src/common/base_classes/CurrentSense.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,12 @@ DQCurrent_s CurrentSense::getDQCurrents(ABCurrent_s current, float angle_el){
void CurrentSense::linkDriver(BLDCDriver* _driver) {
driver = _driver;
}


void enable(){
// nothing is done here, but you can override this function
};

void disable(){
// nothing is done here, but you can override this function
};
10 changes: 10 additions & 0 deletions src/common/base_classes/CurrentSense.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,17 @@ class CurrentSense{
*/
DQCurrent_s getDQCurrents(ABCurrent_s current,float angle_el);

/**
* enable the current sense. default implementation does nothing, but you can
* override it to do something useful.
*/
virtual void enable();

/**
* disable the current sense. default implementation does nothing, but you can
* override it to do something useful.
*/
virtual void disable();
};

#endif

0 comments on commit 4934aae

Please sign in to comment.