Society of Robots - Robot Forum

Software => Software => Topic started by: gathem on May 13, 2012, 01:47:50 AM

Title: DC motors and balancing robots
Post by: gathem on May 13, 2012, 01:47:50 AM
Hi everyone,
Ive been lurking for a while but this is my first post.

Ive built myself a nice balancing robot which almost works...
The problem I am having is with the fricking DC motors. I can't seem to get fine grain control over them.

The goal:
I want to use DC motors to control my balancing robot, and allow it to be pushed and still balance itself.

The details:
I am using an arduino uno
I am using an arduino motor shield to power them
I wrote the code from scratch, and the balancing part, and PID are working at acceptable levels.

I have a whole box full of different DC motors, speed controllers, servos, continuous rotation servos, etc. and have tested all of them.

Continuous rotation servos work fine, but the robot will not be able to be pushed and remain balanced (pushing could be done if you pushed hard enough but thats bad for servo gears)

The best luck I have had with DC motors is geared 6.2:1 ratio 5v (2A max) motors, but its not good enough, I cant get the motors to take movement commands quick enough, or even get consistant distances when I pulse the same voltage to them multiple times

Code: [Select]
void drive()
{
  // If the PID returns negative move backwards, if the PID is positive move forwards
  digitalWrite(dir_a, pidVal < 0 ? LOW : HIGH);
  digitalWrite(dir_b, pidVal < 0 ? LOW : HIGH);

  // If the PID returns anything between positive or negative 300 the robot is for the most part in perfect balancing state
  if (pidVal > 300 || pidVal < -300) {
    /**
     * 255 is full speed
     * 40-42 is the minimum speed I can get the motors to start from 0 speed
     * 28 is the minimum it will slow down to even if it starts at high speeds and then lowers
     */
    analogWrite(pwm_a, 200); //After I can get the motors to be controlled more precisely the PID will specify the delay (or so the theory goes)
    analogWrite(pwm_b, 200);
    delay(14);
    analogWrite(pwm_a, 0);
    analogWrite(pwm_b, 0);
  }
}

I have been playing with different pwm voltages, as well as delays but I am really unhappy with the results. The motors movements are so jerky that they cause it to fall out of balance.

If I cannot precisely control how far the wheels spin when a pulse is applied (or at the very least prevent the motors from jerking so much), I do not see how I am going to get this bot to balance.

I am also worried that if I get a higher gear ratio that I wont be able to achieve the "pushing the robot" affect.

I know there are some robotics experts on here who know how to precisely control a balancing bot/segway bot.

It doesnt seem like segways/other balancing bots use stepper motors (and I would prefer not to, as again I am afraid of not being able to push it)

Update: I took an indepth look at the arduRoller http://www.flickr.com/photos/fasaxc/5944650602/#secretb52128ea53 (http://www.flickr.com/photos/fasaxc/5944650602/#secretb52128ea53) and it seems to be using a 24:1 gear ratio.
I am going try putting some mondo wheels (currently I have 2" wheels so the theory goes if I up them to 8" wheels I should have the equivilent of a 24:1 ratio pushing 2" wheels) (any thoughts on this tactic?
It also looks like the gear box I have could be easily altered to support 12:1 ratio (plus 4" wheels).
Do any experts know if this will work, and if so will I completely loose the ability to push the robot or will it be easier? I could also find out that this will draw more than 2A which will max out the arduino motor shield (although with a balancer robot, its just balancing, not ever moving at full speeds)
Title: Re: DC motors and balancing robots
Post by: mstacho on May 14, 2012, 07:00:30 AM
What is the sensor you're using to determine if you're off balance?   Shouldn't your code just work on the error between the sensor value and where you want to be (ie: 0 degrees pitch, or whatever you're calling it?)   If so...then you should just toss the PID output to the motors and as long as they have enough torque, you'll be able to control it? have I missed something?

MIKE
Title: Re: DC motors and balancing robots
Post by: gathem on May 14, 2012, 12:31:21 PM
I'm using a Ping ultrasonic sensor to measure the distance from the ground.

Your understanding is how the code is supposed to work. The problem is with the motors.
if I do:
Code: [Select]
analogWrite(pwm_a, HIGH);
delay(1000);

each time the above runs the motors spin a different amount (degrees pitch).
Moving the motors is more of a crap shoot than actual control.
Everytime I "drive" the motors it basically can move in the desired direction some amount between ~1-8 degrees.
The PID output looks great. I think if I had better control over the motors it would work fine.

Title: Re: DC motors and balancing robots
Post by: mstacho on May 14, 2012, 12:36:31 PM
Yes...I am not sure that I understand how your PWM function works...why are you changing the delay?  You should do:

analog_write(PWM_A, PID_OUTPUT_VALUE);

(where PID_OUTPUT_VALUE is capped to be within 0 and 100, and where if you need to go negative you have some direction pin that changes for your motor controller).

Then there should not be a delay at all.  Am I misunderstanding?
Title: Re: DC motors and balancing robots
Post by: gathem on May 14, 2012, 02:24:19 PM
I understand what your saying mstacho, and I very much appreciate you taking the time to understand my problem.
I agree with how you recommend it be implemented but the code is not the problem. That was simply code for testing control over the motors.

I think I know what my problem is.
I took a high RPM motor, and assumed 6:1 gear ratio was sufficient. It is not. I need to get down to ~150-300 rpm not the 1000+ RPM it currently has.

I need the switch in 20-50:1 ratio geared motors. It was one of the design areas I overlooked.

Thanks for the help.
Title: Re: DC motors and balancing robots
Post by: jkerns on May 14, 2012, 06:27:44 PM
FWIW...

If you look at the hightechnics web site they have the code for a Lego based version (click on my video chanel for a quick video and links). The Lego motors have feedback built in - I don't know how well it would work without the wheel rotation feedback, but your posts suggest that it is likely to be a problem.

If I am reading your code snippet correctly, you are updating the commanded wheel speed only once per second? That seems like a long time.
Title: Re: DC motors and balancing robots
Post by: Wesley888 on May 23, 2012, 12:59:31 PM
I think using a traditional motor is simply just not precise enough, well, not easily, to get it to balance.  Ever consider using a stepping motor or the motor that people use for RC?