Jump to content

Firmware


jayjay23

Recommended Posts

4 hours ago, Hunka Hunka Burning Love said:

Not sure if this might help as it is for a different processor, but here's some C source code from an MIT guy who made his own wheel...

https://gist.github.com/stepchowfun/2475495

https://www.stephanboyer.com/post/17/my-electric-unicycle

Thanks!!

//We set the torque proportionally to the actual angle of tilt (anglerads), and also proportional to the RATE of tipping over (ganglerate rads)
//the 4.5 and the 0.5 set the amount of each we use - play around with them if you want.

https://cdn.instructables.com/ORIG/FL4/Z0JZ/HQ1E0PYO/FL4Z0JZHQ1E0PYO.txt

Seems everyone is doing differently from my MicroWorks EUC. For what I can understand, like that, user need to keep the forward till while riding!!

On my EUC, I till just for accelerating and then I go back to vertical position to maintain that speed -- it is really different!! @Hunka Hunka Burning Love can you please confirm your EUC works like this??

And on the code: https://gist.github.com/stepchowfun/2475495

// proportional term
motor_speed = angle*MOTOR_GAIN_P*(1.0f-exp(-(angle*angle)*MOTOR_DEAD_ZONE));

MOTOR_DEAD_ZONE = 0.5:

Screenshot_from_2017-05-12_05-34-39.png

MOTOR_DEAD_ZONE = 0.05:

Screenshot_from_2017-05-12_05-37-35.png

Although seems the code also sets motor duty cycle proportionally to the actual angle of tilt, it have something interesting that I may be missing!! that "dead zone" on the vertical / point of balancing. Maybe that's why is so hard to balance if there is no dead zone. Maybe the softness/less softness of acceleration settings on EUCs are this dead zone.

My current code is more like this (green line):

Screenshot_from_2017-05-12_05-43-21.png

 

By the way, found a video of a device that is clearly oscillating, not balancing well. Also seems the rider needs to keep the till to keep the velocity - again, I do not want to do like this, at least I didn't learn to ride an EUC like that :-)

 

Link to comment
Share on other sites

1 hour ago, lizardmech said:

How is sensor fusion being done? I didn't see a kalman filter.

The code is there but commented, and for complementary filter that seems everyone is using it. I found that current code seems to output the angle value correctly and fast like it is now - I can always uncomment the code if I think I need it.

Link to comment
Share on other sites

Hmmm, good information:

  balance_torque = (float) (TORQUE * anglerads) + (POWER * gangleraterads); //power to motors (will be adjusted for each motor later to create any steering effects
  //balance torque is motor control variable we would use even if we just ahd one motor. It is what is required to make the thing balance only.
  //the values of 4.5 and 0.5 came from Trevor Blackwell's segway clone experiments and were derived by good old trial and error
  //I have also found them to be about right
  //We set the torque proportionally to the actual angle of tilt (anglerads), and also proportional to the RATE of tipping over (ganglerate rads)
  //the 4.5 and the 0.5 set the amount of each we use - play around with them if you want.
  //Much more on all this, PID controlo etc on my website
  cur_speed = (float) (cur_speed + (anglerads * 6 * cycle_time)) * 0.999;
  //this is not current speed. We do not know actual speed as we have no wheel rotation encoders. This is a type of accelerator pedal effect:
  //this variable increases with each loop of the program IF board is deliberately held at an angle (by rider for example)
  //So it means "if we are STILL tilted, speed up a bit" and it keeps accelerating as long as you hold it tilted.
  //You do NOT need this to just balance, but to go up a slight incline for example you would need it: if board hits incline and then stops - if you hold it
  //tilted for long eneough, it will eventually go up the slope (so long as motors powerfull enough and motor controller powerful enough)
  //Why the 0.999 value? I got this from the SeWii project code - thanks!
  //If you have built up a large cur_speed value and you tilt it back to come to a standstill, you will have to keep it tilted back even when you have come to rest
  //i.e. board will stop moving OK but will now not be level as you are tiliting it back other way to counteract this large cur_speed value
  //The 0.999 means that if you bring board level after a long period tilted forwards, the cur_speed value magically decays away to nothing and your board
  //is now not only stationary but also level!
  level = (float)(balance_torque + cur_speed) * overallgain;  
  //level = (float)balance_torque * overallgain;  //You can omit cur speed term during testing while just getting it to initially balance if you want to
  //avoids confusion

https://cdn.instructables.com/ORIG/FL4/Z0JZ/HQ1E0PYO/FL4Z0JZHQ1E0PYO.txt

Link to comment
Share on other sites

17 minutes ago, electric_vehicle_lover said:

