KT motor controllers -- Flexible OpenSource firmware for BMSBattery S/Kunteng KT motor controllers (0.25kW up to 5kW)

stancecoke said:
casainho said:
Copy-past would make the firmware a mess.
Copy-Paste of the improved direction detection for PAS took me just one or two hours of work. But of course you are right, most of the time I had to spend to understand how you solved things in your code. If you don't like a "quick-and-dirty"-solution, you can take the principle from the other fork and have to implement it yourself. I think you are the only one in the world, who understands the whole firmware structure :shock: I lost track of things one day :-(.
I suggest you to make a branch or fork so you can add it and we can discuss here the structure and where it makes morr sense to add the code.
 
LCD3: I implemented the configuration of wheel max speed, wheel size and units of Km/h or MPh (for TSDZ2 motor).
Let's see if anyone is interested to implement the version for our firmware for KT motor controllers. The structure of the configuration menus is there and working so should be simple to expand to add custom configuration menus:

[youtube]pQBaFCXBn1g[/youtube]
 
casainho said:
I suggest you to make a branch or fork so you can add it and we can discuss here the structure and where it makes morr sense to add the code.
Hm, I just had a short look at the recent code. The speed limit is already enabled/disabled by the display via parameter P3. The speed control is not just a cut off at the speed limit, but a speed control according to the throttle position (or PAS state).

edit: ah, now I found the cut off code :), but I can't find any call of the function set_speed_erps_max_to_motor_controller?!
And the definition of the default values :)

I think the wanted function is an enabled speed limit by default, when switching on the system, for legality issues, and a hidden function to disable the limit until the system is switched off again.

Is that right?

I've added a first try to a new branch at github, it's not tested in hardware yet.
The speed limit is disabled by sending the "code" by the brake lever as described in the tab "alternative fork" of the windows tutorial. The cheat step duration is defined in the main.h to one second each at the moment, to avoid the need of updating the java tool. The slow loop runs at 10Hz at casainhos master, in my fork it runs at 50Hz.

The cheat works like this: Hold the brake lever for cheat time 1, then release it for the duration of cheat time 2, then pull it again for cheat time 3, then release it again. For step 1 with a value of 10, the release of the brake lever is recognized as valid for a period of 1 to 1.5 seconds after pulling and continues with step 2. If the lever is released too early or too late, the whole procedure is reset and you have to start all over again. Currently the user does not get any feedback on whether the cheat has been activated.

regards
stancecoke
 
I really don't like the wording "cheat" as it depreciates the project. Look at this reality: I have an ebike, in this case BTT bike with a powerful mid drive motor of 800W and that can achive 45km/h - I will drive 10km on road until I arrive at montains were I will do a sport ride with other friends. In the end I will be back to home again that 10km on the road -- so, current tecnhology is very flexible and is desirable to be like that, the same ebike we can be used offroad without speed, power and throttle usage imposed limits while just after when commuting on the road, it must need to be limited. That is not a cheat but instead, flexibility.
 
:D you can call it whatever you want :D

Please, can you confirm: The function for cutting the power at the speed limit is prepared in the code but it's not used actually?!

Code:
volatile uint16_t ui16_target_erps_max = MOTOR_OVER_SPEED_ERPS;

...

void motor_controller_set_speed_erps_max (uint16_t ui16_erps)
{
  ui16_target_erps_max = ui16_erps;
}


regards
stancecoke
 
stancecoke said:
:D you can call it whatever you want :D

Please, can you confirm: The function for cutting the power at the speed limit is prepared in the code but it's not used actually?!

Code:
volatile uint16_t ui16_target_erps_max = MOTOR_OVER_SPEED_ERPS;

...

void motor_controller_set_speed_erps_max (uint16_t ui16_erps)
{
  ui16_target_erps_max = ui16_erps;
}
I am remaming the variables and simplifing a bit the code. Should commit today.

Yes, I think it is not used right now.

Without PI controller, it can be implemented on fast loop. I just did that for TSDZ2 and found issues on the code that I can correct for KT. But the cut in speed is kind of fast, may be ok for max erps but not for user speed limit. Anyway, we can start like that for now.

Street mode should impose a 25km/h limit or the limit value that is configured by user on the LCD?
 
