How to get drone to hover in Webots

103 views Asked by At

I am trying to get a Crazyflie drone to hover in Webots. I have written the code but when I change the velocity, no matter what I change the velocity to, it stays in the same place on the ground with the rotors spinning but no change in height.

from controller import Robot

robot = Robot()
timestep = int(robot.getBasicTimeStep())

# Get the motor devices with the correct names from your Webots simulation
motor1 = robot.getDevice("m1_motor")  # Replace with the correct name
motor2 = robot.getDevice("m2_motor")  # Replace with the correct name
motor3 = robot.getDevice("m3_motor")  # Replace with the correct name
motor4 = robot.getDevice("m4_motor")  # Replace with the correct name

# Set motor velocity to make the drone take off
motor1.setPosition(float('inf'))
motor2.setPosition(float('inf'))
motor3.setPosition(float('inf'))
motor4.setPosition(float('inf'))

# Adjust motor speeds to experiment with takeoff

motor1.setVelocity(600)
motor2.setVelocity(600)
motor3.setVelocity(600)
motor4.setVelocity(600)

while robot.step(timestep) != -1:
    pass  # Drone is in the air and can hover here

Drone on ground

I am just trying to get a basic understanding of using webots, so advanced algorithms/PID controllers are not something I want to focus on at the moment. If I can get it to rise to at all that will answer my question.

0

There are 0 answers