Pages: 1 2 [3]   Go Down
Author Topic: PD of PID in a balancing robot  (Read 4322 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 301
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

PeterH, I'm little bit confused that you say we don't need accel, actually without filtering, if using only gyro output, the big drift I'd have and change of set-point that happens, I get nothing, I tried it long before this experiment!

It is impossible in my practice to not to combine output of gyro and accel, and yet balance the bot! I've read so many works (of other people already done it) and everybody is doing it this way, writing that impossible to use only gyro!

Of course, I'm in no way on an authority to claim anything in control, just I report what I've read. Actually if you personally can do it, is because of your skills that I unfortunately don't have, all i have is a background in math and a lot of reading online about this project, and still with a bot that can't balance really smiley

Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 301
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

In your initial post code, there is some stuff after that, which I don't understand:
Code:
...
    analogWrite(RPWM, -output);
  }  [color=green]// probably not good enough, but understood up to here  ;)[/color]
  
  output = -1 * output;
    if(output >= 0)
  {
    digitalWrite(RDIRA, HIGH);
    digitalWrite(RDIRB, LOW);
    analogWrite(RPWM, output);
  }
  else
  {
    digitalWrite(RDIRA, LOW);
    digitalWrite(RDIRB, HIGH);
    analogWrite(RPWM, -output);
  }



  }//if(!(angle>30 || angle < -30))
  else
  {
    analogWrite(LPWM, 0);
    analogWrite(RPWM, 0);
  }


I assume output should represent the speed you want your robot to move. It does not need to be exactly proportional, but you should work on that a bit, too.
- What's the minimum/maximum speed your bot can do ? For smooth and easy contol, motor should react immediately with slow speed. Max speed should rather tell you when to give up.
- What's the dynamic behavior of your balancing rod when it falls ? angle / angular velocity  over time ?
- I think you don't need sin/cos even (5.7° = 0.1 * R is sufficient around your "set point") but a bit of math won't hurt.
- Did you consider that the more your sensor has left the 0° position, the more moving the motor will accelerate it ?  

oh, sorry, I just got that you are pointing this:
Code:
 output = -1 * output;
well, I just changed motors and swapped the left/right wires of motors and one of them started to turn not in the right direction, instead of changing in hardware, I added that line to just turn the output sign to the opposite one, which in turn effects on the 'if' decision and I got the motor turning again on the right direction.

I set 255 to get max. speed and it is claimed by the seller that this motor turns 300rpm, but I did not pass any motor identification process to give a reliable data of the speed.

dynamic behavior  - I'm not sure if I got what you mean by that, when it falls: it takes some 10 deg and only by then the motor reaction happens, which is late, and robot starts to fall, and motors get to turn so fast, until it falls completely and motors stop smiley-sad

 I think you don't need sin/cos even - also didn't get you! sorry!

the more moving the motor will accelerate it ? - no, I don't feel that, but I'd submit a behavioral video, so you all who are kindly helping see it, that is better than me describing it, yet with my English which is noisy smiley

Logged

UK
Offline Offline
Shannon Member
****
Karma: 184
Posts: 11159
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

PeterH, I'm little bit confused that you say we don't need accel, actually without filtering, if using only gyro output, the big drift I'd have and change of set-point that happens, I get nothing, I tried it long before this experiment!

It is impossible in my practice to not to combine output of gyro and accel, and yet balance the bot! I've read so many works (of other people already done it) and everybody is doing it this way, writing that impossible to use only gyro!

Of course, I'm in no way on an authority to claim anything in control, just I report what I've read. Actually if you personally can do it, is because of your skills that I unfortunately don't have, all i have is a background in math and a lot of reading online about this project, and still with a bot that can't balance really smiley

If you are in contact with somebody who has actually done it, then follow their advice. I haven't - I am only telling you my understanding of the theory.

In my opinion, the accelerometer will not do what you intend it to do. The tilt calculations are based on measuring very small lateral accelerations that occur when the sensor is not perfectly level. This only works on a stationary object, and of course your bot is not stationary. As soon as your bot starts to move sideways the sensor will get a big horizontal acceleration that swamps the tiny signal you were using to calculate the direction of gravity.

Now, you can try using that instead of calculating the lean angle, if you like. As soon as the bot starts to fall to the left you move the wheels in the direction it's falling. To get that working reliably you'd really need to be able to work out and control the acceleration caused by your motors and model the relationship between the movement of the base and the top of your bot. Although it would be possible to do, it'd look nothing like the algorithm you have got there and would be quite hard to get working.

