Answered step by step
Verified Expert Solution
Link Copied!

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 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 PioneerNav2{
public static enum MoveState {
STOP,
FORWARD,
ARC,
FOLLOW_WALL };
private Supervisor robot; // reference to the robot
private Node robot_node; // reference to the robot node
private Pose robot_pose; // the robots percieved pose
private Motor left_motor;
private Motor right_motor;
private double max_vel;
private double prev_error;
private double total_error;
private PioneerProxSensors1 prox_sensors;
private MoveState state;
private final double WHEEL_RADIUS =0.96; // in meters - found using CONFIGURE
private final double AXEL_LENGTH =0.5; // in meters - found using CONFIGURE
//==================================================================================
// Constructor
//==================================================================================
public PioneerNav2(Supervisor robot, Pose init_pose,PioneerProxSensors1 ps){
this.prox_sensors = ps;
this.robot = robot;
this.robot_node = this.robot.getSelf(); // reference to the robot node
this.state = MoveState.STOP;
// enable motors
this.left_motor = robot.getMotor("left wheel");
this.right_motor = robot.getMotor("right wheel");
this.left_motor.setPosition(Double.POSITIVE_INFINITY);
this.right_motor.setPosition(Double.POSITIVE_INFINITY);
this.max_vel = this.left_motor.getMaxVelocity()-0.1; // Fudge: just under max vel
int timeStep =(int) Math.round(robot.getBasicTimeStep());
this.max_vel = this.left_motor.getMaxVelocity()-0.1; //
// set up pose
this.robot_pose = new Pose(init_pose.getX(), init_pose.getY(), init_pose.getTheta());
// Initialise motor velocity
this.left_motor.setVelocity(0.0);
this.right_motor.setVelocity(0.0);
this.prev_error =0;
this.total_error =0;
}
// The following method only works if in supervisor mode
public Pose get_real_pose(){
if (this.robot_node == null)
return new Pose(0,0,0);
double[] realPos = robot_node.getPosition();
double[] rot = this.robot_node.getOrientation(); //3x3 Rotation matrix as vector of length 9
double theta1= Math.atan2(-rot[0], rot[3]);
double halfPi = Math.PI/2;
double theta2= theta1+ halfPi;
if (theta1> halfPi)
theta2=-(3*halfPi)+theta1;
return new Pose(realPos[0], realPos[1], theta2);
}
public int forward(double target_dist, double robot_linearvelocity){
double wheel_av =(robot_linearvelocity/this.WHEEL_RADIUS);
double target_time = target_dist/robot_linearvelocity;
this.left_motor.setVelocity(wheel_av);
this.right_motor.setVelocity(wheel_av);
this.state = MoveState.FORWARD;
// return target_time as millisecs
return (int)(1000.0*target_time);
}
public int arc(double icr_angle, double icr_r, double icr_omega){
double target_time = icr_angle / icr_omega;
// Calculate each wheel velocity around ICR
double vl = icr_omega *(icr_r -(this.AXEL_LENGTH /2));
double vr = icr_omega *(icr_r +(this.AXEL_LENGTH /2));
double leftwheel_av =(vl/this.WHEEL_RADIUS);
double rightwheel_av =(vr/this.WHEEL_RADIUS);
this.left_motor.setVelocity(leftwheel_av);
this.right_motor.setVelocity(rightwheel_av);
this.state = MoveState.ARC;
// return target_time as millisecs
return (int)(1000.0*target_time);
}
public void stop(){
this.left_motor.setVelocity(0.0);
this.right_motor.setVelocity(0.0);
this.state = MoveState.STOP;
}
public MoveState getState(){
return this.state;
}
public void set_velocity(double base, double control){
double base_av = base / this.WHEEL_RADIUS;
double lv = base_av;
double rv = base_av;
if (control !=0){
double control_av = control / this.WHEEL_RADIUS;
lv = base_av - control_av;
rv = base_av + control_av;
// Check and limit velocity to avoid exceeding maximum velocity
double correction =1.0;
if (lv > this.max_vel || rv > this.max_vel){
double maxVel = Math.max(lv, rv);
correction = this.max_vel / maxVel;
lv *= correction;
rv *= correction;
}
}
this.left_motor.setVelocity(lv);
this.right_motor.setVelocity(rv);
}
private double pid(double error){
public void follow_wall{}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Autonomous Database In Enterprise Architecture

Authors: Bal Mukund Sharma, Krishnakumar KM, Rashmi Panda

1st Edition

1801072248, 978-1801072243

More Books

Students also viewed these Databases questions

Question

6. Explain the strengths of a dialectical approach.

Answered: 1 week ago

Question

2. Discuss the types of messages that are communicated nonverbally.

Answered: 1 week ago