go away spammer

Author Topic: PID is pretty complicated to me  (Read 7191 times)

0 Members and 1 Guest are viewing this topic.

Offline S. KarimTopic starter

  • Robot Overlord
  • ****
  • Posts: 155
  • Helpful? 0
PID is pretty complicated to me
« on: August 12, 2007, 11:13:31 AM »
Actuator_Output = Kp*P + Ki*I + Kd*D

If I want to drive a sraight line, as straight as possible with my robot fixing errors when it veers off a tiny bit, whats the code I have to whip up to control left and right wheels?

Not sure I understand the PID equation at all. Could someone give some pseudo-code and examples of how to implement this with 2 motors trying to equalize themselves?

Offline Steve Joblin

  • Supreme Robot
  • *****
  • Posts: 405
  • Helpful? 2
    • Roebotz
Re: PID is pretty complicated to me
« Reply #1 on: August 12, 2007, 11:54:06 AM »
There is a very good tutorial on PID on the Parallax forums under the "Stamps in Class" section.  I am not quite sure that PID algorithm is necessary for traveling a straight line... I think that wheel encoders with a simple counter is all that is required.

Offline S. KarimTopic starter

  • Robot Overlord
  • ****
  • Posts: 155
  • Helpful? 0
Re: PID is pretty complicated to me
« Reply #2 on: August 12, 2007, 12:02:50 PM »
im not allowed to use encoders for now. what is PID used for then??

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: PID is pretty complicated to me
« Reply #3 on: August 12, 2007, 07:38:33 PM »
What sensors are you using to know if you are going straight or not? How big/heavy is your robot?

For small slow robots, this is how I would do it:

Left_wheel_speed = tweak_constant * (current heading - location of straight line) + another_constant
Right_wheel_speed = - tweak_constant * (current heading - location of straight line) + another_constant

This is a simple PD controller that will work after a few experiments trying different constants.

Offline JesseWelling

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 707
  • Helpful? 0
  • Only You Can Build A Robot!
Re: PID is pretty complicated to me
« Reply #4 on: August 13, 2007, 06:30:54 AM »
This article helped me understand PID a bunch...
http://www.embedded.com/2000/0010/0010feat3.htm


Offline S. KarimTopic starter

  • Robot Overlord
  • ****
  • Posts: 155
  • Helpful? 0
Re: PID is pretty complicated to me
« Reply #5 on: August 13, 2007, 11:10:32 AM »
What sensors are you using to know if you are going straight or not? How big/heavy is your robot?

For small slow robots, this is how I would do it:

Left_wheel_speed = tweak_constant * (current heading - location of straight line) + another_constant
Right_wheel_speed = - tweak_constant * (current heading - location of straight line) + another_constant

This is a simple PD controller that will work after a few experiments trying different constants.
Okay I understand PID needs some sort of input to determine how it's doing. What kind of input are we talking about here? Voltage to a motor? Motor position? My controller has BACK-EMF if it helps.

Also, what kinds of sensors are good for determining whether im going straight or not? The robot will be about 2-3 pounds.

I'm asking all this because im trying to figure out a good way to master odometry. I have a robot that needs to travel an entire board full of obstacles without making any mistakes so its kind of hard.

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: PID is pretty complicated to me
« Reply #6 on: August 13, 2007, 01:34:54 PM »
Quote
Okay I understand PID needs some sort of input to determine how it's doing. What kind of input are we talking about here? Voltage to a motor? Motor position? My controller has BACK-EMF if it helps.
It could be anything . . . you just need a sensor to detect straight line motion. See my next point . . .

Quote
what kinds of sensors are good for determining whether im going straight or not?
gryo, encoders, digital compass, video camera, photoresistors, GPS, IMU . . . it really depends on the terrain, accuracy you require, cost, etc. If it was perfectly flat terrain, your robot doesnt need to travel long distances, and you dont care about gradual drift, I'd go with the gyro for simplicity.

Quote
I have a robot that needs to travel an entire board full of obstacles without making any mistakes so its kind of hard.
How big is this board? I think gryos and/or encoders are your best way to go. If the obstacles have known locations and shapes, you can use a Sharp IR to realign your robot to the obstacle to prevent sensor drift . . .

Offline S. KarimTopic starter

  • Robot Overlord
  • ****
  • Posts: 155
  • Helpful? 0
