Index

MicroWorks 30B4 board

  1. Datasheets 30B4
    1. STM32F103
      1. ADC
      2. STM32 EEPROM
    2. MPU6050
      1. DMA
      2. Issue communications
        1. 01
    3. MPU6050 freq
  2. firmware motor control
  3. Implementations with MicroWorks 30B4 board
  4. Links to sellers

MicroWorks 500W 30km/h motor

  1. BEMF measurements

Flash and Debug STM32

  1. Eclipse IDE and JTAG
  2. Unlock STM32F103 with JTAG
  3. Flash firmware using Bluetooth
    1. STM32F103C6T8 bootloader
    2. ZS-040 Bluetooth module
      1. HC-06 hc01.comV2.0
  4. Serial Port Bluetooth
  5. Serial Port Plot
  6. SM32F103C8T6 use 128kbytes flash

FOC

  1. Observer
  2. Shane Colton documentation and firmware
    1. Firmware
    2. Part 1: Field-Oriented
    3. Part 2: Field-Oriented
    4. Sensorless Pneu Scooter - part 1
    5. Sensorless Pneu Scooter - part 2
    6. Sensorless Pneu Scooter - part 3
  3. Texas Instruments videos
  4. Chinese controllers code

Balance controller

  1. Chinese balance group reference design
  2. Kerry D. Wong -- A Self-Balancing Robot
    1. A Self-Balancing Robot – I
    2. A Self-Balancing Robot – II
    3. A Self-Balancing Robot – III
  3. Self balance bicycle
  4. PID
  5. LQR
    1. Stages of development of the robot-balancer
  6. PID and LQR, MATLAB
  7. Steve Brunton videos

Mechanical parts

  1. Pedals

Various

  1. C language for critical systems
  2. Hall effect sensor placement
  3. The brilliant idea of slow rotating motors
    1. Why does the Torquemax rotate so slowly and so forcefully
  4. Finding Motor Phase-Sensor Combinations

Clipping

  1. Hackaday - 2017.05.07 - opensource firmware for hoverboards

Self balance bicycle

http://www.plctalk.net/qanda/showthread.php?t=103066

images/70-1.png