I think you are better off with the approach you're using, of trying to measure the orientation of the bot. The primary sensor for doing this is the gyro. You have it sitting in front of you; I don't. What signal do you get off the gyro in practice? What is the minimum angular rate you can read from it, and how much latency is there in reading it?

You are right that you need to cope with drift. If it was my project, the way I'd do that was to add a second feedback loop which tried to drive the amount of correction towards zero. In effect it would self-calibrate towards the vertical at startup, and inherently deal with gyro frift. But there's no point thinking about that until you have got the basic underlying feedback loop working. And that depends on know what your sensors are telling you. Hence I keep asking the question: what are you getting from that gyro?
Logged

I only provide help via the forum - please do not contact me for private consultancy.

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 301
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

PeterH thank you for this much support, my aim is to do the project to learn something and I'm ready to try different direction that I took at first. So let's do it the way you suggest, but I've doubt I fully understand you in this (to measure gyro).

Do you mean that I post here simply information like:
1. if I keep robot stationary, output of gyro is x
2. leaning forward fast to around 45deg I get y
3...

or what best way to answer your question "output of gyro" please?
Logged

Germany
Offline Offline
Faraday Member
**
Karma: 49
Posts: 2741
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

2. leaning forward fast to around 45deg I get
Don't bother about 30° or more: If your motor at full speed is able to catch that, it's nice, but you should rather get numbers (or a feeling, at least) about what happens and what your sensor says, when your bot begins leaving the balanced position. (In that region where degrees and displacement in x direction is nearly proportional...)
Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 301
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, thank you all for continuous support!

Just received my new sensors: a separate gyro and a separate accel (my current sensor as you see on photos, has both of them combined on one board).

I can't rely on my old sensor, not really sure about its health, she is too old!

With new ones I'd first build a new chassis, with the hope that it gives me room to easily apply changes as you suggest and instruct. This will take probably around 2 weeks and I'd be back here with a new bot which (hopefully) also helps to answer the questions you kindly put (how goes the output of gyro if you do this/that?) easy and fast.

Please, if you have suggestions for the new chassis I'd build, proportionality info., etc. let me know. What I know for now is that, I'd for instance build the vertical axis in around 70cm height, so that to have it falling not too fast, and keep the base in a way I can add and remove weight to easily change the moment of inertia. Any other suggestions will be very welcome, I will apply them in 3D modeling of chassis in software and finally cut with CNC.

Thank you again,
Logged

Germany
Offline Offline
Faraday Member
**
Karma: 49
Posts: 2741
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

BTW: there is a dedicated Robotics thread http://arduino.cc/forum/index.php/board,14.0.html , discussing "balancing robot" similar to yours (1 ft high, two wheels) http://arduino.cc/forum/index.php/topic,60170.0.html
Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 301
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Man, I just visited the links and the video clip there: when he leans the bot even just a degree, motors react, in my version, I have some 5 deg before reaction, I must take record a video before destructing the current one and upload here!
Logged

UK
Offline Offline
Shannon Member
****
Karma: 184
Posts: 11159
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Man, I just visited the links and the video clip there: when he leans the bot even just a degree, motors react, in my version, I have some 5 deg before reaction, I must take record a video before destructing the current one and upload here!

I think you're looking at the real problem now, but I'm still not clear whether the slow reaction is caused by the sensors, or your algorithm. I really think you need to write a sketch that just outputs the raw data from your gyro and accelerometer and find out how sensitive they are and how quickly they respond. Don't try to do any clever mapping or anything - just output the raw data as promptly and simply as you can.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Germany
Offline Offline
Faraday Member
**
Karma: 49
Posts: 2741
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The fact that you reported the motor producing a sound only on low values and started turning with higher pwm output and without load only, is something you should definitely try to solve.
Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 301
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

True, I'd approach it and some other problems in a totally new design, hopefully to bring it to 1 level higher totally.

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

although it's an old topic,I'd like to share my case>>

I used to have the same problem.. using PD only the robot wouldn't respond to small change in angle and when I increased the P term it went crazy,,,D term wasn't helpful at all and when increased the robot starts to vibrate !!

as mentioned in previous posts this maybe due to noisy data...and what they said is true
I zeroed the D term and put I term instead and it balanced!! just like that!!
I term was like magic! 
Logged

Pages: 1 2 [3]   Go Up
Jump to: