Skip to content

Add currentsense.enable/disable #365

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 CurrentSense::enable(){
// nothing is done here, but you can override this function
};

void CurrentSense::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
12 changes: 8 additions & 4 deletions src/drivers/hardware_specific/atmega/atmega2560_mcu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ void* _configure1PWM(long pwm_frequency,const int pinA) {
_pinHighFrequency(pinA, pwm_frequency);
GenericDriverParams* params = new GenericDriverParams {
.pins = { pinA },
.pwm_frequency = pwm_frequency
.pwm_frequency = pwm_frequency,
.dead_zone = 0.0f
};
return params;
}
Expand All @@ -75,7 +76,8 @@ void* _configure2PWM(long pwm_frequency,const int pinA, const int pinB) {
_pinHighFrequency(pinB, pwm_frequency);
GenericDriverParams* params = new GenericDriverParams {
.pins = { pinA, pinB },
.pwm_frequency = pwm_frequency
.pwm_frequency = pwm_frequency,
.dead_zone = 0.0f
};
return params;
}
Expand All @@ -94,7 +96,8 @@ void* _configure3PWM(long pwm_frequency,const int pinA, const int pinB, const in
_pinHighFrequency(pinC, pwm_frequency);
GenericDriverParams* params = new GenericDriverParams {
.pins = { pinA, pinB, pinC },
.pwm_frequency = pwm_frequency
.pwm_frequency = pwm_frequency,
.dead_zone = 0.0f
};
// _syncAllTimers();
return params;
Expand Down Expand Up @@ -141,7 +144,8 @@ void* _configure4PWM(long pwm_frequency,const int pin1A, const int pin1B, const
_pinHighFrequency(pin2B,pwm_frequency);
GenericDriverParams* params = new GenericDriverParams {
.pins = { pin1A, pin1B, pin2A, pin2B },
.pwm_frequency = pwm_frequency
.pwm_frequency = pwm_frequency,
.dead_zone = 0.0f
};
return params;
}
Expand Down
12 changes: 8 additions & 4 deletions src/drivers/hardware_specific/atmega/atmega328_mcu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ void* _configure1PWM(long pwm_frequency,const int pinA) {
_pinHighFrequency(pinA, pwm_frequency);
GenericDriverParams* params = new GenericDriverParams {
.pins = { pinA },
.pwm_frequency = pwm_frequency
.pwm_frequency = pwm_frequency,
.dead_zone = 0.0f
};
return params;
}
Expand All @@ -70,7 +71,8 @@ void* _configure2PWM(long pwm_frequency,const int pinA, const int pinB) {
_pinHighFrequency(pinB, pwm_frequency);
GenericDriverParams* params = new GenericDriverParams {
.pins = { pinA, pinB },
.pwm_frequency = pwm_frequency
.pwm_frequency = pwm_frequency,
.dead_zone = 0.0f
};
return params;
}
Expand All @@ -89,7 +91,8 @@ void* _configure3PWM(long pwm_frequency,const int pinA, const int pinB, const in
_pinHighFrequency(pinC, pwm_frequency);
GenericDriverParams* params = new GenericDriverParams {
.pins = { pinA, pinB, pinC },
.pwm_frequency = pwm_frequency
.pwm_frequency = pwm_frequency,
.dead_zone = 0.0f
};
_syncAllTimers();
return params;
Expand Down Expand Up @@ -141,7 +144,8 @@ void* _configure4PWM(long pwm_frequency,const int pin1A, const int pin1B, const
_pinHighFrequency(pin2B,pwm_frequency);
GenericDriverParams* params = new GenericDriverParams {
.pins = { pin1A, pin1B, pin2A, pin2B },
.pwm_frequency = pwm_frequency
.pwm_frequency = pwm_frequency,
.dead_zone = 0.0f
};
return params;
}
Expand Down
12 changes: 8 additions & 4 deletions src/drivers/hardware_specific/atmega/atmega32u4_mcu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ void* _configure1PWM(long pwm_frequency,const int pinA) {
_pinHighFrequency(pinA);
GenericDriverParams* params = new GenericDriverParams {
.pins = { pinA },
.pwm_frequency = pwm_frequency
.pwm_frequency = pwm_frequency,
.dead_zone = 0.0f
};
return params;
}
Expand All @@ -56,7 +57,8 @@ void* _configure2PWM(long pwm_frequency,const int pinA, const int pinB) {
_pinHighFrequency(pinB);
GenericDriverParams* params = new GenericDriverParams {
.pins = { pinA, pinB },
.pwm_frequency = pwm_frequency
.pwm_frequency = pwm_frequency,
.dead_zone = 0.0f
};
return params;
}
Expand All @@ -72,7 +74,8 @@ void* _configure3PWM(long pwm_frequency,const int pinA, const int pinB, const in
_pinHighFrequency(pinC);
GenericDriverParams* params = new GenericDriverParams {
.pins = { pinA, pinB, pinC },
.pwm_frequency = pwm_frequency
.pwm_frequency = pwm_frequency,
.dead_zone = 0.0f
};
return params;
}
Expand Down Expand Up @@ -119,7 +122,8 @@ void* _configure4PWM(long pwm_frequency,const int pin1A, const int pin1B, const
_pinHighFrequency(pin2B);
GenericDriverParams* params = new GenericDriverParams {
.pins = { pin1A, pin1B, pin2A, pin2B },
.pwm_frequency = pwm_frequency
.pwm_frequency = pwm_frequency,
.dead_zone = 0.0f
};
return params;
}
Expand Down