Question: Create a new controller and implement a wall following behaviour using PID controller. You are expected to use sensors to detect the presence of the

Create a new controller and implement a wall following behaviour using PID controller. You
are expected to use sensors to detect the presence of the wall or obstacle nearby.
Here's the fundamental steps that you may implement:
a. Reading Sensor Input: The robot e-puck is equipped with sensors capable of
detecting the distance to the wall or obstacle.
b. Setpoint: Define the desired distance from the wall that the robot should maintain.
This is the reference value or setpoint for the PID controller.
c. Error Calculation: Calculate the error, which is the difference between the desired
distance (setpoint) and the actual distance measured by the sensor.
d. Proportional Control (P): Use the proportional term of the PID controller to generate a
control signal proportional to the error. The robot adjusts its motion based on how far
it is from the desired distance from the wall. For example, if the error is large (far from
the wall), the robot steers more sharply towards the wall.
e. Integral Control (I): Introduce integral control to account for accumulated error over
time. This helps the robot to overcome steady-state errors and biases. It continuously
adjusts the robot's motion based on the integral of the error over time.
f. Derivative Control (D): Incorporate derivative control to anticipate future error trends
based on the rate of change of the error. This helps dampen oscillations and improve
stability by adjusting the robot's motion based on how quickly the error is changing.
g. Controller Tuning: Tune the PID parameters (proportional gain, integral gain, and
derivative gain) to achieve the desired wall following behavior. This may involve
experimentation or automated tuning methods to find the optimal parameters for the
specific robot and environment.
h. Actuation: Based on the combined output of the proportional, integral, and derivative
terms, adjust the robot's actuators (such as motor speeds or steering angles) to
execute the desired motion and maintain the desired distance from the wall.
THE ENVIROMENT IS GIVEN ABOVE PLEASE ADJUST THE CODE BASED ON THAT: from controller import Robot
class State:
WALL_FOLLOWING =0
TURN_RIGHT =1
TURN_LEFT =2
def run_robot(robot):
timestep = int(robot.getBasicTimeStep())
max_speed =6.28
left_motor = robot.getMotor('left wheel motor')
right_motor = robot.getMotor('right wheel motor')
left_motor.setPosition(float('inf'))
left_motor.setVelocity(0.0)
right_motor.setPosition(float('inf'))
right_motor.setVelocity(0.0)
prox_sensors =[]
for ind in range(8):
sensor_name ='ps'+ str(ind)
prox_sensors.append(robot.getDistanceSensor(sensor_name))
prox_sensors[ind].enable(timestep)
# PID controller parameters
kp =0.1 # Proportional gain
ki =0.001 # Integral gain
kd =0.001 # Derivative gain
integral =0
prev_error =0
state = State.WALL_FOLLOWING
while robot.step(timestep)!=-1:
# Read sensor data
distances =[prox_sensors[ind].getValue() for ind in range(8)]
# Detect T-shaped wall
front_wall = distances[7]>80
left_wall = distances[5]>80
right_wall = distances[2]>80
# Wall-following behavior
if state == State.WALL_FOLLOWING:
if not front_wall:
error =80- distances[7]
proportional = kp * error
integral += ki * error
derivative = kd *(error - prev_error)
prev_error = error
control_signal = proportional + integral + derivative
left_speed = max_speed - control_signal
right_speed = max_speed + control_signal
else:
if left_wall and right_wall:
# Both left and right walls detected
# Move forward while slightly turning towards the opposite direction
left_speed = max_speed *0.7
right_speed = max_speed *0.3
elif left_wall:
# Left wall detected
# Perform a turn to the right while moving forward
left_speed = max_speed *0.5
right_speed = max_speed
elif right_wall:
# Right wall detected
# Perform a turn to the left while moving forw
left_speed = max_speed
right_speed = max_speed *0.5
else:
# No walls detected
# Turn left to search for a wall
left_speed =-max_speed
right_speed = max_speed
# Apply speed limits
left_speed = min(max(left_speed, -max_speed), max_speed)
right_speed = min(max(right_speed, -max_speed), max_speed)
# Set motor velocities
left_motor.setVelocity(left_speed)
right_motor.setVelocity(right_speed)
# Main function
if _name_=="_main_":
my_robot=Robot()
run_robot(my_Robot)
code is giving error
 Create a new controller and implement a wall following behaviour using

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!