Answered step by step
Verified Expert Solution
Question
1 Approved Answer
the following is done Webots, can you please improve the pid and wallfollowing section so that the robots moves better and more accurately. public void
the following is done Webots, can you please improve the pid and wallfollowing section so that the robots moves better and more accurately.
public void setvelocitydouble base, double control
base gives the velocity of the wheels in ms
control is an adjustment on the main velocity
double baseav basethisWHEELRADIUS;
double lv baseav;
double rv baseav;
if control
double controlav controlthisWHEELRADIUS;
Check if we exceed max velocity and compensate
double correction ;
lv baseav controlav;
rv baseav controlav;
if lv this.maxvel
correction this.maxvel lv;
lv lv correction;
rv rv correction;
if rv this.maxvel
correction this.maxvel rv;
lv lv correction;
rv rv correction;
this.leftmotor.setVelocitylv;
this.rightmotor.setVelocityrv;
private double piddouble error
double kp ; proportional weight may need tuning
double kd ; differential weight may need tuning
double ki ; integral weight may need tuning
double prop error;
double diff error this.preverror;
this.totalerror error;
double control kp propki this.totalerrorkd diff;
this.preverror error;
return control;
public void followwalldouble robotlinearvelocity, double desireddistancefromwall, boolean right
int directioncoeff ;
double error;
double control;
double walldist
if right directioncoeff ; invert the values for the control
Check if the robot is too close to the wall
if Mathminthisproxsensorsgetvalue
Math.minthisproxsensorsgetvalue
Math.minthisproxsensorsgetvalue
Math.minthisproxsensorsgetvalue
Math.minthisproxsensorsgetvalue
this.proxsensorsgetvalue desireddistancefromwall
this.setvelocityrobotlinearvelocity directioncoeff; Reduce turning speed
else
Determine the closest wall distance
if right walldist Math.minthisproxsensorsgetvalue
this.proxsensorsgetvalue;
else walldist Math.minthisproxsensorsgetvalue
this.proxsensorsgetvalue;
Check if the robot is running approximately parallel to the wall
if walldist this.proxsensorsgetmaxRange
Calculate the error and control using PID
error walldist desireddistancefromwall;
control this.piderror;
Adjust for right wall
this.setvelocityrobotlinearvelocity, control directioncoeff ; Reduce turning speed
else
No wall detected, so turn
this.setvelocityrobotlinearvelocity, directioncoeff; Reduce turning speed
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started