casainho said:
But the cut in speed is kind of fast, may be ok for max erps but not for user speed limit. Anyway, we can start like that for now.
Yes, I think we should ramp down the power slowly within a range of 2 km/h. It's solved that way in the "Forumscontroller" and in my fork. But it has to be placed in the slow loop, I think.


Code:
uint32_t CheckSpeed (uint16_t current_target, uint16_t speed)
{

  //ramp down motor power if you are riding too fast and speed liming is active
  if (speed>limit*1000 && ui8_cheat_state!=4){
      //printf("Vor %d, %d\r\n", current_target-ui16_current_cal_b, speed);
	if (speed>(limit+2)*1000){ //if you are riding much too fast, stop motor immediately
	    current_target=ui16_current_cal_b;
	   //printf("Speed much too high! %d, %d\r\n", current_target, speed);
	}
	else {

	    ui32_temp=((current_target-ui16_current_cal_b));
	    //printf("Substraktion %d, %lu\r\n", current_target, ui32_temp) ;
	    ui32_temp *=((limit+2)*1000-speed);
	    //printf("Mal %d, %lu\r\n", current_target, ui32_temp) ;
	    current_target=(uint16_t)(ui32_temp/2000+ui16_current_cal_b); 	//ramp down the motor power within 2 km/h, if you are riding too fast
	    //printf("Speed too high!\r\n");
	    //printf("Nach %d, %lu\r\n", current_target, ui32_temp) ;
	}
  }
    return ((uint32_t)current_target);
  }


casainho said:
Street mode should impose a 25km/h limit or the limit value that is configured by user on the LCD?

We should use the value that's defined by the user on the LCD. I think in US the legal limit is 20mph (32km/h).

regards
stancecoke
 
Offroad mode code is on this branch: https://github.com/OpenSource-EBike-firmware/BMSBattery_S_controllers_firmware/tree/feature/offroad_mode

The code is untested as now I don't have have ready hardware to test it.

offroad_mode (); is now called inside ebike_app ();
The output is the ui8_offroad_mode = 1 if offroad mode is enable, otherwise will be zero.

stancecoke said:
casainho said:
But the cut in speed is kind of fast, may be ok for max erps but not for user speed limit. Anyway, we can start like that for now.
Yes, I think we should ramp down the power slowly within a range of 2 km/h. It's solved that way in the "Forumscontroller" and in my fork. But it has to be placed in the slow loop, I think.
Maybe you can reuse map function.
Inputs: delta speed (max speed - 2)
Range input: 0 to 2
Range output: 0 to max battery current
Output: ui8_adc_target_battery_current_max
 
casainho said:
The code is untested as now I don't have have ready hardware to test it.

Hm, I don't understand your code, I think it can't work. The if condition will never get true, so the switch structure will never be called....

Code:
if (ui8_offroad_state == 3)

Another bug in my code: the 25 has to be 5. The 25 represents half a second at 50 Hz. At 10Hz it has to be 5. I had changed the 25 to 5 only at state 3...

regards
stancecoke
 
stancecoke said:
Code:
#define ADC_MOTOR_CURRENT_MAX	43 // each unit = 0.35A; 43 = 15A

regards
stancecoke
After attempts to configure PWM_DUTY_CYCLE_AMP
the controller burned out. The wheel began to spin and stop very choppy. I did not press Throttle!
 
stancecoke said:
casainho said:
The code is untested as now I don't have have ready hardware to test it.

Hm, I don't understand your code, I think it can't work. The if condition will never get true, so the switch structure will never be called....

Code:
if (ui8_offroad_state == 3)

Another bug in my code: the 25 has to be 5. The 25 represents half a second at 50 Hz. At 10Hz it has to be 5. I had changed the 25 to 5 only at state 3...
You are right. I just changed that, please review now.
 
Basia said:
stancecoke said:
Code:
#define ADC_MOTOR_CURRENT_MAX	43 // each unit = 0.35A; 43 = 15A

regards
stancecoke
Фfter attempts to configure PWM_DUTY_CYCLE_AMP
the controller burned out. The wheel began to spin and stop very choppy. I did not press Throttle!
I was to say that small motor using 1.5 amps at max speed, seems a bit high to me. I would say something more like 0.5 amps.

