Author Topic: Arduino Mega + Motorcontroller + IR Sensors = Over compensation?  (Read 4543 times)

0 Members and 1 Guest are viewing this topic.

Offline lowglowTopic starter

  • Beginner
  • *
  • Posts: 4
  • Helpful? 0
Arduino Mega + Motorcontroller + IR Sensors = Over compensation?
« on: February 20, 2010, 03:57:45 PM »
The MCU is following a wall, polling two IR sensors, and changing the PWM on a dual h-bridge v2.0 by lynxmotion.

When a threshold is met, it will soft turn left or right to re-align the sensors. But it never goes straight, or compensates just a little, always overcompensates, so it serpentines along the wall.

Any suggestions?

Offline madsci1016

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,450
  • Helpful? 43
    • Personal Website
Re: Arduino Mega + Motorcontroller + IR Sensors = Over compensation?
« Reply #1 on: February 20, 2010, 04:04:38 PM »
You need a PID controller, or at least a PD controller, to get rid of the oscillations. I think there's a library somewhere in the Arduino website for a PID controller.

Once you add it to your code, it's a matter of tuning the gains (KP, KD, etc) by way of experimentation, until you find values that drive your robot straight.

http://en.wikipedia.org/wiki/PID_controller


Offline lowglowTopic starter

  • Beginner
  • *
  • Posts: 4
  • Helpful? 0
Re: Arduino Mega + Motorcontroller + IR Sensors = Over compensation?
« Reply #2 on: February 20, 2010, 04:08:26 PM »
You need a PID controller, or at least a PD controller, to get rid of the oscillations. I think there's a library somewhere in the Arduino website for a PID controller.

Once you add it to your code, it's a matter of tuning the gains (KP, KD, etc) by way of experimentation, until you find values that drive your robot straight.

http://en.wikipedia.org/wiki/PID_controller

Awesome. Another professor was talking about how it was a control system, but I didn't understand. Would you mind explaining a little bit more? I went to the wiki page, but quickly got lost seeing the relationship to this. thanks :)

Offline madsci1016

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,450
  • Helpful? 43
    • Personal Website
Re: Arduino Mega + Motorcontroller + IR Sensors = Over compensation?
« Reply #3 on: February 20, 2010, 04:28:46 PM »
Lol, I was just thinking that i was a bit to vague, and went looking for a better tutorial on PID controllers, but couldn't find one. Might have to be the next thing Tutorial i write for the world.

I'll try to give some insight to you, without spending all day typing. I'm also going to only explain a PD controller, as they are easier to tune and implement.

For your application, the 'Goal' of the PD controller is the distance you want to be away from the wall, let's say you are trying to stay 10" away from the wall. The 'Error' is the amount away you are from that goal. So if you were actually 9", that's an error of -1, or if you were 12" that's an error of +2. So it's simple to calculate your error.

Once you have this error, you feed it into the PD equations.

P for proportional error = Error
D for derivative error = "(This Error - Last Error) / (Time since last error was calculated)"

Then, the output of the PD controller = (P * KP) + (D * KD)

**Edit:  KP and KD are the controller gains. These are numbers you change and experiment with to 'tune' the controller. **

You use the output of this to feed into your command to your motor controller. For your case, if your robot is a skid steer, I would use the output of the controller as a "difference" in power sent to you wheels. So if they are usually at 50% power (PWM duty cycle), and your PD controller outputs a -10, you would send 40% power to one wheel, and 60 % power to another.

Make sure you get all the signs (+/-) straight, so if too close to the wall would be a negative error, and output a negative PD output, that the equations used to find the difference in wheel power would have the robot turn away from the wall.

Make sense? Sorry if i lost you.

BTW, this doesn't happen to be a robot for the IEEE competition, is it?
« Last Edit: February 20, 2010, 04:30:28 PM by madsci1016 »

Offline madsci1016

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,450
  • Helpful? 43
    • Personal Website
Re: Arduino Mega + Motorcontroller + IR Sensors = Over compensation?
« Reply #4 on: February 20, 2010, 04:40:47 PM »
O, and to tune, or set KP and KD

Start with KP = 1 and KD = 0. Change KP up or down until the robot isn't over or under correcting too fast or too slow. It will oscillate, but that's not what KP fixes.

Then, try changing KD to fix the oscillations. Gain numbers can be small, like .05 or big like 5. It's all based on how your particular system (your robot) behaves.

Offline RobotBits

  • Jr. Member
  • **
  • Posts: 18
  • Helpful? 0
    • Robot Bits - Robot Kits & Components
Re: Arduino Mega + Motorcontroller + IR Sensors = Over compensation?
« Reply #5 on: February 20, 2010, 05:06:02 PM »
The excellent Arduino PID library can be found at: http://www.arduino.cc/playground/Code/PIDLibrary

Have fun ...

RobotBits - Robot kits and components for fun and learning!
http://www.RobotBits.co.uk

Offline lowglowTopic starter

  • Beginner
  • *
  • Posts: 4
  • Helpful? 0
Re: Arduino Mega + Motorcontroller + IR Sensors = Over compensation?
« Reply #6 on: February 20, 2010, 05:07:34 PM »
BTW, this doesn't happen to be a robot for the IEEE competition, is it?

Actually, it is, how did you know? :D

Offline lowglowTopic starter

  • Beginner
  • *
  • Posts: 4
  • Helpful? 0
Re: Arduino Mega + Motorcontroller + IR Sensors = Over compensation?
« Reply #7 on: February 20, 2010, 05:08:43 PM »
The excellent Arduino PID library can be found at: http://www.arduino.cc/playground/Code/PIDLibrary

Have fun ...

Sweet, thanks :) It's just a matter of fitting it in to our code now.

Offline madsci1016

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,450
  • Helpful? 43
    • Personal Website
Re: Arduino Mega + Motorcontroller + IR Sensors = Over compensation?
« Reply #8 on: February 20, 2010, 06:55:58 PM »
Actually, it is, how did you know? :D

Gut feeling. Talked to a professor from my old college (Florida State) and he told me a lot of groups where navigating off the walls around the course. I was at SouthEast Con last year and was there when they pitched the idea. You got it lucky, the original plan was for only one 'basking light', now i hear the whole course is well light.

How are you handling the raised (ramp) obstacle? The ramp goes higher than the walls, so you lose contact with it.

FYI, this was my robot for last years competition. It would have won, had it gone, but that's a long story.
http://www.billporter.info/?p=26

 

SMF spam blocked by CleanTalk