OpHaCo / hoverbot

Hack an Hoverboard to propel your fat robots!
72 stars 16 forks source link

OpenSource firmware for motor control on the STM32F103 #6

Open casainho opened 6 years ago

casainho commented 6 years ago

Hi, great project!!

I developed OpenSource firmware for motor control using the STM32F103, for electric unicycles. Currently I am developing for the cheap chinese ebike controllers, one based on STM8 and other with STM32F103.

Would be great if you or someone could develop firmware for the motor control for the hoverboards.

But my target is to make firmware for cheap ebike Kunteng STM8 controllers and make them a general bldc motor controller - it has UART communication and so with an Arduino, anyone could control easily this type of motors.

https://opensourceebikefirmware.bitbucket.io/

https://eggelectricunicycle.bitbucket.io/

LeoDJ commented 6 years ago

I would really like to delve into developing a BLDC controller on the hovervoard mainboard. But I do not know how to best get started and not brick and/or fry the motherboard. E.g. if I would activate the wrong outputs, the MOSFETs would short the battery and something will explode.

Also I'm not quite sure how I would then implement the BLDC controller using the hall effect sensor inputs.

I guess, that you have way more experience with those things, seeing that you already wrote such a firmware for the STM, only driving one motor.

Maybe we could work together on this? I am currently in the process of reverse engineering the mainboard (getting the pinout of the mosfets etc)

casainho commented 6 years ago

Hi.

Maybe we could work together on this? I am currently in the process of reverse engineering the mainboard (getting the pinout of the mosfets etc) I am not motivated to work on the hoverboard: I look to them as a toy because are instable after 10km/h; I would prefer electric unicycles that can go over 30km/h (yes, I did ride both of them). But now I even prefer electric bicycles because they are way safe than electric unicycles at speeds like 25km/h and over than that. I usually ride at up to 45km/h, on flat land were I live. My motivation is to develop knowledge and tecnhology "to accelerate the advent of sustainable transport" and innovation on personal light electric vehicles.

My focus is to develop OpenSource firmware for the cheap and widely available EBike motor controllers. The one I am developing for now, costs only 14€!! It has UART interface for an LCD or bluetooth modules. My plan is to create a generic motor controller that can be commanded by Arduino, using the UART interface, then anyone will be able to use this motor controllers and do other devices like hoverboards, electric unicycles, etc!!

I have an idea for you: use the Lishui LSW-675 EBike motor controller that is relative cheap and uses the same STM32FEBKC6T6 as on the hoverboard -- you can find the datasheet of STM32FEBKC6T6 here as many other information: https://opensourceebikefirmware.bitbucket.io/Motor_controllers--Lishui_motor_controllers--LSW-675.html

Good luck and don't forget to start a thread on https://endless-sphere.com/forums/viewforum.php?f=30 to document and post news about this project!!

LeoDJ commented 6 years ago

Okay. On terms of hoverboard riding, we are on the same page. I don't want to use it in its original form, but repurpose the motors, main board and battery as a drive chain for a few robot ideas I have in mind, because they are still very powerful.
I think I found the official firmware for the hoverboard mainboard, so it hopefully shouldn't be so hard to reprogram it to accept direct control commands over UART.

Thanks for the tip with the LSW-675. It's too expensive for me to use as an ESC for the two motors, but I'll look into the firmware for inspiration.

As for the 14€ open source motor controller: That sounds really neat, I'll look forward to using that in the future 😉

casainho commented 6 years ago

As for the 14€ open source motor controller: That sounds really neat, I'll look forward to using that in the future 😉

Don't you want to join the project?? we can implement the firmware for a generic motor controller that is controlled using UART commands send by Arduino.

-- Cumprimentos, Jorge Pinto E-mail: casainho@gmail.com Telemóvel: 927145983

LeoDJ commented 6 years ago

Yeah, good idea.
Currently I'm a little bit busy with uni, but I'll see when I got time :D What do you think is the best way we can communicate?

casainho commented 6 years ago