Re: PID is pretty complicated to me
« Reply #7 on: August 13, 2007, 01:43:20 PM »
ok well the only one i have from those is a small CMUCam.

heres my situation: a 4'x4' board that the robot has to travel in to collect colored items and avoid obstacles and drop items in destinations.

i have touch switches, IR sensors, a sonar sensor, camera and light sensors.

could any of these be used for keeping the robot straight?

Offline Ro-Bot-X

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,431
  • Helpful? 25
  • Store: RoBotXDesigns.ca
    • Ro-Bot-X Designs
Re: PID is pretty complicated to me
« Reply #8 on: August 13, 2007, 02:05:09 PM »
You can build a rotation sensor using a light sensor or a touch sensor and use PID...
Check out the uBotino robot controller!

Offline S. KarimTopic starter

  • Robot Overlord
  • ****
  • Posts: 155
  • Helpful? 0
Re: PID is pretty complicated to me
« Reply #9 on: August 13, 2007, 02:33:29 PM »
You can build a rotation sensor using a light sensor or a touch sensor and use PID...
a touch sensor would only work in 1 direction, that wont work when the motor spins backwards, itll try to rip the switch back.

forget going straight, what are the best methods for making sure the robot does what it's supposed to consistently as far as getting to places, grabbing things and dropping them in places? especially against opponents..

Offline Ro-Bot-X

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,431
  • Helpful? 25
  • Store: RoBotXDesigns.ca
    • Ro-Bot-X Designs
Re: PID is pretty complicated to me
« Reply #10 on: August 14, 2007, 02:42:54 AM »
a touch sensor would only work in 1 direction, that wont work when the motor spins backwards, itll try to rip the switch back.
I have used Lego touch sensors and (depending on the design, of course) it works both ways. I did not need quadrature, since I allready knew the direction the motor was moving.

Quote
forget going straight, what are the best methods for making sure the robot does what it's supposed to consistently as far as getting to places, grabbing things and dropping them in places? especially against opponents..