click meclick me
Is a PD controller correct choiceHi - I know the following isn't about PLCs but I've seen some great info about PID controllers here, so was hoping for some help. I am absolutely beginner in all of this... I am making a self balancing bicycle (something like this: https://www.youtube.com/watch?v=kEctw-TUCcs) and will use a PID controller to control the PWM to the flywheel motor. I believe that I need only a PD controller and that I will not help here as there is no steady-state error. Would you agree? However, one concern I have with the use of D is, since this is a rapidly changing system (the PV - angle - will change quickly due to falling and then the correction by the flywheel), won't this cause a very high PWM (since de/dt will be high)? As I understand it, D causes dampening to reduce overshoot from P. To dampen the effects of the P, I understand I need a suitable D (relatively large)...but then doesn't the derivative also kick in as the error increases? So, the D will now cause a high PWM output, thereby causing potentially some overshoot. Also, can you give some hints on tuning the PID for this? I have tried the difficult manual method without much success. I'm not sure how to apply some of the other methods I've read about in such a system since measuring variables is very difficult.

images/70-2.png

images/70-3.png

images/70-4.png

images/70-5.png

click meclick me
May 18th, 2016, 09:46 AM #2
RocketTesterMember Join Date: Oct 2009Location: Sacramento, CAPosts: 158 I agree that PD is typical in controlling such "servo" systems with much inertia. Integral action is more useful for long-term trim in process control like chemical plants. But, I doubt basic feedback control will be sufficient for your process, which is trying to make an unstable system stable via active control. You most likely will also need "anticipatory" action, termed "feed-forward" or "open-loop control". These are algebraic equations that look at disturbance variables to the system and apply control output before a set-point error is realized. If you add the proper dynamics (lead/lag), they are differential equations. Feedback control is like trying to keep a car in its lane by looking straight down at a lane line, whereas feed-forward would be looking ahead, seeing the lane curve and start turning the wheel a little early. Another example, think of Space X trying to land a tall, skinny booster on a barge in heaving seas. Feed-forward inputs might be approaching waves, tilting rate of the platform, approaching air gusts, ... Even if you have only the controlled variable as an input, there are additions to PID that act similarly. Look at Delta Computer's RMC motion controllers, which have enhanced derivative terms.

images/70-6.png

images/70-7.png

images/70-8.png

images/70-9.png

images/70-10.png

click meclick me
May 18th, 2016, 10:03 AM #3
kamengesMember Join Date: Nov 2002Location: Brillion, WIPosts: 3,604 The first thing you need to understand and account for is, even in the small signal sense, this is a non-linear system. A given set of PID tuning values will only be valid for a very small range of angles. So you either have to scale your PID output based on the angle of the bike or you will have to perform what is referred to as gain scheduling, which means to change the PID gains as the bike angle changes. Ideally I think gain scheduling may be the better plan. However, that will require you to make up a mathematical model of your system so you have something to calculate the gains from. Also, what are you intending to use to command the motor? Is it a speed command or a torque command? Keep in mind that the restoring force is supplied by the acceleration of the wheel and for any given bike angle there will be a wheel acceleration required counteract the disturbance force due to angle. So ideally the output of your controller will be a torque command, not a velocity command. If it has to be a velocity command you should integrate the output of your controller prior to sending it to the motor controller so the result of the control action is acceleration of the wheel. I don't think you will be able to get by without the derivative gain. I think this will end up evaluating to an integrating system. Without the derivative gain you won't be able to keep the thing stable as you go past center. Also, having the damping present as the error changes is a good thing, not a bad thing. You are going to have a hard time tuning this manually. You may ultimately get it to work but it won't be easy. Keith

images/70-11.png

images/70-12.png

images/70-13.png

images/70-14.png

images/70-15.png

Originally Posted by dpatel20I believe that I need only a PD controller and that I will not help here as there is no steady-state error. Would you agree?

Yes, agreed.

Quote:images/70-16.png

Originally Posted by dpatel20However, one concern I have with the use of D is, since this is a rapidly changing system (the PV - angle - will change quickly due to falling and then the correction by the flywheel), won't this cause a very high PWM (since de/dt will be high)?

Yes, if PWM is your controller's output. You'll be limited by the max PWM your motor can receive. The bike's angle is a function of gravity, which is second order force (an acceleration). Thus, the more time angle of the bike is increasing (or decreasing) the higher the rate angle change (think speed of angle change).

Quote:images/70-17.png

Originally Posted by dpatel20 ...but then doesn't the derivative also kick in as the error increases?

D kicks in as the 'rate of error change' increases. D won't act at all on a constant or steady state error regardless of how large.

Quote:images/70-18.png

Originally Posted by dpatel20Also, can you give some hints on tuning the PID for this?

If you can't find anything (I'd be surprised) on a bike controller, look up inverted pendulum. Very similar classic controller. images/70-19.png images/70-20.png

images/70-21.png

images/70-22.png

images/70-23.png

click meclick me
May 19th, 2016, 01:59 AM #5
dpatel20Member Join Date: May 2016Location: EnglandPosts: 4 Thanks all for your responses. I guess I've got my work cut out to get this to work! Keith - I am controlling the voltage using the PWM. Is that incorrect?

images/70-24.png

images/70-25.png

images/70-26.png

images/70-27.png

images/70-28.png

Originally Posted by kamengesIf it has to be a velocity command you should integrate the output of your controller prior to sending it to the motor controller so the result of the control action is acceleration of the wheel.

Typo. Should be:
differentiate the output of your controller images/70-29.png images/70-30.png

images/70-31.png

images/70-32.png

images/70-33.png

Originally posted by danw:

Typo. Should be:
differentiate the output of your controller

No, I meant integrate.

Functionally, the controller is attempting to generate a restoring FORCE to bring the bike back to vertical. The only way a rotating wheel can generate a force is through acceleration. If the output of the controller is a force (acceleration) command and the motor controller takes a velocity command the user would need to integrate the force/acceleration command to generate the changing velocity command necessary to result in an acceleration.

Quote:
Originally posted by dpatel20:

Keith - I am controlling the voltage using the PWM. Is that incorrect?

