Answered step by step
Verified Expert Solution
Question
1 Approved Answer
can you please add completed bug 2 algorith to the following code. import com.cyberbotics.webots.controller.Motor; import com.cyberbotics.webots.controller.Supervisor; import com.cyberbotics.webots.controller.Node; public class PioneerNav 2 { public static
can you please add completed bug algorith to the following code. import com.cyberbotics.webots.controller.Motor;
import com.cyberbotics.webots.controller.Supervisor;
import com.cyberbotics.webots.controller.Node;
public class PioneerNav
public static enum MoveState
STOP,
FORWARD,
ARC,
FOLLOWWALL ;
private Supervisor robot; reference to the robot
private Node robotnode; reference to the robot node
private Pose robotpose; the robots percieved pose
private Motor leftmotor;
private Motor rightmotor;
private double maxvel;
private double preverror;
private double totalerror;
private PioneerProxSensors proxsensors;
private MoveState state;
private final double WHEELRADIUS ; in meters found using CONFIGURE
private final double AXELLENGTH ; in meters found using CONFIGURE
Constructor
public PioneerNavSupervisor robot, Pose initpose,PioneerProxSensors ps
this.proxsensors ps;
this.robot robot;
this.robotnode this.robot.getSelf; reference to the robot node
this.state MoveState.STOP;
enable motors
this.leftmotor robot.getMotorleft wheel";
this.rightmotor robot.getMotorright wheel";
this.leftmotor.setPositionDoublePOSITIVEINFINITY;
this.rightmotor.setPositionDoublePOSITIVEINFINITY;
this.maxvel this.leftmotor.getMaxVelocity; Fudge: just under max vel
int timeStep int Math.roundrobotgetBasicTimeStep;
this.maxvel this.leftmotor.getMaxVelocity;
set up pose
this.robotpose new Poseinitpose.getX initpose.getY initpose.getTheta;
Initialise motor velocity
this.leftmotor.setVelocity;
this.rightmotor.setVelocity;
this.preverror ;
this.totalerror ;
The following method only works if in supervisor mode
public Pose getrealpose
if thisrobotnode null
return new Pose;
double realPos robotnode.getPosition;
double rot this.robotnode.getOrientation; x Rotation matrix as vector of length
double theta Math.atanrot rot;
double halfPi Math.PI;
double theta theta halfPi;
if theta halfPi
thetahalfPitheta;
return new PoserealPos realPos theta;
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 MoveState getState
return this.state;
public void setvelocitydouble base, double control
double baseav base this.WHEELRADIUS;
double lv baseav;
double rv baseav;
if control
double controlav control this.WHEELRADIUS;
lv baseav controlav;
rv baseav controlav;
Check and limit velocity to avoid exceeding maximum velocity
double correction ;
if lv this.maxvel rv this.maxvel
double maxVel Math.maxlv rv;
correction this.maxvel maxVel;
lv correction;
rv correction;
this.leftmotor.setVelocitylv;
this.rightmotor.setVelocityrv;
private double piddouble error
public void followwall
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