moving up speed compensation for simulated speed

master
interfisch 2 years ago
parent 5463f1bb25
commit 41f7b207b9
  1. 11
      src/main.cpp

@ -94,6 +94,8 @@ struct blindmodel
float speedfactorLow=1; //how much position units (mm) per second at pwm=100. speedfactorLow for position at 0
float speedfactorHigh=1; //speedfactorHigh for position at 1000 mm. gets extrapolated above
float speedfactor_factor_updirection=1; //when moving up, how much to change the estimated position change (speed). when going slower in up direction, choose value below 1.0
int sense_clear_lower; //adc value lower limit for clear part. clear is around 70
int sense_clear_upper; //adc value upper limit for clear part
@ -210,8 +212,9 @@ void setup() {
blind1.sense_end_upper=1024;
blind1.speedfactorLow=28.7;
blind1.speedfactorHigh=25.3;
blind1.speedfactor_factor_updirection=0.97; //down: 2306mm in 94s ,up: 97s
blind1.start_first_clear=27;
blind1.simulated_acc_dec=-150;
blind1.simulated_acc_dec=-120;
blind1.simulated_acc_inc=200;
blind1.softlimit_min=0;
blind1.softlimit_max=2500;
@ -228,8 +231,9 @@ void setup() {
blind2.sense_end_upper=1024;
blind2.speedfactorLow=27.6;
blind2.speedfactorHigh=23.5;
blind2.speedfactor_factor_updirection=0.97;
blind2.start_first_clear=27;
blind2.simulated_acc_dec=-150;
blind2.simulated_acc_dec=-120;
blind2.simulated_acc_inc=200;
blind2.softlimit_min=0;
blind2.softlimit_max=2500;
@ -485,6 +489,9 @@ void errorCheck(blindmodel &blind, HomieNode &node) {
void estimatePosition(blindmodel &blind, HomieNode& node) {
float positional_speedfactor = blind.speedfactorLow + constrain(blind.position, blind.softlimit_min, blind.softlimit_max)*(blind.speedfactorHigh-blind.speedfactorLow)/POSITION_SPEEDMEASURE_HIGH; //interpolate/extrapolate speedfactor (speed is different when rolled up)
if (blind.speedSimulated<0) { //moving up
positional_speedfactor*=blind.speedfactor_factor_updirection; //used if speed for up direction is slower (likely when using dc motor)
}
if (millis() > blind.last_calculate_position_estimate + CALCULATEPOSITIONESTIMATE_INTERVAL) {
float _actualTime=(millis()-blind.last_calculate_position_estimate)/1000.0; //in seconds
blind.speedSimulated+= constrain(blind.speed - blind.speedSimulated, blind.simulated_acc_dec*_actualTime, blind.simulated_acc_inc*_actualTime);

Loading…
Cancel
Save