The code is there but commented, and for complementary filter that seems everyone is using it. I found that current code seems to output the angle value correctly and fast like it is now - I can always uncomment the code if I think I need it.

@lizardmech, maybe I must need to use complementary filter:

float aa = 0.005; //this means 0.5% of the accelerometer reading is fed into angle of tilt calculation with every loop of program (to correct the gyro).
//accel is sensitive to vibration which is why we effectively average it over time in this manner. You can increase aa if you want experiment. 
//too high though and the board may become too vibration sensitive.
angle = (float) ((1-aa) * (angle + gyroangledt)) + (aa * x_accdeg);//aa allows us to feed a bit (0.5%) of the accelerometer data into the angle calculation
  //so it slowly corrects the gyro (which drifts slowly with tinme remember). Accel sensitive to vibration though so aa does not want to be too large.
  //this is why these boards do not work if an accel only is used. We use gyro to do short term tilt measurements because it is insensitive to vibration
  //the video on my instructable shows the skateboard working fine over a brick cobbled surface - vibration +++ !
Link to comment
Share on other sites

On 2017-05-11 at 10:48 PM, electric_vehicle_lover said:

On my EUC, I till just for accelerating and then I go back to vertical position to maintain that speed -- it is really different!! @Hunka Hunka Burning Love can you please confirm your EUC works like this??

That is different as my generic and Ninebot require that you lean to maintain the speed.  If you stand back staight up after accelerating they both slow down.  I think the controller needs that lean to detect the tilt so it drives the motor.

Edited by Hunka Hunka Burning Love
  • Upvote 1
Link to comment
Share on other sites

@Hunka Hunka Burning Love was you looking for a EUC motor of 18'' or 22''??

Because I have one idea: since EUC motors seems to be the same as EBikes, we could found EBike direct drive motors (with hall sensors) and then make our custom wheel size from 16'', 20, 24, 26, 700c. I usually buy EBike parts here: https://bmsbattery.com/ebike-parts/112-double-wall-aluminum-alloy-rim-parts.html?search_query=rim&results=91

Link to comment
Share on other sites

1 hour ago, electric_vehicle_lover said:

@Hunka Hunka Burning Love was you looking for a EUC motor of 18'' or 22''??

Because I have one idea: since EUC motors seems to be the same as EBikes, we could found EBike direct drive motors (with hall sensors) and then make our custom wheel size from 16'', 20, 24, 26, 700c. I usually buy EBike parts here: https://bmsbattery.com/ebike-parts/112-double-wall-aluminum-alloy-rim-parts.html?search_query=rim&results=91

I was hoping Microworks had a 16" or larger wheel that would work with their controllers before, but the ones they had in stock they said wouldn't work with self-balancing unicycles for some reason.  I also thought the Ebike motors weren't compatible as well?  Maybe it's due to fewer magnets or something?  I'm not sure what the reason is.

Remember those 16" and 18" ones Microworks had on their sales pages?  The 16" had a connector similar to the Ninebot's wheel and the 18" had spokes identical to the Kingsong KS18,  but everyone said they wouldn't work.

In regards to Lisardmech's question I always thought that if you could find a wheel's level position you could pick it up without it wanting to spin?

Edited by Hunka Hunka Burning Love
Link to comment
Share on other sites

25 minutes ago, Hunka Hunka Burning Love said:

I was hoping Microworks had a 16" or larger wheel that would work with their controllers before, but the ones they had in stock they said wouldn't work with self-balancing unicycles for some reason.  I also thought the Ebike motors weren't compatible as well?  Maybe it's due to fewer magnets or something?  I'm not sure what the reason is.

I found a ebike hub motor that is equal (same number of magnets and poles) to one motor of an old EUC I have: https://www.electricbike.com/9c/

I have seen EBike motors (the ones more like scooters) that also have about ~60 poles...

  • Upvote 1
Link to comment
Share on other sites

On 26/03/2017 at 11:09 AM, RolluS said:

I have a Microworks (6 mosfet) and a ReinTech (12 mosfets)  boards laying around I'd like to test for a two wheels vehicle, no need for balance code.

Do you have contact with ReinTech? MicroWorks disappeared and maybe we can buy boards from ReinTech?

Link to comment
Share on other sites

@Hunka Hunka Burning Love BMSBattery sells https://bmsbattery.com/ebike-kit/580-q11-48v1kw-rear-driving-e-bike-hub-motor-wheel-ebike-kit.html?search_query=direct+drive&results=41#/89-wheelrim-24_1_5_1_95 the same motor https://www.electricbike.com/9c/ and it even works with the cheap controllers https://bmsbattery.com/ebike-kit/552-s12s-500w-torque-simulation-sine-wave-controller-ebike-kit.html that I am developing firmware for.