No, that isn't incorrect. You just need to know what it is you are working with so you know how to use it. I assume the motor is a permanent magnet DC motor. So motor velocity is proportional to motor voltage. However, the motor response is a linear first order system of it's own. Said another way, the motor won't instantly achieve the speed that the voltage to the motor would seem to indicate it would. I think your velocity command changes will be small enough per iteration that this won't factor in too much but realize it is there.

Also, as stated above, your control output will likely be a restoring force to bring the bike back to level. Imagine that the bike can magically hang at a given angle that is not vertical but doesn't move. The P portion of your controller will try to generate a restoring force to bring the bike back to vertical. If you use this output directly as the command to the motor you will end up with a fixed motor speed that will not generate a restoring force. If you integrate this command you will end up with a constant acceleration, which will generate a restoring force. Take some time to make sure you understand where your forces are coming from and how they will act on the system. This all assumes there isn't some other quality of the wheel that will generate a restoring force simply due to rotation.

Also, as AGill pointed out, do some research on the inverted pendulum problem. If you ignore swing-up, the bike balancing problem is pretty similar to the inverted pendulum problem.

Keith Last edited by kamenges; May 19th, 2016 at 09:11 AM. images/70-34.png images/70-35.png

images/70-36.png

images/70-37.png

images/70-38.png

images/70-39.png

click meclick me
May 19th, 2016, 12:46 PM #8
danwMember Join Date: Oct 2004Location: midwest, USAPosts: 2,564 Sorry. My misread. I misread it as have velocity, need force.

images/70-40.png

images/70-41.png

images/70-42.png

images/70-43.png

click meclick me
May 19th, 2016, 03:01 PM #9
dpatel20Member Join Date: May 2016Location: EnglandPosts: 4 Keith - Yes, I recognised the problem was an inverted pendulum (with a reaction wheel) and have taken time to understand the equations of motion, etc. But having read your post I have to say I am now confused! My understanding: the reaction wheel generates a torque as it accelerates and conservation of momentum means the bike will 'turn' in response - thereby correcting the bike angle. Since, the flywheel torque = motor torque, then controlling the motor torque is key. Torque=KI. In my implementation, I cannot control current but can control voltage. Now, this is where I'm confused - if I understood correctly, as the voltage increases so does the speed (so, there's acceleration). As the reaction wheel accelerates there is torque thereby causing an increase in motor current. But I am unclear how my controller should be... In my set up, I am taking the angle of the bike as the PV and use the PID to generate a value for the PWM - with the view that as the voltage increases motor speed increases, it accelerates the reaction wheel and causes torque. My thinking here is that the greater the change in angle, the greater the PWM change - which means greater acceleration - and, hence, generates more corrective torque. From your post, though, I get the impression this is wrong/over simplified or I'm missing something fundamental?

images/70-44.png

images/70-45.png

images/70-46.png

images/70-47.png

images/70-48.png

click meclick me
May 19th, 2016, 08:24 PM #10
kamengesMember Join Date: Nov 2002Location: Brillion, WIPosts: 3,604 You are going to very quickly outpace my ability to help you with this. There are others on this forum that may be able to take you farther. I can only speak about this in generalities. I think you are very close with what you are thinking. However, to make sure you are getting the output you want it may help to think of this system in a static sense. Imagine holding the bike at a 5 degree angle with your hand and turning on your controller. What should the motor do? Based on what I THINK you said in your post the controller would generate an output and the motor would accelerate to a velocity determined by the 5 degree angle and then hold that velocity. What you would feel is a quick push against your hand in the direction to move the bike back to a balanced position and then nothing. In addition, you wouldn't have much control over that pulse magnitude. The pulse strength would be based on the motor transfer function. What SHOULD happen is the controller generates an output just like before but that output should cause the motor to continuously accelerate until it is at maximum speed (assuming the 5 degree angle remains where it is). All the while it is accelerating you should feel a force pushing the bike against your hand trying to get it to stand up. Do you see the difference between the two descriptions? A constant force request cannot result in a constant velocity. Keith

images/70-49.png

images/70-50.png

images/70-51.png

click meclick me
May 20th, 2016, 03:40 AM #11
dpatel20Member Join Date: May 2016Location: EnglandPosts: 4 That makes sense and I understand the difference between the two now. And I really appreciate the help. I'll have to think about the scenario you mention. Thanks.