Show Posts
Pages: [1]
1  Topics / Robotics / Re: smoothing servo movements on: June 17, 2012, 04:20:50 pm
I am at a loss on how to modify my code to smooth the drive servos start/stop/reverse movements. I have tried to include parts of the sweep code example from the servo library into my code.         for(pos = 0; pos < 180; pos += 1)      for(pos = 180; pos>=1; pos-=1)
nothing I have tried compiles.
I have attached my code. I am looking for help figuring out what and where to add to this code that would achieve this effect.
2  Topics / Robotics / Re: I need code to run to modified 360 degrees servo motors. on: June 03, 2012, 11:17:30 am
Rewrote code a little more with some help from oric_dan(333), thanks  smiley-grin still working on how to smooth out the servo movements. my servos start/stop/and reverse directions too rapidly. I am worried that this will damage them eventually smiley-confuse
my continuous rotation servos were made by vex robotics. they were originally designed to rotate continuously so I have never taken them apart, instead I just changes the settings in the code. the suggestions above are great if you are modifying normal servos. I have used the method of centering the potentiometer and glue it in place while the servo is hooked up and receiving a "center" signal, works great. here is my latest code smiley-cool
3  Topics / Robotics / Re: smoothing servo movements on: June 03, 2012, 12:14:49 am
thank you, I did a little rearranging. removed the const and rightbacward=leftforward and vise versa. I dont understand "graded". but I feel like I am several steps closer to the effect I wanted to get. will have to do some reading. here is code now.
4  Topics / Robotics / smoothing servo movements on: June 02, 2012, 09:42:32 pm
I have a bot that works well. it uses an ultrasonic proximity detector that pans 180 degrees. two "bumper" switches. it is driven by two continuously rotating servos "skid steer". I would like to smooth out the start/stop speed of the servos that drive it. they start and reverse directions too rapidly, and I am worried this will eventually damage them.
5  Topics / Robotics / Re: I need code to run to modified 360 degrees servo motors. on: June 02, 2012, 09:13:42 pm
I have tinkered with that code some more and added two "bump" switches to my bot. my ping sensor has good response approaching objects head on, however while approaching objects at near parallel angles it doesn't see them. bot has a wide platform and the ping sensor has a narrow field smiley-sad  A friend had a great idea also. Wrapping a length of wire several times around the positive wire to each drive servo could induce a small current flow with respect to ground. this could be used for current sensing for overload protection smiley my next goal is to find a way to smooth out the start/stop speed of my servos. they shift directions rapidly.  best of luck to you on your bot this weekend, I am sure you will need to tinker with the values that return the servos to center or stop position... here is my latest code.

Code:
//remember that the power for the servos comes from the voltage source, not the arduino board. only the signal wire "white or yellow" //is connected to the arduino board. no motor shield required .
//notes are written after these forward slashes to help explain the code
//IRpin and sharp ir sensor not working yet, ignore for now...

#include <Servo.h> //include Servo library information from arduino folder
const int RForward = 47; //speed value of drive servo, value 0 for full speed rotation
const int RBackward = 180; //speed value of drive servo, value 180 for full speed rotation
const int LForward = RBackward; //servos rotate opposite directions to drive in same direction
const int LBackward = RForward; //servos rotate opposite directions to drive in same direction
const int RNeutral = 95; //value 90 is default for center "stop", my servo is a little off
const int LNeutral = 95; //continuous rotation servo center "stop" position
const int pingPin = 7;  //signal pin on parallax ping sensor connected to arduino pin 7
const int dangerThresh = 40; //threshold limit for obstacles (in cm), 10 by default
const int IRpin = A0;  //Sharp infrared sensor connected to arduino pin analog 0
int switchPin = 2;  // normally open bumper switch connected to arduino pin 2 and ground
int leftDistance, rightDistance; //store values for later use to compare ping readings
Servo panMotor; //servo that pans the ping sensor
Servo leftMotor;  //continuous rotation servo that drives the left wheel
Servo rightMotor; //continuous rotation servo that drives the right wheel

long duration; //time it takes to recieve PING))) signal
void setup()
{
  rightMotor.attach(11); //right drive servo signal wire connected to arduino pin 11
  leftMotor.attach(10);  //left drive servo signal wire connected to arduino pin 10
  panMotor.attach(6); //pan servo for ping sensor connected to arduino pin 6
  pinMode(switchPin, INPUT);  //N.O. bumper switch connected to pin 2 and ground
  digitalWrite(switchPin, HIGH);// turns on 20k pullup resistor so switchPin will read HIGH unless triggered LOW
  pinMode(IRpin, INPUT); // set anolog pin 0 as sharp infrared sensor input
  float volts=analogRead(IRpin)*0.0048828125; ;  //read voltage from sharp ir sensor
  float distance = 65*pow(volts, -1.10);  //calculate distance from voltage reading above
  panMotor.write(83); //set PING))) sensor pan angle to center "90 by default"
}

void loop()  //after setup do these actions in a countinuous loop
{
  int distanceFwd = ping(); //ping stright ahead continuously and store the reading for comparison
  if (digitalRead(switchPin) == HIGH  && distanceFwd>dangerThresh) //if switch reads high and ping is greater distance than threshold
  
  {
    leftMotor.write(LForward); //move forward
    rightMotor.write(RForward); //move forward
  }
  else //otherwise if the path is blocked
  {
    leftMotor.write(LNeutral); //stop left drive motor
    rightMotor.write(RNeutral); //stop right drive motor
    panMotor.write(20); //turn ping sensor right, 0 for full right
    delay(300);        //wait this many milliseconds for servo to reach position
    rightDistance = ping(); //ping and calculate distance
    delay(100);  //wait this many milliseconds to store the measurement
    panMotor.write(135); //turn ping sensor left, 180 for full left
    delay(300);  //wait this many milliseconds for servo to reach position
    leftDistance = ping(); //ping and calculate distance
    delay(100);  //wait this many millisecondsto store measurement
    panMotor.write(83); //return to center, 90 for center
    delay(300);  //wait this many milliseconds for servo to reach position
    compareDistance(); //move on to next step "compare distance"
  }
}
  
void compareDistance()
{
  if (leftDistance>rightDistance) //if left is less obstructed
  {
    leftMotor.write(LBackward); //rotate left drive servo backward
    rightMotor.write(RForward); //rotate right drive servo forward
    delay(400); //run motors this many milliseconds
  }
  else if (rightDistance>leftDistance) //otherwise if right is less obstructed
  {
    leftMotor.write(LForward); //rotate left drive servo forward
    rightMotor.write(RBackward); //rotate right drive servo backward
    delay(400);  //run motors this many milliseconds
  }
   else //otherwise if they are equally obstructed
  {
    leftMotor.write(LForward); //rotate left drive servo forward
    rightMotor.write(RBackward); //rotate right drive servo backward
    delay(1500); //run motors this many milliseconds
  }
}

Moderator edit: code tags added. Again.
6  Topics / Robotics / Re: I need code to run to modified 360 degrees servo motors. on: May 31, 2012, 09:14:34 pm
well I have got mine working nice.. it is a ping pan roam robot. uses an ultrasonic prox sensor "parallax" mounted to a servo that pans it left and right. during a late night search for some similar arduino code I hit the jackpot. I don't know who originally created it as I have omitted and rewritten notes along with the header showing that info, thanks whoever you are. "oops". here it is smiley



Code:
#include <Servo.h> //include Servo library

const int RForward = 65; //speed value of drive servo, value 0 for full speed rotation
const int RBackward = 130; //speed value of drive servo, value 180 for full speed rotation
const int LForward = RBackward; //the servos must rotate in opposite directions in order to drive in the same direction
const int LBackward = RForward; //the servos must rotate in opposite directions in order to drive in the same direction
const int RNeutral = 95; //value 90 for center, my servo is a little off
const int LNeutral = 95; //value 90 for center, my servo is a little off
const int pingPin = 7;  //signal pin on parallax ping sensor connected to this arduino pin "remember the ping sensor is 5V, not source"
const int irPin = 0;  //Sharp infrared sensor connected to this arduino pin "not currently used"
const int dangerThresh = 20; //threshold for obstacles (in cm), this was 10 by default
int leftDistance, rightDistance; //distances on either side
Servo panMotor; //servo that pans the ping sensor
Servo leftMotor;  //continuous rotation servo that drives the left wheel
Servo rightMotor; //continuous rotation servo that drives the right wheel
long duration; //time it takes to recieve PING))) signal

void setup()
{
  rightMotor.attach(11); //signal wire on right countinuous rotation "drive" servo connected to this arduino pin
  leftMotor.attach(10);  //signal wire on left continuous rotation "drive servo connected to this arduino pin
  panMotor.attach(6); //signal wire on pan servo for ping sensor connected to this arduino pin
  panMotor.write(90); //set PING))) pan to center "90 by default"
}

void loop()
{
  int distanceFwd = ping(); //ping stright ahead
  if (distanceFwd>dangerThresh) //if the path is clear
  {
    leftMotor.write(LForward); //move forward
    rightMotor.write(RForward); //move forward
  }
  else //if path is blocked
  {
    leftMotor.write(LNeutral); //stop left drive motor
    rightMotor.write(RNeutral); //stop right drive motor
    panMotor.write(0); //turn ping sensor right, 0 for full right
    delay(500);        //wait this many milliseconds
    rightDistance = ping(); //ping
    delay(500);  //wait this many milliseconds
    panMotor.write(170); //turn ping sensor left, 180 for full right "my servo hits stop limit and binds at 180"
    delay(500);  //wait this many milliseconds
    leftDistance = ping(); //ping
    delay(500);  //wait this many milliseconds
    panMotor.write(83); //return to center, "90 by default" my servo is off center
    delay(100);  //wait this many milliseconds
    compareDistance(); //compare the two distances measured
  }
}
  
void compareDistance()
{
  if (leftDistance>rightDistance) //if left is less obstructed
  {
    leftMotor.write(LBackward); //rotate left drive servo bacward "skid steer"
    rightMotor.write(RForward); //rotate right drive servo forward "skid steer"
    delay(1000); //run motors this many milliseconds
  }
  else if (rightDistance>leftDistance) //if right is less obstructed
  {
    leftMotor.write(LForward); //rotate left drive servo forward "skid steer"
    rightMotor.write(RBackward); //rotate right drive servo backward "skid steer"
    delay(1000);  //run motors this many milliseconds
  }
   else //if they are equally obstructed
  {
    leftMotor.write(LForward); //rotate left drive servo forward
    rightMotor.write(RBackward); //rotate right drive servo backward
    delay(2000); //run motors this many milliseconds
  }
}

Moderator edit: [code] [/code] tags added
7  Topics / Robotics / Re: I need code to run to modified 360 degrees servo motors. on: May 29, 2012, 10:07:51 pm
 I am working on a robot platform made by vex. it is a skid steer platform driven by two continuously rotating servos. I have added a regular servo to pan a ping sensor. so far I have been able to get it moving forward at equal speeds per side and I have the pan servo working for the ping sensor. working hard to figure out how I am going to cause a reaction from the ping sensor to avoid obstacles. for now here is my code so far, it sounds like it may be similar to the type of platform discussed here.

#include <Servo.h>
 
Servo myservopan;  // create servo object to control a servo
Servo myservorightdrive;
Servo myservoleftdrive;
 
int pos = 0;    // variable to store the servo position

void setup()
{
  myservopan.attach(9);
  myservorightdrive.attach(2);
  myservoleftdrive.attach(3);
}
 
 
void loop()
{
  for(pos = 0; pos < 90; pos += 1)  // goes from 0 degrees to 90 degrees
  {                                  // in steps of 1 degree
    myservopan.write(pos);              // tell servo to go to position in variable 'pos'
    delay(20);
  }
  for(pos = 90; pos>=1; pos-=1)     // goes from 90 degrees to 0 degrees
  {                               
    myservopan.write(pos);              // tell servo to go to position in variable 'pos'
    delay(20);                       // waits 20ms for the servo to reach the position
  }
  for(pos = 90; pos>=60; pos-=1)
  {
    myservorightdrive.write(pos);
    delay(1);
  }
  for(pos = 90; pos < 130; pos += 1)
  {
    myservoleftdrive.write(pos);
    delay(1);
  }
}
Pages: [1]