squareface
squareface

Reputation: 11

Robot sensors malfunction

I'm trying to make a simple wall follower robot on webots simulator but the sensors values are weird. The code bellow it's only to make the robot drive foward and print sensor values:

from controller import Robot

robot = Robot()
MAX_SPEED = 6.4
timestep = 32

leftBackMotor = robot.getDevice('back left wheel')
rightBackMotor = robot.getDevice('back right wheel')

leftFrontMotor = robot.getDevice('front left wheel')
rightFrontMotor = robot.getDevice('front right wheel')

motors = [leftBackMotor, rightBackMotor, leftFrontMotor, rightFrontMotor]

for motor in motors:
    motor.setPosition(float('inf'))  
    motor.setVelocity(0.0)  

dist_sensor = []
for i in range(16):
    sensor_name = "so" + str(i)
    dist_sensor.append(robot.getDevice(sensor_name))
    dist_sensor[i].enable(timestep)    

while robot.step(timestep) != -1:
   for i in range(16):
        print(f'Sensor: {i} Valor: {dist_sensor[i].getValue()}')
    
   leftBackMotor.setVelocity(MAX_SPEED)
   leftFrontMotor.setVelocity(MAX_SPEED)
   rightBackMotor.setVelocity(MAX_SPEED)
   rightFrontMotor.setVelocity(MAX_SPEED)

I'm using a pioneer 3at robot with 16 sensors(6 of them are frontal sensors) but only two of them are returning values different than zero, even the other frontal sensors that are expected to detects the wall. When a sensor touches an object the rays tuns green but even though the frontal rays turn green, only two sensors are greater than 0. What could it be?

Upvotes: 1

Views: 26

Answers (0)

Related Questions