void scanObstacle ()
{
myservo.write(pos); // sets the servo position
delay(aDelay); // waits for the servo to get there
readDistance = analogRead(sensorPin); // Take a reading from sensor
delay(aDelay); // Wait to get the reading SOSOSOSOS !!!! We need this
if (readDistance > minDistanceLimit) // If we can scan an obstacle
{
avoidObstacle(pos); // Then do avoiding actions
}
if (pos == 180) // If we reach end of servo
{
servoStep= -sStep; // Move it back
}
if (pos == 0) // If we are at the start
{
servoStep = sStep; // Move it right
}
pos += servoStep;
}
What i m trying to do is. to use a 2nd servo and
when the pan servo value is between (0 and 80 ) and ( 100 to 180 ) to myservo_vertical.write(90); <<---- the 2nd servo
and when is between 80 and 100 to
myservo_vertical.write(100);
How can i do this ??? What ever i try is not working :-[
Thnx in advance
when the pan servo value is between (0 and 80 ) and ( 100 to 180 ) to myservo_vertical.write(90); <<---- the 2nd servo
and when is between 80 and 100 to
myservo_vertical.write(100);
Yes ...
Same results as PaulS code..
The 1st servo is panning correctly but the 2nd is not working at all
I thing that the part of code for the 2nd servo must be INSIDE the existent code something like
if (pos == 180) // If we reach end of servo
{
servoStep= -sStep; // Move it back
<<<<---Here to add somehow the code for the 2nd servo
}
What i want to do is... the paning servo (1st) to scan for obstacles in front of my robot and the 2nd (vertical) to scan in two potitions . 180 degrees for Gap in front of my robot and 90 degrees for an obstacle in the front of my robor. The final goal is to compare the 2 readings from the 2 front results in order to descide if the obstacle is tall enough (both sensors detect obstacle) and in this case to turn my robot OR if the lower (2nd) sensor detects an obstacle but the 1st is not , then the obstacle is "small" and my robot is able to climbe it.
void scanObstacle ()
{
myservo_pan.write(pos); // sets the servo position
myservo_vertical.write(90); // sets the servo position @ 90 degree
delay(aDelay); // waits for the servo to get there
readDistance = analogRead(sensorPin); // Take a reading from sensor
readDistance90 = analogRead(Vertical_sensorPin); // Take a reading from Vertical sensor @90 degree and store it
delay(aDelay); // Wait to get the reading SOSOSOSOS !!!! We need this
if (readDistance > minDistanceLimit) // If we can scan an obstacle
{
avoidObstacle(pos); // Then do avoiding actions
}
<<<<--------------------------------------------------------------------------- i v test to paste the code here also .Same results
if (pos == 180) // If we reach end of servo
{
servoStep= -sStep; // Move it back
}
if (pos == 0) // If we are at the start
{
servoStep = sStep; // Move it right
}
if((pos >= 0 && pos <= 80) || (pos >= 100 && pos <= 180))
{
myservo_vertical.write(90);
}
else if(pos > 80 && pos < 100)
{
myservo_vertical.write(180);
}
pos += servoStep;
<<<<--------------------------------------------------------------------------- i v test to paste the code here also .Same results
}
One thing I noticed is that you are stepping by 10. So, the only value of pos that should result in the vertical servo moving is 90. Try changing the vertical servo code to this:
if((pos >= 0 && pos < 80) || (pos > 100 && pos <= 180))
{
Serial.println("Move vertical servo to 90");
myservo_vertical.write(90);
}
else if(pos >= 89 && pos <= 91) <<<------------- only one step for 180 degree
{
Serial.println("Move vertical servo to 180");
myservo_vertical.write(180);
delay(500); <<<<<<<---------------------------added this delay
}
and now WORKING just fine.. as expected
Seems that was working from the first time , both 2 modifications , but due to small delay
int aDelay = 30; // Delay for the servo and let the IR to return results
the 2nd servo was not moving at all
I m so sorry.. its my fault :-[
From now , I must use the print statements that helps a lot to see what goes wrong.
The important thing is that you learned something.
You need to take a look at the if/else block that moves the vertical servo, though. There is no action defined when pos = 80 to 89 or when pos = 92 to 100. Even if the step size remains 10, pos = 80 and pos = 100 do not have defined actions.