Skip to content
This repository has been archived by the owner on Oct 8, 2018. It is now read-only.

Walk assist mode #7

Open
casainho opened this issue Aug 9, 2018 · 11 comments
Open

Walk assist mode #7

casainho opened this issue Aug 9, 2018 · 11 comments
Labels
enhancement New feature or request

Comments

@casainho
Copy link
Contributor

casainho commented Aug 9, 2018

No description provided.

@casainho casainho added the enhancement New feature or request label Aug 9, 2018
@casainho
Copy link
Contributor Author

Not on/off because it is dangerous.
User must keep the button pressed but small releases of button should be ignored (low pass filter??) as that happens frequently when we are pushing the ebike.

@ncvanleeuwen
Copy link
Contributor

ncvanleeuwen commented Sep 11, 2018

I'm experimenting with this, it almost works already and it's quite easy to implement. But, how can I get the motor to run slow enough? It still feels too fast for my liking. @casainho do you have some good ideas?

@casainho
Copy link
Contributor Author

How are you implementing it??

I would try to use a PI controller as I did on KT motor controller Firmware -- see ebike_app.c file on that project:

// PI controller for wheel speed
wheel_speed_pi_controller_state.ui8_current_value = ui8_ebike_app_get_wheel_speed ();
wheel_speed_pi_controller_state.ui8_target_value = ui8_temp;
pi_controller (&wheel_speed_pi_controller_state);
ui8_target_duty_cycle = wheel_speed_pi_controller_state.ui8_controller_output_value;

@ncvanleeuwen
Copy link
Contributor

ncvanleeuwen commented Sep 11, 2018

Thanks! I experimented using the wheel speed but is it just me or is the wheel speed unreliable at these low speeds (6 km/h)? Will try the PI controller.

@ncvanleeuwen
Copy link
Contributor

ncvanleeuwen commented Sep 11, 2018

Motor won't run using the code below. Also the case when I bypass the PI controller and just set a fixed duty cycle. Am I missing some kind of enable flag or state? What does the motor controller need exactly besides max_current and duty_cycle?

// walk assist
  if (configuration_variables.ui8_walk_assist == 1)
  {
    walk_assist_wheel_speed_pi_controller_state.ui8_current_value = (uint8_t) ui16_wheel_speed_x10;
    walk_assist_wheel_speed_pi_controller_state.ui8_target_value = 6 * 10;
    pi_controller (&walk_assist_wheel_speed_pi_controller_state);

    ebike_app_set_target_adc_battery_max_current (ui8_adc_battery_current_max);

    if (!brake_is_set ())
    {
      //motor_set_pwm_duty_cycle_target (PWM_DUTY_CYCLE_MIN); //fixed duty cycle
      motor_set_pwm_duty_cycle_target (walk_assist_wheel_speed_pi_controller_state.ui8_controller_output_value);
    }
    else
    {
      motor_set_pwm_duty_cycle_target (0);
      pi_controller_reset (&walk_assist_wheel_speed_pi_controller_state);
    }
  }
  else
  {
     // the rest of ebike_control_motor ()
  }

I've initialized the PI controller using the default parameters of main.h

@casainho
Copy link
Contributor Author

I think you need to use the PI controller output value!! The output should be the current value to after setup on ebike_app_set_target_adc_battery_max_current ().

The idea is that you have as input the speed variable and the output the current value.

See that you need to setup correctly the P and I coefficients.

@ncvanleeuwen
Copy link
Contributor

Thanks! I've experimented again tonight. I've tried your suggestion (using the current controller) before but decided to retry it tonight. Same issue unfortunately: the minimum current for ebike_app_set_target_adc_battery_max_current () is 1 right? With this value the motor and wheel is spinning way too fast. That's why I was experimenting with the duty cycle...

Regarding the PI controller, isn't the update rate of 10Hz too slow? I'm calling the PI controller from the ebike_app which is called every 100 ms if I'm correct. Maybe we should move it to the motor controller (called every 4ms)? I also have my doubts about the implementation of the PI controller, there is no delta time factor and the resolution is quite low?

Btw, I have a simple low pass filter (debounce) for walk assist implemented in the display, this allows a short interruption of the button down event.

@ncvanleeuwen
Copy link
Contributor

@casainho can you clarify on ebike_app_set_target_adc_battery_max_current () and how we can get a better resolution?

@casainho
Copy link
Contributor Author

// each 1 unit = 0.625 amps
void ebike_app_set_target_adc_battery_max_current (uint8_t ui8_value)

Better resolution would be to use ui8_adc_battery_current but with a 10 bits ADC resolution (see motor.c):
ui16_adc_battery_current_10b = ui16_adc_read_battery_current_10b ();
ui8_adc_battery_current = ui16_adc_battery_current_10b >> 2;

I decided to use 8 bits because the STM8 is 8 bits and also when we loose resolution from 10 bits to 8 bits, we are low pass filtering, which I think is important because the raw 10 bits signal should be noisy.

Maybe, the best option here is for you to control directly the target duty_cycle with motor_set_pwm_duty_cycle_target (255);. I would keep the code just the same but reduce target duty_cycle from 255, when I want a lower speed....

@hurzhurz
Copy link

If that matters, I think the 6kmh walk assist of the original TSDZ2 firmware doesn't really care about the actual speed.
I tested this a while ago by faking different speeds via generated pulses at the speed sensor input. This didn't influence the motor rpm at all.

So, maybe it would be an idea to implement it simply by a constant (maximum) motor rpm together with a very limited maximum power?

@casainho
Copy link
Contributor Author

casainho commented Sep 26, 2018

At 6km/h, my 26 inchs wheel takes 1.24 seconds to make one rotation, which I think is slow as input variable to control.

I think we can increase motor current/pwm duty-cycle and when wheel speed is equal or over 6km/h, we can store the motor speed value that equals to wheel speed of 6km/h (like 10km/h motor rotating at 100 erps, so (6 * 10) /100 = 60 erps, we would control the motor erps to be 60.

And in fact, we already control motor max erps to be 525, so maybe we could change the motor max speed erps value to the lower value we need for walk assist and them the speed controller is already done??

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants