Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

using the below information can you please implemnet a obstancle avoidance algorith either bug 1 or bug 2 . please do implement actual algorithm. public

using the below information can you please implemnet a obstancle avoidance algorith either bug1 or bug2. please do implement actual algorithm. 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 void set_velocity(double base, double control){
// base gives the velocity of the wheels in m/s
// control is an adjustment on the main velocity
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);
// Check if we exceed max velocity and compensate
double correction =1;
lv = base_av - control_av;
rv = base_av + control_av;
if (lv > this.max_vel){
correction = this.max_vel / lv;
lv = lv * correction;
rv = rv * correction;
}
if (rv > this.max_vel){
correction = this.max_vel / rv;
lv = lv * correction;
rv = rv * correction;
}
}
this.left_motor.setVelocity(lv);
this.right_motor.setVelocity(rv);
}
public MoveState getState(){
return this.state;
}
private double pid(double error){
double kp =0.475; // proportional weight (may need tuning)
double kd =3; // differential weight (may need tuning)
double ki =0.0475; // integral weight (may need tuning)
double prop = error;
double diff = error - this.prev_error;
this.total_error += error;
double control =(kp * prop)+(ki * this.total_error)+(kd * diff);
this.prev_error = error;
return control;
}
public void follow_wall(double robot_linearvelocity, double set_point, boolean right){
int direction_coeff =1;
double error;
double control;
double wall_dist;
if (right) direction_coeff =-1; // invert the values for the control
if (Math.min(this.prox_sensors.get_value(1),
Math.min(this.prox_sensors.get_value(2),
Math.min(this.prox_sensors.get_value(3),
Math.min(this.prox_sensors.get_value(4),
Math.min(this.prox_sensors.get_value(5),
this.prox_sensors.get_value(6))))))< set_point)
this.set_velocity(robot_linearvelocity/3,-0.2*direction_coeff);
else {
if (!right) wall_dist = Math.min(this.prox_sensors.get_value(1),
this.prox_sensors.get_value(0));
else wall_dist = Math.min(this.prox_sensors.get_value(7),
this.prox_sensors.get_value(8));
// Running aproximately parallel to the wall
if (wall_dist < this.prox_sensors.get_maxRange()){
error = wall_dist - set_point;
control = this.pid(error);
// adjust for right wall
this.set_velocity(robot_linearvelocity, control*direction_coeff);
} else {
// No wall, so turn
this.set_velocity(robot_linearvelocity, 0.08*direction_coeff);
}
}
this.state = MoveState.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

Concepts Of Database Management

Authors: Joy L. Starks, Philip J. Pratt, Mary Z. Last

9th Edition

1337093424, 978-1337093422

More Books

Students also viewed these Databases questions

Question

Explain the factors that determine the degree of decentralisation

Answered: 1 week ago

Question

What Is acidity?

Answered: 1 week ago

Question

Explain the principles of delegation

Answered: 1 week ago

Question

State the importance of motivation

Answered: 1 week ago

Question

Discuss the various steps involved in the process of planning

Answered: 1 week ago

Question

Describe the concept of diversity and diversity management.

Answered: 1 week ago

Question

How does the EEOC define sexual harassment?

Answered: 1 week ago