How to write a script for a go-to-goal differential robot using just a proportional controller?
Show older comments
I'm trying to write a script where a differential drive robot travels from an origin to a goal location. I've used just a proportional controller, but upon simulation the trajectory of the robot to the goal location doesn't look very much like a proportional controller. Can anyone tell me if there is anything wrong with my code?
%UAV final destination
r=5;
s=2;
plot(r,s,'*')
hold on
%UAV initial position
a=0;
b=0;
%UAV current co-ordinates
x_old=a;
y_old=b;
x_new=0;
y_new=0;
%desired angle to goal
phi_desired= atan((s-a)/(r-a))
%gain
k=1;
%time step
t=.1;
%velocity
vel_x=1;
vel_y=1;
v=1;
%initial heading
phi_old=0; phi_new=0;
while(1)
if(x_new==r && y_new==s)
break;
end
error=phi_desired-phi_old
% w: angular velocity
w=k*error
phi_new=t*w+phi_old
vel_x=v*cos(phi_new)
vel_y=v*sin(phi_new)
pause(t);
x_new=x_old+vel_x * t
y_new=y_old+vel_y * t
phi_old=atan((s-y_new)/(r-x_new))
plot(x_new,y_new,'*');
hold on
x_old=x_new;
y_old=y_new;
end
Accepted Answer
More Answers (0)
Categories
Find more on Robotics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!