Question: please implement a obstacle avoidance algorithm here. navigator class public static enum MoveState { STOP, FORWARD, ARC, CONFIGURE, FOLLOW _ WALL } / / more
please implement a obstacle avoidance algorithm here.
navigator class
public static enum MoveState
STOP,
FORWARD,
ARC,
CONFIGURE,
FOLLOWWALL
more private class
private PioneerProxSensors proxsensors;
more code her
public int forwarddouble targetdist, double robotlinearvelocity
double wheelav robotlinearvelocitythisWHEELRADIUS;
double targettime targetdistrobotlinearvelocity;
this.leftmotor.setVelocitywheelav;
this.rightmotor.setVelocitywheelav;
this.state MoveState.FORWARD;
return targettime as millisecs
return inttargettime;
public int arcdouble icrangle, double icrr double icromega
double targettime icrangle icromega;
Calculate each wheel velocity around ICR
double vl icromega icrr thisAXELLENGTH ;
double vr icromega icrr thisAXELLENGTH ;
double leftwheelav vlthisWHEELRADIUS;
double rightwheelav vrthisWHEELRADIUS;
this.leftmotor.setVelocityleftwheelav;
this.rightmotor.setVelocityrightwheelav;
this.state MoveState.ARC;
return targettime as millisecs
return inttargettime;
public void stop
this.leftmotor.setVelocity;
this.rightmotor.setVelocity;
this.state MoveState.STOP;
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;
public MoveState getState
return this.state;
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 setpoint, boolean right
int directioncoeff ;
double error;
double control;
double walldist;
if right directioncoeff ; invert the values for the control
if Mathminthisproxsensorsgetvalue
Math.minthisproxsensorsgetvalue
Math.minthisproxsensorsgetvalue
Math.minthisproxsensorsgetvalue
Math.minthisproxsensorsgetvalue
this.proxsensorsgetvalue setpoint
this.setvelocityrobotlinearvelocitydirectioncoeff;
else
if right walldist Math.minthisproxsensorsgetvalue
this.proxsensorsgetvalue;
else walldist Math.minthisproxsensorsgetvalue
this.proxsensorsgetvalue;
Running aproximately parallel to the wall
if walldist this.proxsensorsgetmaxRange
error walldist setpoint;
control this.piderror;
adjust for right wall
this.setvelocityrobotlinearvelocity, controldirectioncoeff;
else
No wall, so turn
this.setvelocityrobotlinearvelocity, directioncoeff;
this.state MoveState.FOLLOWWALL;
controller class
double timeelapsed ;
double targettime ;
double robotvelocity ;
define schedule
PioneerNavMoveState schedule PioneerNavMoveState.FOLLOWWALL;
int scheduleindex ; we increment before selecting the current action
PioneerNavMoveState state; current state
set up display
String displayaction ;
if schedule PioneerNavMoveState.CONFIGURE
scheduleindex;
nav.configureinitialiseparametersMathPI;
while robotsteptimeStep
robotpose nav.getrealpose;
proxsensorssetposerobotpose;
etc
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
