Go Down

Topic: Pendulum Balance Robot (Read 2 times) previous topic - next topic

Yewzorz

Mar 13, 2013, 01:25 pm Last Edit: Mar 13, 2013, 01:44 pm by AWOL Reason: 1
Hey guys, Its my first post,  so be nice  :)

For a project I am supposed to create an Inverted pendulum balancing robot, controlled by PID via arduino.

I am using a Mega2560 with the motor shield, and an optical encoder, however I am struggling a little with the code, I dont think I'm too far away, but unfortunately when uploading, nothing happens. I was wondering if anyone could point me where the problem may be? Most of it is assembly of Library codes (Note: I have the encocer, stepper and PID libraries installed, so its not that)

Code: [Select]
#include <PID_v1.h>
#include <Encoder.h>
#include <Stepper.h>
const int pwmA = 3;
const int pwmB = 11;
const int brakeA = 9;
const int brakeB = 8;
const int dirA = 12;
const int dirB = 13;
const int STEPS = 200;
const int m = 0;
const int newPosition = 0;
Stepper myStepper(STEPS, dirA, dirB);
Encoder myEnc(20, 21);
PID myPID(newPosition, m, 0, 1, 20, 100, 1);
void setup() {
 myStepper.setSpeed(90);
 Serial.begin(9600);
 Serial.println("Basic Encoder Test:");
}

long oldPosition  = -999;

void loop() {
 myEnc.write(-180);
 long newPosition = myEnc.read();
 if (newPosition != oldPosition) {
   oldPosition = newPosition;
   Serial.println(newPosition);

 }
 myPID.Compute();
 myStepper.step(m);
 Serial.println(m);
 delay (1);

}


Currently when the code is ran,  nothig happens, I have tested the stepper motor components in another sketch and then work,  but even when assigning a number for the step (say 200) in this sketch,  the stepper does not move.

Since a picture speaks a thousand words, I have included one below



Thanks for your help, Yew


Moderator edit: Quote tags swapped for code tags

HazardsMind

Nothing happens at all? What about the serial monitor, does that at least give you "Basic Encoder Test:" ?
Do you ever get a print out for Serial.println(newPosition) ?
When does "m" ever change?
Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

JimboZA

Quote
Currently when the code is ran,  nothig happens


Do you mean that literally?- not even the serial write from setup()?

Edit.... seems HM and I on the same track here...
Roy from ITCrowd: Have you tried turning it off an on again?
I'm on LinkedIn: http://www.linkedin.com/in/jimbrownza

Yewzorz


Nothing happens at all? What about the serial monitor, does that at least give you "Basic Encoder Test:" ?
Do you ever get a print out for Serial.println(newPosition) ?
When does "m" ever change?


by 'nothing happens'  I mean there is no movement from the motor, and serial.println Gives a page of 0's, I'm unsure how to measure m, however. (as I'm still a beginner to arduino. :D

JimboZA

Quote
Gives a page of 0's


It will, it never changes in that code

Quote
I'm unsure how to measure m


What is m in the first place?
Roy from ITCrowd: Have you tried turning it off an on again?
I'm on LinkedIn: http://www.linkedin.com/in/jimbrownza

Go Up