Show Posts
Pages: [1]
1  Forum 2005-2010 (read only) / Syntax & Programs / Re: robot with sharp IR on: June 30, 2010, 11:59:05 am
Manut, I'm doing very much the same thing, but with an R/C car and its ESC.  I'm using the Sharp IR sensor (GP2Y0D810Z0F) for now since they're cheap enough to experiment with and simple in design.  the range is pretty low on them though.  

 Here's me code so far...can I get a sanity check??

Code:
/* Convert an R/C vehicle to an autonomous robot.  2 IR sensors at the front of the vehicle will detect obstacles & signal the vehicle to stop, backup, turn

and move forward again.  Speed is set very slow for the first test run. */

#include <Servo.h>

Servo SteeringServo;
Servo ElecSpeedCntl;

int DriveMotorPin = 0;
int FrLeftSensorPin = 1;
int FrRightSensorPin = 2;
int SteeringServoPin = 3;
int FrLeftSensorValue = 1;
int FrRightSensorValue = 1;
int x;

void arm()
{
      setSpeed (50);      // arm the ESC
      delay(1000);      // delay for 1 sec
}

void setSpeed (int speed)
{
       // speed is from -100 to 100 where 0 is off and 100 is max speed
       
        int angle = map(speed, 0, 100, 0, 180);      // maps speed values of 0 to 100 to angles from 0 to 180
        ElecSpeedCntl.write(angle);    
}

void setup ()
{
      pinmode (DriveMotorPin, OUTPUT);      // sets pin to drive motors as output
      pinmode (FrLeftSensorPin, INPUT);      // sets pin for IR sensor as input
      pinmode (FrRightSensorPin, INPUT);      // sets pin for IR sensor as input
      pinmode (SteeringServoPin, OUTPUT);      // sets pin to drive servos as output

      SteeringServo.attach(SteeringServoPin);      // sets pin for steering servo control
      ElecSpeedCntl.attach(DriveMotorPin);      // sets pin for electronic speed control
      arm();
}

void loop ()
{
      setSpeed(60);      // start at low speed

      x = 0;
      while (x < 1) {
      
            FrLeftSensorValue = FrLeftSensorPin;      // get left sensor value
            FrRightSensorValue = FrRightSensorPin;      // get right sensor value
      
            If (FrLeftSensorValue = LOW) {
                  setSpeed(50);                        // stop
                  delay (2000);                        // delay 2 seconds
                  setSpeed(70);                        // Drive in reverse
                  delay (2000);                        // delay 2 seconds
                  setSpeed(50);                        // stop
                  SteeringServo.write(112);            // turn right
                  setSpeed(60);                        // Drive fwd
                  delay (2000);                        // delay 2 seconds
                  setSpeed(50);                        // stop
                  SteeringServo.write(90);            // bring servo back to center
                  delay(2000);                        // delay 2 seconds
                  break;
            }
            else if (FrRightSensorValue = LOW)  {
                  setSpeed(50);                        // stop
                  delay (2000);                        // delay 2 seconds
                  setSpeed(70);                        // Drive in reverse
                  delay (2000);                        // delay 2 seconds
                  setSpeed(50);                        // stop
                  SteeringServo.write(67);            // turn left
                  setSpeed(60);                        // Drive fwd
                  delay (2000);                        // delay 2 seconds
                  setSpeed(50);                        // stop
                  SteeringServo.write(90);            // bring servo back to center
                  delay(2000);                        // delay 2 seconds
                  break;
            }

      }
}
2  Forum 2005-2010 (read only) / News / Re: Single-page Arduino Cheat Sheet on: June 08, 2010, 11:57:46 am
This was extremely helpful, thanks!

BMag
3  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Question on Digital Input Values on: June 09, 2010, 07:12:28 pm
By the way, a 2K resistor takes the signal input of 5.63V down to 5.11V High / 0.97V Low.  Should I take it lower than that?

BMag

4  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Question on Digital Input Values on: June 09, 2010, 06:43:52 pm
That darn ground wire will get you every time!  Yes, I'm using a separate power source.  Otakon2K - you're right it's 3V.  I found that on the reference section today.

I made a wiring harness from an R/C receiver switch assembly, and six male servo leads which will hold my six sensors.   I connected all of the power lines together to power the sensors from a 6V input through the switch.  I separated the signal output lines and will use them with the Arduino to help control the robot's motion.  

The platform....My old E-MAXX.  Can't wait to get this together.

Thanks for all the great input here.  will post pics soon.

BMag
5  Forum 2005-2010 (read only) / Frequently-Asked Questions / Question on Digital Input Values on: June 08, 2010, 12:09:53 pm
My first project with the Arduino is to flag an LED on when the input from a Sharp IR sensor goes low (GP2Y0D810Z0F).  I've written the most basic of programs to get the input and using an if statement, but it doesn't seem to be working.  The LED is either always on or off leding me to believe that the translation of the input is not working.  

My question is - what value does the input have to be for the Arduino to assign a HIGH or LOW value?  the input from my sensors are either 5.6V or 1.05V.  Will this translate to HIGH and LOW or do I have to regulate the input somehow?

Thanks.
6  Forum 2005-2010 (read only) / Bar Sport / Re: Haptic Robotic Arm on: June 25, 2010, 12:39:41 pm
Try this on for size...found it yesterday.  There's also a youtube video on the Videos page that shows the arm in motion side by side with the controller.

http://www.endurance-robotics.com/page.aspx?id=4
Pages: [1]