Author Topic: Arduino Robot Programming  (Read 5118 times)

0 Members and 1 Guest are viewing this topic.

Offline minas11Topic starter

  • Beginner
  • *
  • Posts: 2
  • Helpful? 0
Arduino Robot Programming
« on: April 25, 2011, 03:49:36 AM »
I have made a robot with an arduino, but I do not know how to write the sketch in the Arduino IDE, I've written some simple sketches (blinking leds etc.) but i don't know how to write such a difficult for me sketch. I need help about the sketch, if someone has a sketch for a robot like mine please send it to me. :P


My robot includes:
2x continuous rotation servo for moving the robot
2x standard servo for moving the robot's head with the sharp ir sensor
1x sharp ir sensor (in the head) to avoid obstacles
1x PIR sensor (not in the head)

that's all :o
Please i need help

Offline joe61

  • Supreme Robot
  • *****
  • Posts: 417
  • Helpful? 16
Re: Arduino Robot Programming
« Reply #1 on: April 25, 2011, 06:57:23 AM »
You might be trying to do too much at once. Try figuring out each piece separately and then put them together.

The Arduino web site has a lot of information about how to interface with hardware, features of available libraries, and other stuff. Start with http://arduino.cc/playground/Main/InterfacingWithHardware and look for the section on Servos. That will lead you to various libraries and code examples for dealing with servos. You can find help/libraries/code for other hardware as well. Search the page or look at the menu on the left.

Also check http://arduino.cc/en/Reference/HomePage for how to use the built in libraries and other features for programming the Arduino.

Joe

Offline rbtying

  • Supreme Robot
  • *****
  • Posts: 452
  • Helpful? 31
Re: Arduino Robot Programming
« Reply #2 on: April 25, 2011, 06:59:46 AM »
1) What do you want your robot to do?
2) Can you give an accurate 3D representation of the location of these 4 servos and two sensors?
3) How do you have the electronics connected, and what models of each are they?

Some basic help, though we won't write all the code for you:

Servos:
Code: [Select]
// declaration
Servo myServo;
// initialization
myServo.attach(pinNumber);
// usage:
myServo.write(num); // num is in the set [0, 180], sets Servo to angle with given degree, or if continuous, sets it to move forward or backward
myServo.writeMicroSeconds(num); // num is in the set [1000, 2000], sets Servo to angle in proportion to signal given

Sharp IR:
Code: [Select]
analogRead(pinNumber); // gets 10-bit ADC reading of voltage
You'll need to tell us a little more about which sensor before we can help you any more than that... same with the PIR sensor.

Offline minas11Topic starter

  • Beginner
  • *
  • Posts: 2
  • Helpful? 0
Re: Arduino Robot Programming
« Reply #3 on: April 25, 2011, 07:49:24 AM »


i want my robot avoid obstacles and follow motion also my electronic are:
2x parallax continuous rotation servo
2x standard servo
1x Sharp GP2D12 IR Sensor
1x Parallax PIR sensor
1x Arduino

Offline rbtying

  • Supreme Robot
  • *****
  • Posts: 452
  • Helpful? 31
Re: Arduino Robot Programming
« Reply #4 on: April 25, 2011, 02:22:57 PM »
You still need to tell us what you want it to do... =)

Comments:
1. You need a caster or 'third wheel' to contact the ground, otherwise your robot will be very unstable (three points of contact define a plane).
2. Wheels?

I assume, however, that your CAD is just a mockup, and that you've already got answers to the two comments above.

You should use a step-by-step approach for this project. 

Step 1: Mount the hardware to make a stable robot platform.
Step 2: Program a working drive base (example code at end of post)
Step 3: Read data from sensors (example code at end of post)
Step 4: Implement algorithm to do whatever you want the robot to do (need your input!)

Example code for drive base (you may want to switch this to a state machine later):
Code: [Select]
#include <Servo.h> // include the servo library

// you will need to give these values
#define LEFT_SERVO_SIGNAL_PIN
#define RIGHT_SERVO_SIGNAL_PIN

Servo leftServo, rightServo;

// Takes a speed value between -100 (full reverse) and 100 (full forward) for each servo.
void setSpeeds(int8_t lspd, int8_t rspd) {
  uint16_t lSet = map(lspd, -100, 100, 1000, 2000); // map this to the servo's input range
  // because one of the servos is mounted backwards relative to the other, we will map it in reverse
  uint16_t rSet = map(rspd, -100, 100, 2000, 1000); // map this to the servo's input range

  leftServo.writeMicroseconds(lSet); // set left servo
  rightServo.writeMicroseconds(rSet); // set right servo
}

void setup() {
  leftServo.attach(LEFT_SERVO_SIGNAL_PIN);
  rightServo.attach(RIGHT_SERVO_SIGNAL_PIN);

  setSpeeds(0, 0);
}

void loop() {
  // turn left
  setSpeeds(-50, 50);
  // turn right
  setSpeeds(50, -50);
  // go forward
  setSpeeds(50, 50);
  // go backward
  setSpeeds(-50, -50);
}

Example code for Sharp GP2D12:
Code: [Select]
uint8_t readIR(uint8_t irpin) {
  uint16_t adc = analogRead(irpin);
  return (uint8_t) (5 * 2769 / 2 / value); // this equation was empirically derived for my sensor at some point, you can and should derive your own.
}

Example code for Parallax PIR: (assumes that it is set to single trigger output mode, see datasheet.)
Code: [Select]
#define PIR_SIGNAL_PIN

// in setup:
pinMode (PIR_SIGNAL_PIN, INPUT);

// when you want to check it
bool isMovement = digitalRead(PIR_SIGNAL_PIN);
Note: the code above is not guaranteed to work, it's instead intended to give you an idea of what you need to do

 


Get Your Ad Here

data_list