Sorry to know that controller did burn. At least this controllers relatively cheap to replace.
I always use a car fuse of 10 amps to try protect from that situation.
 
casainho said:
Basia said:
stancecoke said:
Code:
#define ADC_MOTOR_CURRENT_MAX	43 // each unit = 0.35A; 43 = 15A

regards
stancecoke
Фfter attempts to configure PWM_DUTY_CYCLE_AMP
the controller burned out. The wheel began to spin and stop very choppy. I did not press Throttle!
I was to say that small motor using 1.5 amps at max speed, seems a bit high to me. I would say something more like 0.5 amps.

Sorry to know that controller did burn. At least this controllers relatively cheap to replace.
I always use a car fuse of 10 amps to try protect from that situation.

I ordered a new controller ;). How to set up PWM_DUTY_CYCLE_AMP correctly? My battery is 48V.
 
Basia said:
I ordered a new controller ;). How to set up PWM_DUTY_CYCLE_AMP correctly? My battery is 48V.
PWM_DUTY_CYCLE_AMP ??
And buy and use a fuse in series with the battery positive/red wire, of 10 amps or even less.
 
casainho said:
Basia said:
I ordered a new controller ;). How to set up PWM_DUTY_CYCLE_AMP correctly? My battery is 48V.
PWM_DUTY_CYCLE_AMP ??
And buy and use a fuse in series with the battery positive/red wire, of 10 amps or even less.

Sorry )
config.h
#define PWM_DUTY_CYCLE_RAMP_UP_INVERSE_STEP 35
#define PWM_DUTY_CYCLE_RAMP_DOWN_INVERSE_STEP 35
 
casainho said:
You are right. I just changed that, please review now.

Hm, with OFFROAD_STATE_END 4, you will disable the routine with the first time you are using the brake lever. You have to reset the state to zero, if you are just using the break lever for breaking, or if you failed to find the right rythm of the morse-code.

OFFROAD_STATE_END 0 should work. I can try it in hardware during the weekend...

regards
stancecoke
 
Basia said:
casainho said:
Basia said:
I ordered a new controller ;). How to set up PWM_DUTY_CYCLE_AMP correctly? My battery is 48V.
PWM_DUTY_CYCLE_AMP ??
And buy and use a fuse in series with the battery positive/red wire, of 10 amps or even less.

Sorry )
config.h
#define PWM_DUTY_CYCLE_RAMP_UP_INVERSE_STEP 35
#define PWM_DUTY_CYCLE_RAMP_DOWN_INVERSE_STEP 35

I do not understand how this works. Is it possible to disable PWM? Is it possible to disconnect all PAS sensors from the settings? I have only a throttle.
 
stancecoke said:
casainho said:
You are right. I just changed that, please review now.

Hm, with OFFROAD_STATE_END 4, you will disable the routine with the first time you are using the brake lever. You have to reset the state to zero, if you are just using the break lever for breaking, or if you failed to find the right rythm of the morse-code.

OFFROAD_STATE_END 0 should work. I can try it in hardware during the weekend...
I see. I implemented thinking that user can do it only once when system boots up.

Also added option to config.h so user can enable always offroad mode.
 
Basia said:
Basia said:
casainho said:
Basia said:
I ordered a new controller ;). How to set up PWM_DUTY_CYCLE_AMP correctly? My battery is 48V.
PWM_DUTY_CYCLE_AMP ??
And buy and use a fuse in series with the battery positive/red wire, of 10 amps or even less.

Sorry )
config.h
#define PWM_DUTY_CYCLE_RAMP_UP_INVERSE_STEP 35
#define PWM_DUTY_CYCLE_RAMP_DOWN_INVERSE_STEP 35

I do not understand how this works. Is it possible to disable PWM? Is it possible to disconnect all PAS sensors from the settings? I have only a throttle.
PAS settings must be there but you can ignore the values/PAS options.

Should be this for a throttle:
// choose between throttle and/or pas or torque sensor
#define EBIKE_THROTTLE_TYPE EBIKE_THROTTLE_TYPE_THROTTLE_PAS
//#define EBIKE_THROTTLE_TYPE EBIKE_THROTTLE_TYPE_TORQUE_SENSOR

// next, choose one of the both (only apply to throttle and/or PAS)
//#define EBIKE_THROTTLE_TYPE_THROTTLE_PAS_PWM_DUTY_CYCLE // direct PWM duty_cycle control
#define EBIKE_THROTTLE_TYPE_THROTTLE_PAS_CURRENT_SPEED // control using motor current/torque and/or wheel speed

Don't change this, a smaller value of 35 can help burn the power mosfets of the controller. But you can try increase the value to get a slower response and even have the mosfets with lower phase currents, so will be better for them.

#define PWM_DUTY_CYCLE_RAMP_UP_INVERSE_STEP 35
#define PWM_DUTY_CYCLE_RAMP_DOWN_INVERSE_STEP 35
 
casainho said:
Basia said:
Basia said:
casainho said:
PWM_DUTY_CYCLE_AMP ??
And buy and use a fuse in series with the battery positive/red wire, of 10 amps or even less.

Sorry )
config.h
#define PWM_DUTY_CYCLE_RAMP_UP_INVERSE_STEP 35
#define PWM_DUTY_CYCLE_RAMP_DOWN_INVERSE_STEP 35

I do not understand how this works. Is it possible to disable PWM? Is it possible to disconnect all PAS sensors from the settings? I have only a throttle.
PAS settings must be there but you can ignore the values/PAS options.

Should be this for a throttle:
// choose between throttle and/or pas or torque sensor
#define EBIKE_THROTTLE_TYPE EBIKE_THROTTLE_TYPE_THROTTLE_PAS
//#define EBIKE_THROTTLE_TYPE EBIKE_THROTTLE_TYPE_TORQUE_SENSOR

// next, choose one of the both (only apply to throttle and/or PAS)
//#define EBIKE_THROTTLE_TYPE_THROTTLE_PAS_PWM_DUTY_CYCLE // direct PWM duty_cycle control
#define EBIKE_THROTTLE_TYPE_THROTTLE_PAS_CURRENT_SPEED // control using motor current/torque and/or wheel speed

Don't change this, a smaller value of 35 can help burn the power mosfets of the controller. But you can try increase the value to get a slower response and even have the mosfets with lower phase currents, so will be better for them.

#define PWM_DUTY_CYCLE_RAMP_UP_INVERSE_STEP 35
#define PWM_DUTY_CYCLE_RAMP_DOWN_INVERSE_STEP 35

Please see my config.
 

Attachments

  • config.h
    1.4 KB · Views: 53
casainho said:
I see. I implemented thinking that user can do it only once when system boots up.

Hmm, still you have no chance for a second try or to put in the code after first braking. You have to switch off/on the system each time, for a new try :-(
Why do you use all the constants?! The simple numbering was much easier to follow....

regards
stancecoke
 
stancecoke said:
Hmm, still you have no chance for a second try or to put in the code after first braking. You have to switch off/on the system each time, for a new try :-(
Why do you use all the constants?! The simple numbering was much easier to follow....
I think should be very easy to enter on the offroad mode by mistake. I changed to: once throttle or PAS are active for the first time, don't check anymore for offroad mode.

Constants because the numbering is fast to change when I need to change that number on all the code, which I had a few times. Also with a good name should make more clear what that state means.
 
Hm, that's not my prefered solution, as you have to stop, swtich off, switch on try to morse, fail, switch off, switch on, try again..... It is quite difficult to find the right rythm and I see no danger to activate the offroad-mode randomly...

But no problem, it's easy for me to modify it in the way I like :)

regards
stancecoke
 
stancecoke said:
Hm, that's not my prefered solution, as you have to stop, swtich off, switch on try to morse, fail, switch off, switch on, try again..... It is quite difficult to find the right rythm and I see no danger to activate the offroad-mode randomly...
I see, the issue is that we don't have an indication for user that offroad mode was activated. If we had, would then be ok for you? If so, how it would be? Maybe motor accelerating to max power full speed? :)
 
Hm, I would prefer to activate the offroad mode while riding, without the need of switching off/on the system.
As feedback for the user, we could set the speed-display to 99km/h for three seconds e.g.

regards
stancecoke
 
Back
Top