So is a 1KW motor and BMSBAttery can sell with a 24'' wheel -- how much speed can it do?? it says 370 RPMs... at 48V.

  • Upvote 1
Link to comment
Share on other sites

58 minutes ago, electric_vehicle_lover said:

@Hunka Hunka Burning Love BMSBattery sells https://bmsbattery.com/ebike-kit/580-q11-48v1kw-rear-driving-e-bike-hub-motor-wheel-ebike-kit.html?search_query=direct+drive&results=41#/89-wheelrim-24_1_5_1_95 the same motor https://www.electricbike.com/9c/ and it even works with the cheap controllers https://bmsbattery.com/ebike-kit/552-s12s-500w-torque-simulation-sine-wave-controller-ebike-kit.html that I am developing firmware for.

So is a 1KW motor and BMSBAttery can sell with a 24'' wheel -- how much speed can it do?? it says 370 RPMs... at 48V.

I would be really curious to see if that motor would work with the Microworks 30B controller with stock firmware.  Does the firmware need to be adjusted to compensate for the diameter of the wheel, or does it just try to keep the gyro sensor level?

Link to comment
Share on other sites

10 hours ago, electric_vehicle_lover said:

@Hunka Hunka Burning Love BMSBattery sells https://bmsbattery.com/ebike-kit/580-q11-48v1kw-rear-driving-e-bike-hub-motor-wheel-ebike-kit.html?search_query=direct+drive&results=41#/89-wheelrim-24_1_5_1_95 the same motor https://www.electricbike.com/9c/ and it even works with the cheap controllers https://bmsbattery.com/ebike-kit/552-s12s-500w-torque-simulation-sine-wave-controller-ebike-kit.html that I am developing firmware for.

So is a 1KW motor and BMSBAttery can sell with a 24'' wheel -- how much speed can it do?? it says 370 RPMs... at 48V.

Can we just do it properly and make open hardware? That thing costs $70 with shipping, doesn't support high enough voltages and has no IMU.

  • Upvote 1
Link to comment
Share on other sites

9 hours ago, Hunka Hunka Burning Love said:

I would be really curious to see if that motor would work with the Microworks 30B controller with stock firmware.  Does the firmware need to be adjusted to compensate for the diameter of the wheel, or does it just try to keep the gyro sensor level?

No, even the winding resistance being different will break compatibility let alone wheel size.

  • Upvote 1
Link to comment
Share on other sites

50 minutes ago, lizardmech said:

No, even the winding resistance being different will break compatibility let alone wheel size.

Not sure about this as my code is not using any winding resistance value!!

The only thing changing from the 500w MW motor to the others I have is phase wires and/or hall sensors wires sequence.

  • Upvote 1
Link to comment
Share on other sites

3 hours ago, lizardmech said:

Can we just do it properly and make open hardware? That thing costs $70 with shipping, doesn't support high enough voltages and has no IMU.

I wanted to say that motor works for EBikes and should also work for an EUC.  And that BMSBattery sells ready wheels with that motor, of size 24'' or higher.

As for hardware, I am very happy with 30B4 board. I even hope to use it soon for my EBike, as the motor controller. Would be great to have a board simple, cheap and widely available as 30B4 and be OpenHardware.

  • Upvote 1
Link to comment
Share on other sites

9 hours ago, electric_vehicle_lover said:

I wanted to say that motor works for EBikes and should also work for an EUC.  And that BMSBattery sells ready wheels with that motor, of size 24'' or higher.

As for hardware, I am very happy with 30B4 board. I even hope to use it soon for my EBike, as the motor controller. Would be great to have a board simple, cheap and widely available as 30B4 and be OpenHardware.

I can make completely new designs anytime now, I sorted out all the minor issues on my test boards. I can adapt them to anything now. Only thing preventing me is finding someone to help with C code.

  • Upvote 3
Link to comment
Share on other sites

13 minutes ago, lizardmech said:

I can make completely new designs anytime now, I sorted out all the minor issues on my test boards. I can adapt them to anything now. Only thing preventing me is finding someone to help with C code.

Since your firmware mainly lacks the EUC balance algorithm, I can't help you. After I finish the EUC balance algorithm, I may help you on that time.

  • Upvote 1
Link to comment
Share on other sites

On 5/14/2017 at 4:08 AM, electric_vehicle_lover said:

@Tomek since MicroWorks disappeared, do you know others sources for the boards?

nopes,

perhaps you could try your luck on Taobao, but you'd need a translator to help you

  • Upvote 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...