Not an easy task. You need encoders (simple or complex, doesn't matter much) and you need a scanning distance sensor to detect both objects and other robots.
With Lego RCX I would use Sensor port 1 and 3 for encoders (using touch sensors) and sensor port 2 for a distance sensor (custom sensor IR or Ultrasonic, mounted on a scanning device) and a third encoder sensor. I would use a motor for both grab/lift and scanning and 2 motors for driving. If you also need to see colors, I don't think it would be easy, unless you use a active sensor multiplexer.
Using the NXT it's a lot easier, since the motors have built-in encoders and the kit has a ultrasonic sensor. This setup uses only one sensor port, so you can use the light sensor to detect colors and the touch sensor for bumpers.

OK, now for the logic, I would have to know the layout of the board and the tasks that need to be done, but basicaly, the robot eighter needs to know the distances it needs to travel, angle of turns, the locations of the objects, etc. or it needs to find openings to find it's way around to find objects, wich means mapping is necesary. Allways it needs a routine to avoid other robots and get back on track corectly.
Check out the uBotino robot controller!

Offline S. KarimTopic starter

  • Robot Overlord
  • ****
  • Posts: 155
  • Helpful? 0
Re: PID is pretty complicated to me
« Reply #11 on: August 14, 2007, 11:27:50 AM »
well dont worry about ports, i have 8 digital and 8 analog ports, 4 motor and 4 servo ports.

difficult task indeed.

Offline DomoArigato

  • Full Member
  • ***
  • Posts: 54
  • Helpful? 1
Re: PID is pretty complicated to me
« Reply #12 on: August 14, 2007, 12:40:17 PM »
You can't use encoders, but could you use an old mouse?  It's basically an encoder, or maybe even an optical mouse, if your on a nice surface.  You could use the range finders to measure movement if your in a a maze and they can see the walls your moving toward or away.  Is it possible to program the maze into it, and all it has to do is localize?  That may be the easiest.

Offline S. KarimTopic starter

  • Robot Overlord
  • ****
  • Posts: 155
  • Helpful? 0
Re: PID is pretty complicated to me
« Reply #13 on: August 14, 2007, 01:35:11 PM »
there is no maze.

its a flat board with objects on it the robot has to pick up and drop in destinations. the robot cant be fully automated most of the time.

Offline S. KarimTopic starter

  • Robot Overlord
  • ****
  • Posts: 155
  • Helpful? 0
Re: PID is pretty complicated to me
« Reply #14 on: August 14, 2007, 01:57:55 PM »
ok heres a picture of the board.



right-click, view image to see the whole thing. everything is labelled. a maximum of 2 robots can fit in the starting box, which is 15" by 15" and has a imaginary height limit of 12".

Goals:

-get the house shields (umbrellas) on top of the houses.
-get the ocean balls (blue) into compost bins.
-get the pineapple plants (yellow balls) into yellow compost bin.
-get the leaves (green balls) into green compost bin.
-at 45seconds the volcano erupts 7 orange balls (lava) onto each side of the field, each counting as -1 point. you have to put as much as lava off the board or into the ocean as you can to negate the effect.

teams compete against other teams, end to end of this 8'x4' board. the half point is at the half of the board.

rules:

-90 seconds to complete your strategy for most points
-cant pass to other side until 45 seconds
-green balls are 1 point each, yellow balls are 3
-ocean balls are 5 points each
-umbrellas in house is 5 points each
-house returned back to starting back is 3 points each.
-lava on your side is -1 point each.

-sensors we have: nooby camera, bumper switches, light sensors, IR distance sensors, sonar US rangefinders, Infrared "Top Hat" Reflectance Sensor.

so, if you guys were playing this game (its called BOTBALL), what would your strategy be? how would you play? what kinds of robots would you make and what sensors would you use? how would you make use of these given sensors for best possible gameplay? can someone explain mapping?
« Last Edit: August 14, 2007, 01:59:40 PM by S. Karim »

Offline Ro-Bot-X

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,431
  • Helpful? 25
  • Store: RoBotXDesigns.ca
    • Ro-Bot-X Designs
Re: PID is pretty complicated to me
« Reply #15 on: August 14, 2007, 03:12:48 PM »
It looks like to get the most points you need to get the umbrellas on the houses and the blue balls in the composts first, then get the yellow balls and green balls.

The best way to do it is to split the work between 2 robots, built a little different. One robot to handle the small yellow and green balls and one robot to handle the umbrellas and big blue balls.

To know wich sensor is best for what purpose I need to know how many sensors and what type you have. I understand you have light sensors, what type, LDR or Lego style? Can they detect colors? What type of camera is that nooby camera? How many cameras do you have? What is that reflectance sensor?

The servos are modified for continuous rotation or not? If not, can they be modified? This is important, because you can use servo pulses to determine the distance traveled.

Here is what I would do:
1. The Big robot with a large gripper to be able to handle the big balls. The arm has to be able to rise the balls over the compost. The gripper can be something like a double scoop, imagine grabbing wather from a pond in your hands put close together... With this design you can get the balls and the umbrellas. You need some method of distance traveled measurement, so you can get one umbrella and go to a house to shade it and return to base to get a second umbrella, etc. For this you need to measure distance and turns. To get the blue balls is easier, you know their location, just get streight to the edge, get a ball, turn and head for the closest compost bin, return, get the second ball (or get them both in the first try) and head back to the second bin. Maybe get the umbrellas after the blue balls.

2. The Small robot has a different arm. Just a sticky double foam tape on a popsicle stick... When you find the pile, hit it with the stick (in a downward motion), the ball will adhere to the stick, lift it up and take it to the bin, lower it then pull the stick over the edge (keeping it horizontal), the ball will remain inside of the bin. Turn, get another ball... and so on. You will need 2 distance sensors mounted one above the other on the same vertical axis. The lower will detect the balls, the upper will detect the bins. Use a color sensor to detect the ball when you have it lifted up on the stick so you know wich bin to put it into. Distance measurement is not really necessary, but it helps. The position of bins is symetrical so if you face both bins, you know that the yellow bin is on your left. The balls will not stay in place, so don't worry if the robot spreads them around.

Robot avoiding strategy. Make sure both robots can detect the other. If they are in a colision course, one allways stops and the other allways passes by. The robot that needs to track it's traveled distance has to stop so it doesn't loose count.

Don't worry about the lava verry much, but if you do, take it out with the Small robot.
Check out the uBotino robot controller!

Offline S. KarimTopic starter

  • Robot Overlord
  • ****
  • Posts: 155
  • Helpful? 0
Re: PID is pretty complicated to me
« Reply #16 on: August 14, 2007, 04:00:52 PM »
It looks like to get the most points you need to get the umbrellas on the houses and the blue balls in the composts first, then get the yellow balls and green balls.
Actually, the ocean ball is so big that if you put it into the composts first, anything on top of that will overflow. Therefore, you have to put the yellow/green balls first and put the ocean ball on top of them.

Quote
The best way to do it is to split the work between 2 robots, built a little different. One robot to handle the small yellow and green balls and one robot to handle the umbrellas and big blue balls.
Exactly what we did this year.

Quote
To know wich sensor is best for what purpose I need to know how many sensors and what type you have. I understand you have light sensors, what type, LDR or Lego style? Can they detect colors? What type of camera is that nooby camera? How many cameras do you have? What is that reflectance sensor?
The only thing of legos we have is the parts. No electronics (servos/sensors) are lego style. Every piece of electronic we have are hobby electronics, not from legos. The light sensors are only allowed to be used for one purpose...to start the robot once the lamps at the end of the boards turn on automatically (sorry, i shouldnt have mentioned it at all). We have 2 camera, each for one robot. The reflectance sensor measures distance, using reflected light.

Quote
The servos are modified for continuous rotation or not? If not, can they be modified? This is important, because you can use servo pulses to determine the distance traveled.
No, they cannot be modified. We have 4 motors and 4 servos. We also have 2 ferrit bead motors that are weaker but faster. Total 6 motors, 4 servos that must be split among 2 robots.

Quote
Here is what I would do:
1. The Big robot with a large gripper to be able to handle the big balls. The arm has to be able to rise the balls over the compost. The gripper can be something like a double scoop, imagine grabbing wather from a pond in your hands put close together... With this design you can get the balls and the umbrellas. You need some method of distance traveled measurement, so you can get one umbrella and go to a house to shade it and return to base to get a second umbrella, etc. For this you need to measure distance and turns. To get the blue balls is easier, you know their location, just get streight to the edge, get a ball, turn and head for the closest compost bin, return, get the second ball (or get them both in the first try) and head back to the second bin. Maybe get the umbrellas after the blue balls.
Another thing i forget to mention. All measurements of the board are given to us, like how far one thing is from another. Also, the umbrellas can be started attached to your robot, so you dont have to pick them up and keep coming for them. Your idea of 2 balls at once is what one team did, they ended up being the most successful at it too.

Quote
Don't worry about the lava verry much, but if you do, take it out with the Small robot.
Yeah, what I did was I made a robot grab and store green balls in a cart, then the cart can be lifted and opened to dump everything in the green compost bin. I had a camera in the front of the robot, but I never put it to use. If I had used the camera, I couldve made the robot perfectly centered to the balls instead of guessing and being off every time. Here's a picture of pickup and dump:





I'm a fool, if I had realized I couldve used the camera for function instead of looks...this robot couldve done so much. It couldve used it to grab a blue ball as well, and use it to line up perfectly centered with the small foam balls and also used the color construction paper around the compost bins to get it to line up perfectly. because we programmed in the routine of movement it had to do, and it had no sensors...it wasnt a very smart robot. yet, it was just a machine :-[

Offline Ro-Bot-X

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,431
  • Helpful? 25
  • Store: RoBotXDesigns.ca
    • Ro-Bot-X Designs
Re: PID is pretty complicated to me
« Reply #17 on: August 15, 2007, 12:03:50 AM »
Looks like the balls were sponge type, you could have used velcro to grab them :)

Or build a robot that would grab all balls, sort them and dump them in the proper bins... And have the umbrellas mounted on a arm, something like a bullets clip, that would release them one at the time...
« Last Edit: August 15, 2007, 12:05:57 AM by Ro-Bot-X »
Check out the uBotino robot controller!

Offline S. KarimTopic starter

  • Robot Overlord
  • ****
  • Posts: 155
  • Helpful? 0
Re: PID is pretty complicated to me
« Reply #18 on: August 15, 2007, 11:15:32 AM »
Looks like the balls were sponge type, you could have used velcro to grab them :)
No no, simply grabbing them with grippers are enough. We're not allowed to bring in extra materials besides the legos and sensors given in the kit.

 


Get Your Ad Here