We use the forum, see on the project page the link.

Em 28/09/2017 16:39, "Leandro Späth" notifications@github.com escreveu:

Yeah, good idea. Currently I'm a little bit busy with uni, but I'll see when I got time :D What do you think is the best way we can communicate?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/OpHaCo/hoverbot/issues/6#issuecomment-332876454, or mute the thread https://github.com/notifications/unsubscribe-auth/AAI-uBqXu5JfIui70DQUD3NKMUNn5Rr_ks5sm72UgaJpZM4OsxW4 .

chulo601 commented 6 years ago

LeoDJ i have over 50+ hoverboard i can give for free just pay for shipping so you can test the reprogramming of the hoverboard. I will like to use the hoverboard main board and be able to control both wheels with arduino. 20170916_024648

LeoDJ commented 6 years ago

Wow, that sounds awesome! It would be neat to have one or two that I can test my code on, without the fear that I would be bricking one beyond repair ^^ How much would shipping to Germany cost?

VladimirAkopyan commented 6 years ago

this is very amusing

ScottEllisNovatex commented 6 years ago

See https://github.com/NiklasFauth/hoverboard-firmware-hack

vetalik08 commented 6 years ago

Have any more hover boards your willing tk donate if I paid for shipping?

eric-schleicher commented 6 years ago

@chulo601 is this still an area of interest for you? I have a number of interns that are interested making a balance bot from these component. let me know if there is still a supply of yunked parts. we're in US, would certainly pay for shipping.

casainho commented 6 years ago

I implemented FOC using as input: battery voltage; actual duty_cycle; battery current read on shunt; motor speed in ERPs measured on hall sensors; motor inductance.

Videos and realtime graphs, etc:

The only parameter that depends from the motor is the motor inductance L. The math is: angle = arc sin (I motor phase W L / V motor phase). I motor phase: battery current read on shunt / duty_cycle V motor phase: battery voltage * duty_cycle

The piece of code: //**** // FOC implementation by calculating the angle between phase current and rotor magnetic flux (BEMF) // 1. phase voltage is calculate // 2. IwL is calculated, where I is the phase current. L was a measured value for 48V motor. // 3. inverse sin is calculated of (IwL) / phase voltage, were we obtain the angle // 4. previous calculated angle is applied to phase voltage vector angle and so the // angle between phase current and rotor magnetic flux (BEMF) is kept at 0 (max torque per amp)

// calc E phase voltage ui16_temp = ui16_adc_battery_voltage_filtered ADC10BITS_BATTERY_VOLTAGE_PER_ADC_STEP_X512; ui16_temp = (ui16_temp >> 8) ui8_duty_cycle; ui16_e_phase_voltage = ui16_temp >> 9;

// calc I phase current if (ui8_duty_cycle > 10) { ui16_temp = ui16_adc_battery_current_filtered * ADC_BATTERY_CURRENT_PER_ADC_STEP_X512; ui32_i_phase_current_x2 = ui16_temp / ui8_duty_cycle; } else { ui32_i_phase_current_x2 = 0; }

// calc W angular velocity: erps 6.3 ui32_w_angular_velocity_x16 = ui16_motor_speed_erps 101;

// 36V motor: L = 76uH // 48V motor: L = 135uH ui32_l_x1048576 = 142; // 1048576 = 2^20

// calc IwL ui32_temp = ui32_i_phase_current_x2 ui32_l_x1048576; ui32_temp = ui32_w_angular_velocity_x16; ui16_iwl_128 = ui32_temp >> 18;

// calc FOC angle ui8_foc_angle = asin_table (ui16_iwl_128 / ui16_e_phase_voltage);

// low pass filter FOC angle ui16_foc_angle_accumulated -= ui16_foc_angle_accumulated >> 4; ui16_foc_angle_accumulated += ui8_foc_angle; ui8_foc_angle_filtered = ui16_foc_angle_accumulated >> 4;

// apply FOC angle ui8_foc_angle_correction = -ui8_foc_angle_filtered; //****