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 epuck 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 steadystate 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:
WALLFOLLOWING
TURNRIGHT
TURNLEFT
def runrobotrobot:
timestep introbotgetBasicTimeStep
maxspeed
leftmotor robot.getMotorleft wheel motor'
rightmotor robot.getMotorright wheel motor'
leftmotor.setPositionfloatinf
leftmotor.setVelocity
rightmotor.setPositionfloatinf
rightmotor.setVelocity
proxsensors
for ind in range:
sensorname ps strind
proxsensorsappendrobotgetDistanceSensorsensorname
proxsensorsindenabletimestep
# PID controller parameters
kp # Proportional gain
ki # Integral gain
kd # Derivative gain
integral
preverror
state State.WALLFOLLOWING
while robot.steptimestep:
# Read sensor data
distances proxsensorsindgetValue for ind in range
# Detect Tshaped wall
frontwall distances
leftwall distances
rightwall distances
# Wallfollowing behavior
if state State.WALLFOLLOWING:
if not frontwall:
error distances
proportional kp error
integral ki error
derivative kd error preverror
preverror error
controlsignal proportional integral derivative
leftspeed maxspeed controlsignal
rightspeed maxspeed controlsignal
else:
if leftwall and rightwall:
# Both left and right walls detected
# Move forward while slightly turning towards the opposite direction
leftspeed maxspeed
rightspeed maxspeed
elif leftwall:
# Left wall detected
# Perform a turn to the right while moving forward
leftspeed maxspeed
rightspeed maxspeed
elif rightwall:
# Right wall detected
# Perform a turn to the left while moving forw
leftspeed maxspeed
rightspeed maxspeed
else:
# No walls detected
# Turn left to search for a wall
leftspeed maxspeed
rightspeed maxspeed
# Apply speed limits
leftspeed minmaxleftspeed, maxspeed maxspeed
rightspeed minmaxrightspeed, maxspeed maxspeed
# Set motor velocities
leftmotor.setVelocityleftspeed
rightmotor.setVelocityrightspeed
# Main function
if namemain:
myrobotRobot
runrobotmyRobot
code is giving error
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
