Answered step by step
Verified Expert Solution
Link Copied!

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 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);
}
private double pid(double error){
double kp =0.5; // proportional weight (may need tuning)
double kd =3.0; // differential weight (may need tuning)
double ki =0.00; // 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 desired_distance_from_wall, boolean right){
int direction_coeff =1;
double error;
double control;
double wall_dist
if (right) direction_coeff =-1; // invert the values for the control
// Check if the robot is too close to the wall
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))))))< desired_distance_from_wall){
this.set_velocity(robot_linearvelocity /3,-0.1* direction_coeff); // Reduce turning speed
} else {
// Determine the closest wall distance
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));
// Check if the robot is running approximately parallel to the wall
if (wall_dist < this.prox_sensors.get_maxRange()){
// Calculate the error and control using PID
error = wall_dist - desired_distance_from_wall;
control = this.pid(error);
// Adjust for right wall
this.set_velocity(robot_linearvelocity, control * direction_coeff *0.5); // Reduce turning speed
} else {
// No wall detected, so turn
this.set_velocity(robot_linearvelocity, 0.04* direction_coeff); // Reduce turning speed
}
}

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

SQL Instant Reference

Authors: Gruber, Martin Gruber

2nd Edition

0782125395, 9780782125399

Students also viewed these Databases questions

Question

consider your role and influences as a researcher;

Answered: 1 week ago