Z
Z
Zugni2015-07-15 20:13:21
Arduino
Zugni, 2015-07-15 20:13:21

Need Help Breaking Down the Code How to Reduce Servo Rotation?

void motion (char dimention, int prev_angle, int next_angle, int time)
{
int a;
if(next_angle>=prev_angle)
a=15;
else
a=-15; 

if (dimention=='f')
{ 
int i=prev_angle;
while( i!=next_angle)
{ 
i+=a;
myservo.write(i);
forward();
delay(time);
}
}
if (dimention=='l')
{ 
int i=prev_angle;
while( i!=next_angle)
{ 
i+=a;
myservo.write(i);
left();
delay(time);
}
}
if (dimention=='r')
{ 
int i=prev_angle;
while( i!=next_angle )
{ 
i+=a;
myservo.write(i);
right();
delay(time);
}
}
if (dimention=='b')
{ 
int i=prev_angle;
while( i!=next_angle )
{ 
i+=a;
myservo.write(i);
back();
delay(time);
}
}
if (dimention=='w')
{
int i=prev_angle; 
while( i!=next_angle )
{ 
i+=a;
myservo.write(i);
wait();
delay(time);
}
}

}

void front_motion( int time )
{
if(dist_45<=9)
{
left();
delay(3*time);
}
if(dist_135<=9)
{
right();
delay(3*time);
} 
}

void motion_back( int time )
{
motion('b',180,90,2*time);
if(dist_l>=dist_r)
{
do
{
left();
delay(time);
dist_f=sonar();
}while(dist_f<=20);
} 

if(dist_l<dist_r)
{
do
{
right();
delay(time);
dist_f=sonar();
}while(dist_f<=20); 
} }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
LittleFatNinja, 2015-07-15
@LittleFatNinja

what is "reduce rotation"?

A
Alexander Gusev, 2015-07-15
@Sanchogus

What do you need? Decrease the speed at which the servo moves from one position to another? Change the speed of a servo that is designed for constant rotation? You can do
it without delving into the program. In the case of a constant rotation servo, this will reduce its speed, in this case by 2 times, in the case of a conventional servo, it will reduce its rotation angle by 2 times. If it is necessary to slow down the movement and make it smoother, then apparently a decrease in the variable amyservo.write(i);myservo.write(i/2);

a=15;
else
a=-15;

in let's say
a=5;
else
a=-5;

will lead to this result. And a=1 will give the smoothest transition.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question