Giter Club home page Giter Club logo

smartesc_stm32_v1's Introduction

[ SmartESC ]

⚠️ Warning : this is work in progress. I decline all responsability about using informations from this project ⚠️

To contribute and help this project :

Donate

Logo

This project is desgiend to replace the firmware inside Xiaomi M365 controller.

It is based on the hoverboard firmware with commutation, sine and FOC algorithms. FOC is the most efficient algorithm and this is what we plan to use.

The Xiaomi controller is well designed and can already accept up 52V (2.1 & 3.0 rev) without modification. With some modifications, it can accept up to 80V. And heavy modifications, 100V.

The controller is based on STM32F103C6T8 micro-controller.

Xiaomi M365 Controller details :

  • The M365 controller exist to 3 versions and 1.4 & 2.1 have clone version more sheap some copy are very good, and some are bad the bad copy have poor mosfets, poor aluminum heatskin but the pcb is OK good copy exist only on 1.4 Rev have all good but probably not exist today
    • Rev 1.4 have 60v regulator (maximum absolute) can be use to 12S battery pack maximum safety
    • Rev 2.1 have 90v regulator (maximum absolute, 84V real) can be use to 19S battery pack maximum safety
    • Rev 3.0 is exactly the same with 2.1 but design is more stronger for current than 2.1 & 1.4
  • stock Voltage sending limited to 54v by divided bridge resistor, but 150v tolérant
  • stock Current reading to ~ +/- 100A per negative phase*
  • stock Capacitor is 1000uf 63v in stock can be change for 100V
  • NEWS we find voltage régulator 100v for remplace the 90v régulator on the board More détails here : https://docs.google.com/spreadsheets/d/1jOdUUpbCZVHQc2-eIezrbkNFHuf14I3zOeL0la91yoo/edit?usp=sharing

Requirements

  • Xiaomi controller
  • SmartDisplay or arduino
  • Motor with hall sensors
  • STLink (for flashing)
  • Power (battery or power supply)

Current status

  • Build hover boardfirmware
  • Flashing with STLInk
  • Modify pinout for Xiaomi controller
  • Spin the motor
    • in commutation mode
    • in sine mode
    • in FOC mode (speed, voltage & Torque)
  • Controller the motor with serial link (display / SmartController)
    • Create a new serial link with all data
    • Full-duplex
    • Half-duplex
  • Modes for speed limits
    • configurable speed limits
  • Control from the SmartDisplay
  • Process soft electric braking
    • configurable electric braking force
  • Link multiple controller
  • Optimize
  • Process wheel lock
  • Process soft throttle release
  • Communicate with BMS
    • Half-duplex
    • Full-duplex
  • Overvolage Protection to prevent a power supply or controller destruction (cut-off mosfets if value reached)

Controller schematics

Here

Here

Remote control from Arduino

Here is a test program : Here

With this, you can remote control the SmartESC with an ESP32 :

  • analog PIN 39 : analog throttle with hall sensor trigger (0.8V -> 4.1V)
  • analog PIN 34 : analog brake with hall sensor trigger (0.8V -> 4.1V)
  • IO PIN 27 : SERIAL_ESP_TO_CNTRL
  • IO PIN 14 : SERIAL_CNTRL_TO_ESP
  • Monitor serial : 921600 bauds
  • ESC serial : 115200 bauds

Remote control from Chrome

Use a FTDI adapter and launch the webconsole in Chrome : https://koxx3.fr.eu.org:8086/SmartESC_WebControl/

Flashing

Right to the STM32, there is a debugging header with GND, 3V3, SWDIO and SWCLK. Connect GND, SWDIO and SWCLK to your SWD programmer, like the ST-Link found on many STM devboards.

If you have never flashed your controller before, the MCU is probably locked. To unlock the flash, check-out the wiki page How to Unlock MCU flash.

Do not power the mainboard from the 3.3V of your programmer! This has already killed multiple mainboards.

Make sure you hold the powerbutton or connect a jumper to the power button pins while flashing the firmware, as the STM might release the power latch and switches itself off during flashing. Battery > 36V have to be connected while flashing.

To build and flash, you need to use STM32CubeIDE.



Original hoverboard-firmware-hack-FOC informations

License: GPL v3

This repository implements Field Oriented Control (FOC) for stock hoverboards. Compared to the commutation method, this new FOC control method offers superior performance featuring:

  • reduced noise and vibrations
  • smooth torque output and improved motor efficiency. Thus, lower energy consumption
  • field weakening to increase maximum speed range

Table of Contents

For the hoverboard sideboard firmware, see the following repositories:

For the FOC controller design, see the following repository:

Videos:


Hardware

mainboard_pinout

