Skip to content

Commit

Permalink
UMWC: ramp up voltage slowly
Browse files Browse the repository at this point in the history
Signed-off-by: Cornelius Claussen <cc@pionix.de>
  • Loading branch information
corneliusclaussen committed Oct 2, 2024
1 parent f19861c commit ada1702
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
36 changes: 32 additions & 4 deletions modules/MicroMegaWattBSP/dc_supply/power_supply_DCImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,38 @@ void power_supply_DCImpl::init() {
p.voltage_V = v;
mod->p_powermeter->publish_powermeter(p);
});

std::thread([this]() {
float low_pass_voltage = 0.;

while (true) {
std::this_thread::sleep_for(std::chrono::milliseconds(100));
// prevent overshoot
if (low_pass_voltage > req_voltage) {
// step down immediately
low_pass_voltage = req_voltage;
} else {
float delta = req_voltage - low_pass_voltage;
if (delta > 500) {
low_pass_voltage += 100;
} else {
if (delta > 50) {
low_pass_voltage += 25;
} else {
low_pass_voltage = req_voltage;
}
}
}

if (is_on) {
mod->serial.setOutputVoltageCurrent(low_pass_voltage, req_current);

} else {
mod->serial.setOutputVoltageCurrent(0, 0);
low_pass_voltage = 0.;
}
}
}).detach();
}

void power_supply_DCImpl::ready() {
Expand Down Expand Up @@ -57,10 +89,6 @@ void power_supply_DCImpl::handle_setMode(types::power_supply_DC::Mode& mode,
void power_supply_DCImpl::handle_setExportVoltageCurrent(double& voltage, double& current) {
req_voltage = voltage;
req_current = current;

if (is_on) {
mod->serial.setOutputVoltageCurrent(req_voltage, req_current);
}
};

void power_supply_DCImpl::handle_setImportVoltageCurrent(double& voltage, double& current){
Expand Down
5 changes: 3 additions & 2 deletions modules/MicroMegaWattBSP/dc_supply/power_supply_DCImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ class power_supply_DCImpl : public power_supply_DCImplBase {

// ev@3370e4dd-95f4-47a9-aaec-ea76f34a66c9:v1
// insert your private definitions here
float req_voltage{0}, req_current{0};
bool is_on{false};
std::atomic<float> req_voltage{0};
std::atomic<float> req_current{0};
std::atomic_bool is_on{false};
// ev@3370e4dd-95f4-47a9-aaec-ea76f34a66c9:v1
};

Expand Down

0 comments on commit ada1702

Please sign in to comment.