I just got an Arduino Uno to use on my robot project. I've been using a BASIC stamp for about 2 years and finally decided to make the switch, however, I dont know the first thing about C++, and i need to have a working robot by the end of the month for a competition. It needs to be able to interface with a BASIC Stamp powered controller with RF transceivers, and drive 4 Jaguar motor controllers through PWM (so they behave like a servo). Can anyone help???
I'd start here http://www.cplusplus.com/doc/tutorial/
Then http://arduino.cc/en/Reference/HomePage
If the Jaguar controllers, that you didn't post a link to, can be driven as servos, then Servo - Arduino Reference will help too.
Heres a link to the jaguars: https://estore.ti.com/MDL-BDC24-Stellaris-Brushed-DC-Motor-Control-Module-with-CAN-MDL-BDC24-P1914.aspx
Yoiks, $100 motor controllers? Looking at the 'getting started' guide, you should be fine driving them with the servo library.
Which servo library?
The servo library
The one I linked to earlier. It's supplied with the IDE.
So under the example code, and the servo tab, is it the knob or sweep example code?
So under the example code, and the servo tab, is it the knob or sweep example code?
Yes. Try them both, and see what happens with each of them. Perhaps you'll actually learn something.
Well i dont actually have an Arduino yet. One of my friends is giving me his soon, but ill try it then
Does someone know whats wrong with the code here??
Drivetrain.ino (1.26 KB)
BurtonCustomX:
Does someone know whats wrong with the code here??
Here's the code (folks here prefer you to put code inline, annotated with "code" tags):
// Controlling a servo position using a potentiometer (variable resistor)
// by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>
#include <Servo.h>
Servo Jaguar1; // create servo object to control a servo
int potpin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
void setup()
{
Jaguar1.attach(1); // attaches the servo on pin 9 to the servo object
}
void loop()
{
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
Jaguar1.write(val); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there
}
Servo Jaguar2;
{
Jaguar2.attach(2);
}
{
val = analogRead(potpin);
val = map(val, 0, 1023, 0, 179);
Jaguar2.write(val);
delay(15);
}
Servo Jaguar3;
{
Jaguar3.attach(3);
}
{
val = analogRead(potpin);
val = map(val, 0, 1023, 0, 179);
Jaguar3.write(val);
delay(15);
}
Servo Jaguar4;
{
Jaguar4.attach(4);
}
{
val = analogRead(potpin);
val = map(val, 0, 1023, 0, 179);
Jaguar4.write(val);
delay(15);
}
And here's the result of a compilation:
Drivetrain:24: error: expected unqualified-id before '{' token
Drivetrain:29: error: expected unqualified-id before '{' token
Drivetrain:39: error: expected unqualified-id before '{' token
Drivetrain:44: error: expected unqualified-id before '{' token
Drivetrain:53: error: expected unqualified-id before '{' token
Drivetrain:58: error: expected unqualified-id before '{' token
You should fix those errors -- the compiler is telling that this is not valid C code. I think you want Jaguar2 to be a function (it currently is not, but rather a declaration of a "Servo") but I don't see how it is called from either loop() or setup().
Well its my first time trying C. So i really dont know what im fixing....
This is correct:
Servo Jaguar1; // create servo object to control a servo
...
void setup()
{
Jaguar1.attach(1); // attaches the servo on pin 9 to the servo object
}
This is not correct (Notice how you have the attach function in your setup() rather than floating out there in some random block of code):
Servo Jaguar2;
{
Jaguar2.attach(2);
}
When i had the Void setup () in there, it didnt like the fact that it was already defined on Jaguar1
BurtonCustomX:
When i had the Void setup () in there, it didnt like the fact that it was already defined on Jaguar1
I don't know what this means. Post the code you used and the error message you were getting.
This is what I used originally.
[quote]
#include <[color=#CC6600]Servo[/color].h>
[color=#CC6600]Servo[/color] Jaguar1;
[color=#CC6600]int[/color] potpin = 0;
[color=#CC6600]int[/color] val;
[color=#CC6600]void[/color] [color=#CC6600][b]setup[/b][/color]()
{
Jaguar1.[color=#CC6600]attach[/color](1);
}
[color=#CC6600]void[/color] [color=#CC6600][b]loop[/b][/color]()
{
val = [color=#CC6600]analogRead[/color](potpin);
val = [color=#CC6600]map[/color](val, 1, 60, 0, 179);
Jaguar1.[color=#CC6600]write[/color](val);
[color=#CC6600]delay[/color](15);
}
[color=#CC6600]Servo[/color] Jaguar2;
[color=#CC6600]void[/color] [color=#CC6600][b]setup[/b][/color]()
{
Jaguar2.[color=#CC6600]attach[/color](2);
}
{
val = [color=#CC6600]analogRead[/color](potpin);
val = [color=#CC6600]map[/color](val, 1, 60, 0, 179);
Jaguar2.[color=#CC6600]write[/color](val);
[color=#CC6600]delay[/color](15);
}
[color=#CC6600]Servo[/color] Jaguar3;
[color=#CC6600]void[/color] [color=#CC6600][b]setup[/b][/color]()
{
Jaguar3.[color=#CC6600]attach[/color](3);
}
{
val = [color=#CC6600]analogRead[/color](potpin);
val = [color=#CC6600]map[/color](val, 1, 60, 0, 179);
Jaguar3.[color=#CC6600]write[/color](val);
[color=#CC6600]delay[/color](15);
}
[color=#CC6600]Servo[/color] Jaguar4;
[color=#CC6600]void[/color] [color=#CC6600][b]setup[/b][/color]()
{
Jaguar4.[color=#CC6600]attach[/color](4);
}
{
val = [color=#CC6600]analogRead[/color](potpin);
val = [color=#CC6600]map[/color](val, 1, 60, 0, 179);
Jaguar4.[color=#CC6600]write[/color](val);
[color=#CC6600]delay[/color](15);
}
[/quote]
Not quite sure why the color things got added in the code. Ignore those
BurtonCustomX:
Not quite sure why the color things got added in the code. Ignore those
Don't use the "Copy for Forum" option in the Arduino IDE. Just select all your code and copy it into your post, surrounding it with the code tags. It's pretty difficult to "just ignore it" when it's a majority of the text that you're asking people to look at. Luckily, I had a feeling I knew what you were doing wrong, so I knew what to look for.
void setup()
{
Jaguar1.attach(1);
}
...
Servo Jaguar2;
void setup()
{
Jaguar2.attach(2);
}
You on'y get one setup(), you can't just add as many as you want.
So if I remove the extra void setup () lines it should work?