The original Hardware supports two 4-pin cables that originally were connected to the two sideboards. They break out GND, 12/15V and USART2&3 of the Hoverboard mainboard. Both USART2&3 support UART, PWM, PPM, and iBUS input. Additionally, the USART2 can be used as 12bit ADC, while USART3 can be used for I2C. Note that while USART3 (right sideboard cable) is 5V tolerant, USART2 (left sideboard cable) is not 5V tolerant.

Typically, the mainboard brain is an STM32F103RCT6, however some mainboards feature a GD32F103RCT6 which is also supported by this firmware.

For the reverse-engineered schematics of the mainboard, see 20150722_hoverboard_sch.pdf


FOC Firmware

In this firmware 3 control types are available:

  • Commutation
  • SIN (Sinusoidal)
  • FOC (Field Oriented Control) with the following 3 control modes:
    • VOLTAGE MODE: in this mode the controller applies a constant Voltage to the motors. Recommended for robotics applications or applications where a fast motor response is required.
    • SPEED MODE: in this mode a closed-loop controller realizes the input speed target by rejecting any of the disturbance (resistive load) applied to the motor. Recommended for robotics applications or constant speed applications.
    • TORQUE MODE: in this mode the input torque target is realized. This mode enables motor "freewheeling" when the torque target is 0. Recommended for most applications with a sitting human driver.

Comparison between different control methods

Control method Complexity Efficiency Smoothness Field Weakening Freewheeling Standstill hold
Commutation - - ++ n.a. n.a. +
Sinusoidal + ++ ++ +++ n.a. +
FOC VOLTAGE ++ +++ ++ ++ n.a. +(2)
FOC SPEED +++ +++ + ++ n.a. +++
FOC TORQUE +++ +++ +++ ++ +++(1) n.a(2)

(1) By enabling ELECTRIC_BRAKE_ENABLE in config.h, the freewheeling amount can be adjusted using the ELECTRIC_BRAKE_MAX parameter.

(2) The standstill hold functionality can be forced by enabling STANDSTILL_HOLD_ENABLE in config.h.

In all FOC control modes, the controller features maximum motor speed and maximum motor current protection. This brings great advantages to fulfil the needs of many robotic applications while maintaining safe operation.

Field Weakening / Phase Advance

  • By default the Field weakening is disabled. You can enable it in config.h file by setting the FIELD_WEAK_ENA = 1
  • The Field Weakening is a linear interpolation from 0 to FIELD_WEAK_MAX or PHASE_ADV_MAX (depeding if FOC or SIN is selected, respectively)
  • The Field Weakening starts engaging at FIELD_WEAK_LO and reaches the maximum value at FIELD_WEAK_HI
  • The figure below shows different possible calibrations for Field Weakening / Phase Advance Field Weakening
  • If you re-calibrate the Field Weakening please take all the safety measures! The motors can spin very fast!

Parameters

  • All the calibratable motor parameters can be found in the 'BLDC_controller_data.c'. I provided you with an already calibrated controller, but if you feel like fine tuning it feel free to do so
  • The parameters are represented in Fixed-point data type for a more efficient code execution
  • For calibrating the fixed-point parameters use the Fixed-Point Viewer tool
  • The controller parameters are given in this table

Troubleshooting

First, check that power is connected and voltage is >36V while flashing. If the board draws more than 100mA in idle, it's probably broken.

If the motors do something, but don't rotate smooth and quietly, try to use an alternative phase mapping. Usually, color-correct mapping (blue to blue, green to green, yellow to yellow) works fine. However, some hoverboards have a different layout then others, and this might be the reason your motor isn't spinning.

Nunchuk not working: Use the right one of the 2 types of nunchuks. Use i2c pullups.

Nunchuk or PPM working bad: The i2c bus and PPM signal are very sensitive to emv distortions of the motor controller. They get stronger the faster you are. Keep cables short, use shielded cable, use ferrits, stabilize voltage in nunchuk or reviever, add i2c pullups. To many errors leads to very high accelerations which triggers the protection board within the battery to shut everything down.

Recommendation: Nunchuk Breakout Board https://github.com/Jan--Henrik/hoverboard-breakout

Most robust way for input is to use the ADC and potis. It works well even on 1m unshielded cable. Solder ~100k Ohm resistors between ADC-inputs and gnd directly on the mainboard. Use potis as pullups to 3.3V.


Diagnostics

For a detailed troubleshooting connect an FTDI Serial adapter or a Bluetooth module to the DEBUG_SERIAL cable (Left or Right) and monitor the output data using the Hoverboard Web Serial Control tool developed by Candas.


smartesc_stm32_v1's People

Contributors

benjaf avatar candas1 avatar eferu avatar foujiwara avatar juodumas avatar koxx3 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.