2

Author Topic: Velocity feedback hill robot:(  (Read 1674 times)

0 Members and 1 Guest are viewing this topic.

Offline TheBadgerTopic starter

  • Jr. Member
  • **
  • Posts: 33
  • Helpful? 0
Velocity feedback hill robot:(
« on: April 15, 2011, 10:48:52 AM »
So I have a White line following robot which has to scale a hill.

Everything is fine on the flat following the line with PID control, however as soon as it reaches the hill there is not enough power to get up the hill. So I increase Tp but this just makes the robot too fast on the flats.

So I thought I need some form of feedback of when the robot is on the hill, I thought about current measurement and tried using HCPL-7520s but there is some problem about isolation and such and its becoming a nightmare.

So I thought I would pitch it to you guys,

a) What do you think the best method of doing this is? current/velocity/accelerometer/tilt sensor?
b) What components to use?

Thanks a lot to all for any help

Offline mstacho

  • Supreme Robot
  • *****
  • Posts: 364
  • Helpful? 10
Re: Velocity feedback hill robot:(
« Reply #1 on: April 15, 2011, 10:54:18 AM »
Why not just actually DO velocity feedback for the whole thing?  You have the position error, so take its derivative and you'll have the velocity error, then try to control that instead.  Generating the setpoint values might be a bit weird, but not impossible, and that way you'll be able to control the robot's speed (and by extension, its position) on and off the ramp.

MIKE
Current project: tactile sensing systems for multifingered robot hands

Offline TheBadgerTopic starter

  • Jr. Member
  • **
  • Posts: 33
  • Helpful? 0
Re: Velocity feedback hill robot:(
« Reply #2 on: April 18, 2011, 09:11:09 AM »
I am not sure I understand what you are getting at, without psudocode or something I am a bit stuck

Offline mstacho

  • Supreme Robot
  • *****
  • Posts: 364
  • Helpful? 10
Re: Velocity feedback hill robot:(
« Reply #3 on: April 18, 2011, 09:20:06 AM »
PID works no matter what you're feeding back.  So instead of feeding back the position, feed back the velocity.

For instance, let's say I want to go in a straight line at a constant speed.  Then I have my desired speed set to, say, 10m/s.

setSpeed = 10;

LOOP
vN = Get Current Speed;
erSpeed = setSpeed - vN;

outPut = PID(erSpeed,gains);

//then put the output into the PWM, or whatever else it is you're using

END LOOP

The hard part here is that you have to be creative in how you generate the signal "setSpeed".  See, in PID with position feedback, you just detect the line and from that get your position error.  Here you'll have to take the derivative of the position error and call *that* erSpeed, which is sort of what I did above.

There is actually another really simple solution (sorry I didn't think of it before!) Just put a governor on your speed, *something* like this (i'm not 100% on how exactly this would work, but):

if SPEED < SomeMaxValue
   Set the gains to their hill climbing value
else
   Set the gains to their flat value
end

using straight forward position feedback.

Finally, there IS a third option: use the integral part.  PID = "Proportional, Integral, Derivative".  The P term makes the tracking work.  The D term makes it so that you don't overshoot and oscillate around where you want to be.  But the I term makes it so that when you have an error that isn't going away, it will ramp up and help out.  On flat ground, the I term will make the system oscillate a bit, but on the hill, when it isn't able to move, the I term will add the extra force to get it going.

It sounds like your system has enough power to make it up the hill, but the gains won't make it do so, so try using the I term or the second option above before making a speed controller.

Does...any of that make sense? :-P It's been a while since my last coffee, so ask for clarification when needed haha.

MIKE

**EDIT: slight error in the pseudocode fixed
Current project: tactile sensing systems for multifingered robot hands

Offline msprague

  • Jr. Member
  • **
  • Posts: 35
  • Helpful? 1
Re: Velocity feedback hill robot:(
« Reply #4 on: April 18, 2011, 06:20:48 PM »
Perhaps TheBadger meant that the algorithm to stay on the center of the line uses PID with multiple sensors, but the motors do not have any feedback (encoders, etc.) for velocity. 

Offline mstacho

  • Supreme Robot
  • *****
  • Posts: 364
  • Helpful? 10
Re: Velocity feedback hill robot:(
« Reply #5 on: April 18, 2011, 08:36:00 PM »
Maybe, although you could always just take the numerical derivative -- use a timer to get dt and just do:

dp = newPosition - oldPosition
speed = dp/dt

But I do admit that controlling the speed is a probably overkill -- the other two methods I suggested (and some I haven't?  Anyone else? :-P I never claim to be right all the time haha) should probably do it.

MIKE
Current project: tactile sensing systems for multifingered robot hands

Offline Kylepowers

  • Full Member
  • ***
  • Posts: 117
  • Helpful? 1
Re: Velocity feedback hill robot:(
« Reply #6 on: April 18, 2011, 10:05:39 PM »
You can use a pedometer on each wheel and set up a code that says the wheel needs to spin this many times a sec. Then when the robot hits the hill the robot will increase power to the motors. When it goes down hill it will then slow down because its going faster than the set set speeds. Its like cruise control in your car.

Basically your code would look a little like this:

If (speed of wheel) = 25 rotations per min
 then ( give 10% power to motor)
If( speed of wheel)< 25 rotations per min
 then ( give 20% power to motor)
If( speed of wheel)> 25 rotations per min
 then ( give 5% power to motor)

Thats the basic form of it you would need to do some trial and error but you could add more into this setup to get more variations if needed depending on hill sizes and such.

Hope that helps.

Offline mstacho

  • Supreme Robot
  • *****
  • Posts: 364
  • Helpful? 10
Re: Velocity feedback hill robot:(
« Reply #7 on: April 19, 2011, 07:19:17 AM »
That's a good idea, and I've seen it used a lot by beginners, but it'll chatter a lot around 25 rotations per minute.  Consider this chain of events:

speed = 24.  Increase power
NEXT TIME STEP
speed = 26.  Decrease power

and so on.  The reason we use feedback is to avoid that sort of "chattering" -- rapid switching between control modes.  As you said, you'd have to trouble shoot a bit to get everything right.  It is a good idea since it's so simple, and as long as you don't care about a chatty robot, it will work just fine once you get the parameters set right.

However, if the OP had access to the speed of wheel, then he could just implement a PID controller:

erSpeed = 25 rotations per min - speed of wheel
motorPower = PID(erSpeed,gains)

The increase in complexity is more than offset by the increase in accuracy.  But I recommend trying both!  It's a great learning experience to play around with control schemes.

MIKE
Current project: tactile sensing systems for multifingered robot hands

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: Velocity feedback hill robot:(
« Reply #8 on: April 19, 2011, 09:52:45 AM »
Hi,

PID = "Proportional, Integral, Derivative".
As I learned it, the "D" stands for Differential, not that it matters much (almost the same thing depending on interpretation).
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: Velocity feedback hill robot:(
« Reply #9 on: April 19, 2011, 10:04:22 AM »
Hi,

Basically your code would look a little like this:

If (speed of wheel) = 25 rotations per min
 then ( give 10% power to motor)
If( speed of wheel)< 25 rotations per min
 then ( give 20% power to motor)
If( speed of wheel)> 25 rotations per min
 then ( give 5% power to motor)
It would be a lot easier to just build a formula/function, where the PWM is set to a value based on wanted speed (Ws), actual speed (As), a constant (k) to get in range and perhaps an exponential (m) to make it an S-curve or rather a biological curve (for better response).

Eg. PWM = ((Ws-As)*k)^m * Sign + Ws
(where Sign = -1 or 1, depending on whether As is greater or lesser than Ws)

Well, enough software on the electronics board.
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

Offline Cristi_Neagu

  • Robot Overlord
  • ****
  • Posts: 165
  • Helpful? 5
Re: Velocity feedback hill robot:(
« Reply #10 on: April 19, 2011, 11:10:22 AM »
I do believe the question was "how to get velocity feedback?", and it was originally a hardware question.

As i see it, you could:
-use more powerful motors (may require a redesign, not the best idea, it will still move slower than on the flat, but it will move)
-put some sort of rotary encoders on the wheels (if you don't want an extremely accurate speed control, some simple handmade encoders as described somewhere on the main SoR site somewhere will suffice, after which you could apply the methods described above to control the speed)
-you could use a current sensor or a tilt sensor, but it would complicate things needlessly (even tough with the tilt sensor you could do something like: PWM_duty_cycle=flatground_duty_cycle*(1+sin(tilt)) )

Best solution would be installing simple encoders on the wheels, derive the current speed from the pulse frequency, and use some kind of feedback loop to adjust the PWM duty cycle to maintain a set speed.

Offline TheBadgerTopic starter

  • Jr. Member
  • **
  • Posts: 33
  • Helpful? 0
Re: Velocity feedback hill robot:(
« Reply #11 on: April 19, 2011, 12:08:23 PM »
yes the original question was hardware on how to get velocity feedback, at the minute I only have the line feedback from phototransistors.

I am getting a bit confused though as the wheels are constantly turning off and on to keep on the line so how would speed feedback work.

Also you mentioned encoders, Is there any cheap off the shelf ones someone could recommend?


Thanks again.

Offline rbtying

  • Supreme Robot
  • *****
  • Posts: 452
  • Helpful? 31
Re: Velocity feedback hill robot:(
« Reply #12 on: April 19, 2011, 12:16:47 PM »
Off the shelf means not cheap.  You're looking at maybe $10-$20/ea, most likely, but you'll need to tell us what motors/wheels you're using before we can give you any recommendations. 

In regards to the algorithm, what you would have is a two-tiered PID control system.  Each wheel would have a velocity PID controller with a setpoint, and those setpoints would be set by your line-following PID algorithm.  Thus, you could be assured that the wheels would rotate at the speed requested by the line-following PID algorithm, regardless of the slope of the hill, provided that the motors would be capable of scaling the hill. 

In code, it basically means that your line-following PID changes the setpoint of the velocity PID controllers, instead of the PWM.  In turn, the velocity PID controllers change the PWM in order to keep the motors running at the desired speed.

Offline TheBadgerTopic starter

  • Jr. Member
  • **
  • Posts: 33
  • Helpful? 0
Re: Velocity feedback hill robot:(
« Reply #13 on: April 20, 2011, 04:58:15 AM »
Okay thanks for the help

I have decided to go with motor encoders which I am making myself with an IR LED and phototransistor arrangement.

As you can probably tell I am not very intuitive when it comes to designing software so now I am trying to plan out the sequence for getting the speed.

If I used just a PIC instead of a counter IC which it states in the encoder tutorial, then I am guessing it will go something like this?

/CODE/

//interrupt generated by click from IR sensor detecting white section of encoder.
time_since_last_click = READ TIMER
speed = (wheel circumference/number of clicks) * time_since_last_click
time_since_last_click = 0;
START TIMER

end interrupt.

Now I am worried that these interrupts are going to be using up all my CPU power, say my wheel is turning at 100rpm and there are 10 black and white sections on my encoder,

thats a lot of interrupts, not to mention all the time it takes to do functions like start timer, read timer etc.

and then ive also got to be reading in sensor data from everything else and doing the PID.

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: Velocity feedback hill robot:(
« Reply #14 on: April 20, 2011, 07:54:29 AM »
Hi,

Now I am worried that these interrupts are going to be using up all my CPU power, say my wheel is turning at 100rpm and there are 10 black and white sections on my encoder,

thats a lot of interrupts, not to mention all the time it takes to do functions like start timer, read timer etc.
That's less than 17 int's/second, nothing to worry about really.
But you could always let a small controller handle this and just report back to the main controller.
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

Offline Kylepowers

  • Full Member
  • ***
  • Posts: 117
  • Helpful? 1
Re: Velocity feedback hill robot:(
« Reply #15 on: April 20, 2011, 12:15:51 PM »
What microcontroler are you using?

Offline TheBadgerTopic starter

  • Jr. Member
  • **
  • Posts: 33
  • Helpful? 0
Re: Velocity feedback hill robot:(
« Reply #16 on: April 20, 2011, 04:30:43 PM »
I am using a PIC18f4520,

Considering having the 2 encoders being fed into another PIC, I have a 28pin PIC knocking around a 2520 which is a bit of overkill, had some 8 pin PICs but can't find them.

Anyway yeah considering having the 2 encoders feeding into a 2520 and then that communicating with the main 18f4520 using SPI.

I think I prefer it this way as then I have an "encoder board" with a preprogrammed pic for future.

What do you guys think?

Offline Kylepowers

  • Full Member
  • ***
  • Posts: 117
  • Helpful? 1
Re: Velocity feedback hill robot:(
« Reply #17 on: April 20, 2011, 04:37:40 PM »
Do what you think is best. That setup sounds better than worrying about trying to sort the information out on one board.

Offline MikeK

  • Full Member
  • ***
  • Posts: 97
  • Helpful? 5
Re: Velocity feedback hill robot:(
« Reply #18 on: April 21, 2011, 05:53:51 AM »
That PIC is certainly capable of doing everything you need, and then some.  What speed clock are you using?

Offline MikeK

  • Full Member
  • ***
  • Posts: 97
  • Helpful? 5
Re: Velocity feedback hill robot:(
« Reply #19 on: April 21, 2011, 08:41:35 AM »
Are you using differential drive?  Could you do a simple discrete component current sense on the motor and then increase the speed of both wheels by some amount?

Offline TheBadgerTopic starter

  • Jr. Member
  • **
  • Posts: 33
  • Helpful? 0
Re: Velocity feedback hill robot:(
« Reply #20 on: April 23, 2011, 03:17:25 AM »
Hi Mike I am using a 10MHz crystal and I tried to do a current sense using an Agilent HCPL 7520, it worked fine when doing my tests on a power supply but when it came to plugging the thing into my H bridge, it wouldn't work. I think this was due to it taking its 0V from the H bridge.

It shows how to use the chip in its datasheet but it confused me loads, sharing supplies and isolation and floating supplies and whatnot. I just wanted to use it as a differential amplifier with isolation but the sharing of the 0V and Vin- just failed.


Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: Velocity feedback hill robot:(
« Reply #21 on: April 23, 2011, 04:50:53 AM »
[...] current sense using an Agilent HCPL 7520, it worked fine when doing my tests on a power supply but when it came to plugging the thing into my H bridge, it wouldn't work. I think this was due to it taking its 0V from the H bridge.

It shows how to use the chip in its datasheet but it confused me loads, sharing supplies and isolation and floating supplies and whatnot. I just wanted to use it as a differential amplifier with isolation but the sharing of the 0V and Vin- just failed.
Just place the current sense resistor from where the H-bridge is normally connected to ground - i.e. both emitters/sources connected together and then the resistor from there to ground.
You need to join the grounds of the bridge circuit and the logic anyway, just add the resistor in the bridge.
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

Offline TheBadgerTopic starter

  • Jr. Member
  • **
  • Posts: 33
  • Helpful? 0
Re: Velocity feedback hill robot:(
« Reply #22 on: April 23, 2011, 05:14:03 AM »
My bridge circuit is ran is totally isolated from the logic though, got optoisolators and a DC/DC converter to power the PIC.

Offline TheBadgerTopic starter

  • Jr. Member
  • **
  • Posts: 33
  • Helpful? 0
Re: Velocity feedback hill robot:(
« Reply #23 on: May 01, 2011, 01:23:41 PM »
Well I spent a long time making the encoders and sensor boards and whatnot and I have come to the conclusion that printer ink just isn't good enough for the job.

Too shiny and not black enough.

I think I will redesign with a slot encoder arrangement

Offline MikeK

  • Full Member
  • ***
  • Posts: 97
  • Helpful? 5
Re: Velocity feedback hill robot:(
« Reply #24 on: May 01, 2011, 07:12:56 PM »
Ink jet or laser?  I've heard complaints about ink jet.  I went over the black sections with a Sharpie and it works well.  What sensors are you using?  QRD1114 and QRB1134 work well at the correct distance.

Offline TheBadgerTopic starter

  • Jr. Member
  • **
  • Posts: 33
  • Helpful? 0
Re: Velocity feedback hill robot:(
« Reply #25 on: May 02, 2011, 12:06:53 PM »
inkjet and I was using a TCRT5000.

I went over it with a black marker but that seemed to make it worse, I'll bet its only certain inks

Offline MikeK

  • Full Member
  • ***
  • Posts: 97
  • Helpful? 5
Re: Velocity feedback hill robot:(
« Reply #26 on: May 02, 2011, 03:43:43 PM »
Go to the hobby store and get a bottle of Testors Flat Black.  Also make sure your sensor is the right distance from the encoder wheel, although it's range is better than others.

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: Velocity feedback hill robot:(
« Reply #27 on: May 02, 2011, 04:21:45 PM »
Hi,

And experiment with the angle as well as the resistors you use.
Even the most IR translucent ink will still have some absorption, so it should be possible to get it to see the black (or rather to not see the black).
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

 


Get Your Ad Here