I own a duemilanove, and I want to use it to RC a chasis built from LEGO. the mindstorm nxt is too easy. I'm trying to make a more sufisticated toy/robot/car or whatever...that "can" operate autonomously, but with a manual override. I'm not using any hobby radios, because i'm trying to get it to work exclusively using my arduino. Ive solved the hardware issues, and can controll individual motors and "homebrew servo", but i'm having trouble writing the sketch to controll it all. I'm a newbie with the arduino, so sketching is still a bit trickie for me. can anyone help? Maybe someone else has already written a sketch for this, or could help me write my own...compound programing is a bit above my abilities at the moment. I can't quite grasp the syntax yet. Iv'e learned some of the routiments of it but I need help. :-? :-/
Hey crazy, there are stacks of people here who want to help. But we can't really help with a whole project at once. Can you break it down?
- What's the next thing you want to do?
- What code have you got and can you please post it?
- Do you have some info you can share on the hardware you've developed?
Help us help you!
I made a modified motor control shield with a servo control edition. The chasis construction is self explanetory. I used the basic servo shetch using a potentiometer, But want the arduino to operate the servo without me having to turn knobs. Modifying the sketch has proven to be difficult. the modified shield controls 1 motor and 1 servo.(individually at the moment) I cant control them both together yet, due to sketch problems. I'v got an XBEE wifi board coming in the mail, which I plan to link with a laptop to remotely control the chasis. I really need help combining the control sketches to work as one, I'm really very embarrased at about my ignorance with the code :-[. Then i want to use the XBee for real time control of the whole unit. "as well as autonomous operation.(this I'll work on later)". For now manual control will suffice. I don't have any pics of my work yet due to the lack of a digi-cam. And I haven't figured out how to post my code (as it is now) on the web. I could type it as a post in the forum, but then everyone would see it. I want it to work before I share it with everyone. no sense in frustrating others the way it frustrates me. If you've got a safe SnailMail address to send a hardcopy of my code to, (like a P.O. Box) you can see firsthand what I'm dealing with.
Here's some code for a lego car I made which used the motor shield to control 1 motor (driving forward and reverse) and a small servo to turn the steering wheel right,left, or center. I didn't do both at the same time though, it would drive forward, stop, turn, forward, etc. every time it turned.
#include <ServoTimer1.h>
ServoTimer1 servo1;
#include <AFMotor.h>
AF_DCMotor motor(3, MOTOR12_64KHZ); // create motor #2, 64KHz pwm
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Servo test!");
servo1.attach(9);
motor.setSpeed(255); // set the speed to 200/255
}
void loop() {
int right = 167; //the servo turns the steering wheel, these are the degree values
int left = 10;
int center = 85;
//10 = LEFT
//85 = CENTER
//167 = RIGHT
servo1.write(right);
delay(500);
motor.run(BACKWARD); // the other way
delay(1000);
motor.run(RELEASE); // stopped
delay(500);
servo1.write(left);
delay(500);
motor.run(FORWARD); // turn it on going forward
delay(1000);
motor.run(RELEASE); // stopped
delay(500);
/*
servo1.write(85);
delay(1000);
servo1.write(10);
delay(1000);
servo1.write(85);
delay(1000);
*/
delay(10);
}
Thanx Bigoil, this will help alot
motor control sketch.
int dirA = 12;
int dirB = 13;
int speedA = 10;
int speedB = 11;
byte ad,bd,as,bs;
void setup() { //call this once at the beginning
pinMode (dirA, OUTPUT);
pinMode (dirB, OUTPUT);
pinMode (speedA, OUTPUT);
pinMode (speedB, OUTPUT);
Serial.begin(115200);
}
void loop() { //main loop
if (Serial.available() > 2) { //if there is anything on the serial port, read it
ad = Serial.read(); //val direction A
bd = Serial.read(); //val direction B
as = Serial.read(); //speed A
bs = Serial.read(); //speed B
Serial.println(ad,DEC);
Serial.println(bd,DEC);
Serial.println(as,DEC);
Serial.println(bs,DEC);
if(ad = 48) digitalWrite(dirA,LOW);
if(ad = 49) digitalWrite(dirA,HIGH);
if(bd = 48) digitalWrite(dirB,LOW);
if(bd = 49) digitalWrite(dirB,HIGH);
if(as >50) analogWrite(speedA,as);
else digitalWrite(speedA,LOW);
if (bs > 50) analogWrite(speedB,bs);
else digitalWrite(speedB,LOW);
ad=0;
bd=0;
as=0;
bs=0;
}
}
Servo sketch from arduino.cc code library.
// Sweep
// by BARRAGAN http://barraganstudio.com
// This example code is in the public domain.
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop()
{
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
These are the codes that Im trying to get to work as one. I borrowed the motor control sketch from "RUSH" a fellow forum user. :).
Does this help?
DO you know about the # button ? just click on modify and insert the sketch between the quotes and see what happens ! and there is no mention to the lego thingy you are using Even if i could help you out i cant ! tell us more about the lego chasis !
I tried to post generic pics of what I'm using and explan how I modified the shield but Im having trouble posting the pics.
you need to upload the the pic somewhere and paste the link in between this [img.][/img.] ( eliminate the fullstops ) and if not the exact pictures even a link to what you are using could help !
You've never heard of Lego technic sets? :-? They're sold at TOYS "R" US(s) all over the world, ranging in price from $20-300 american. If I had pictures of my chasis/ car frame. I'd email them to you. Anyway thanx for the post. at least you tried to help.
You've never heard of Lego technic sets?
The strict answer is NO ! i just know that they exist i not how they are controlled do they have DC motors driven by a h bridge ? continuous rotation servos ?
http://www.arduino.cc/en/Main/ArduinoShields the link was borrowed from: "loldrup" a fellow forum user. I modified one of the motor control outputs to control a servo. Does this help?
They have motors that are designed to work with the set, Many sets come with these motors. but I had to get creative with the servo. I took a lego motor and modified it with a position sensing pcb, essentially I made a homebrew Servo.
Based On my extremely limited code understanding. It appears the this sketch was intend for a preprogramed path. I'm trying to make mine "realtime controlable/ interactive". with the ablitiy to go autonomous. but your sketch was helpful nonetheless, THANK YOU