Suggestions for OpenSource Electric Unicycle firmware

Support for creating custom user applications on the VESC.
rew
Posts: 905
Joined: 25 Mar 2016, 12:29
Location: Delft, Netherlands.

Re: Suggestions for OpenSource Electric Unicycle firmware

Postby rew » 01 Aug 2016, 14:54

lizardmech wrote:
yes_we_can_gogreen wrote:-STM FOC, appears to be less advanced does not sense voltage on phases only vbus. If the existing chinese controllers use this software they may not have phase voltage measurements meaning VESC will not function.
VESC will use the phase voltages for BLDC mode, not for FOC mode (this is what Benjamin told me. In an Email or on the forum: I don't remember....). If you decide to always use FOC, you could get by without using the phase voltage measurements. (running the motor in BLDC mode is required for FOC parameter detection).

yes_we_can_gogreen
Posts: 40
Joined: 13 Apr 2016, 10:27
Location: uk

Re: Suggestions for OpenSource Electric Unicycle firmware

Postby yes_we_can_gogreen » 01 Aug 2016, 15:12

There are 2 "chinese" boards that I experimented. 1st gen measure current 1 shunt resistor, have hall sensors and analog circuit that outputs a square signal related to BEMF or such. The best I could get on that time was to drive the motor, that could quick invert the rotation but making a bit noise at higher speeds and asking for more current - I just used hall sensors signal but now I guess I should used the BEMF signals after medium speed - guess the BEMF signals represents the correct timings of rotor. I were also using SVM. Here is a video of the best I got:


On 2nd gen boards, I know we get 2 phase currents and the motor is much more silent. Also this motor now runs at more than 30km/h while the gen 1 board/motors just runs at max 18km/h.

Maybe I should use the same code to run 2nd gen motor up to low speed and then find a way to have the best rotor position as possible, maybe there is a way without using an estimator that needs float math.

pf26
Posts: 278
Joined: 28 Mar 2016, 14:37
Location: FR Valence

Re: Suggestions for OpenSource Electric Unicycle firmware

Postby pf26 » 01 Aug 2016, 15:43

If you want to use FOC, you need to measure bemf in order to be able to start an already running motor. In VESC mcpwm_foc.c, you can find this :

Code: Select all

      // Track back emf
      float Va = ADC_VOLTS(ADC_IND_SENS1) * ((VIN_R1 + VIN_R2) / VIN_R2);
      float Vb = ADC_VOLTS(ADC_IND_SENS3) * ((VIN_R1 + VIN_R2) / VIN_R2);
      float Vc = ADC_VOLTS(ADC_IND_SENS2) * ((VIN_R1 + VIN_R2) / VIN_R2);

      // Clarke transform
      m_motor_state.v_alpha = (2.0 / 3.0) * Va - (1.0 / 3.0) * Vb - (1.0 / 3.0) * Vc;
      m_motor_state.v_beta = ONE_BY_SQRT3 * Vb - ONE_BY_SQRT3 * Vc;

      // Park transform
      float c,s;
      utils_fast_sincos_better(m_motor_state.phase, &s, &c);
      m_motor_state.vd = c * m_motor_state.v_alpha + s * m_motor_state.v_beta;
      m_motor_state.vq = c * m_motor_state.v_beta  - s * m_motor_state.v_alpha;

      // Update corresponding modulation
      m_motor_state.mod_d = m_motor_state.vd / ((2.0 / 3.0) * m_motor_state.v_bus);
      m_motor_state.mod_q = m_motor_state.vq / ((2.0 / 3.0) * m_motor_state.v_bus);


This is done when the FETs are not powered, so as to be prepared with the SVM precisely matching the motors phases voltages (in phase and in voltage). If they don't match when you start output the SVM on the FETs, there will be a large current spike (especially with low resistance/inductance motors).
Possibly you can determine your rotor position using hall sensors and/or your squared bemf. And then you also need to determine your bemf voltage, maybe assuming the bemf is proportional to rotor speed. Battery voltage variations should also be taken into account..
This is really painfull to implement. I am strugling with a 16bits dsPIC based hardware on the very same issue.

yes_we_can_gogreen
Posts: 40
Joined: 13 Apr 2016, 10:27
Location: uk

Re: Suggestions for OpenSource Electric Unicycle firmware

Postby yes_we_can_gogreen » 01 Aug 2016, 17:29

Thanks pf26, you gave more information/knowledge.

rew
Posts: 905
Joined: 25 Mar 2016, 12:29
Location: Delft, Netherlands.

Re: Suggestions for OpenSource Electric Unicycle firmware

Postby rew » 02 Aug 2016, 18:04

pf26 wrote:If you want to use FOC, you need to measure bemf in order to be able to start an already running motor.
Ah! Of course!

yes_we_can_gogreen
Posts: 40
Joined: 13 Apr 2016, 10:27
Location: uk

Re: Suggestions for OpenSource Electric Unicycle firmware

Postby yes_we_can_gogreen » 04 Aug 2016, 23:03

So, I just wrote the simplified schematic with all pins/signals that goes to the STM32, and guess what, there is only current for phase A and C and battery total voltage, so, NO reading voltage of each phase.

Can you guys guess what kind of control is possible with such board?? could be possible to have FOC?? Thanks in advance.

The schematic is here: https://github.com/EGG-electric-unicycl ... B4.sch.png
Sources on github: https://github.com/EGG-electric-unicycl ... en2_boards

More tecnhical information about the board: https://github.com/EGG-electric-unicycl ... -bluetooth

lizardmech
Posts: 171
Joined: 19 Jan 2016, 10:54
Location: Australia

Re: Suggestions for OpenSource Electric Unicycle firmware

Postby lizardmech » 05 Aug 2016, 06:33

It's just the standard STM FOC setup. If you download their motor software you will see it. The main limitation is it's unable to profile motors. Microworks likely just have their own motor profiling board, they test a motor then write details into their firmware directly. I'm not certain if it will impact FOC performance, possibly if you have very accurate motor specification current sense accuracy is less important.

yes_we_can_gogreen
Posts: 40
Joined: 13 Apr 2016, 10:27
Location: uk

Re: Suggestions for OpenSource Electric Unicycle firmware

Postby yes_we_can_gogreen » 05 Aug 2016, 07:45

Thanks. I will test their tool and I hope it outputs source code. I would like to see how they get the rotor angle.

yes_we_can_gogreen
Posts: 40
Joined: 13 Apr 2016, 10:27
Location: uk

Re: Suggestions for OpenSource Electric Unicycle firmware

Postby yes_we_can_gogreen » 05 Aug 2016, 09:38

The STM tool just outputs a lib, no source. I need to find if is possible to have some estimator for rotor angle based only on the phase current measurements and battery voltage inputs.

lizardmech
Posts: 171
Joined: 19 Jan 2016, 10:54
Location: Australia

Re: Suggestions for OpenSource Electric Unicycle firmware

Postby lizardmech » 05 Aug 2016, 11:44

All the ones provided by MCU companies are like that, everything but the estimator is open source. VESC is the only one I know of with an open source estimator.

Even if you had a stm32f1 compatible option I'm not sure you would easily get it working as you have to overcome motor calibration as the board doesn't have things it requires. Then there is issues with not knowing things about the board such as how many amps the shunted allegro sensors measure. Most likely by the time you figured out all the details it would be cheaper and easier just to make a new board as many will controllers will end up broken during attempts to reverse engineer them.


Return to “Custom Applications”

Who is online

Users browsing this forum: No registered users and 1 guest