Drone doesn't take off in jmavsim from python script

Hi ,

I am using the following python code to take off the drone in jmavsim :slight_smile:

from pymavlink import mavutil
import time

Create the connection

master = mavutil.mavlink_connection(‘udp:localhost:14540’)

Wait for the first heartbeat

master.wait_heartbeat()

Set the command type to MAV_MODE_FLAG_CUSTOM_MODE_ENABLED

custom_mode = 4 # 4 is for LOITER mode in PX4
master.mav.set_mode_send(
master.target_system,
mavutil.mavlink.MAV_MODE_FLAG_CUSTOM_MODE_ENABLED,
custom_mode)

Arm the drone

master.mav.command_long_send(
master.target_system, # target system
master.target_component, # target component
mavutil.mavlink.MAV_CMD_COMPONENT_ARM_DISARM, # command
0, # confirmation
1, # param 1, 1 to arm, 0 to disarm
0, 0, 0, 0, 0, 0) # param 2 ~ 7

Takeoff

master.mav.command_long_send(
master.target_system, # target system
master.target_component, # target component
mavutil.mavlink.MAV_CMD_NAV_TAKEOFF, # command
0, # confirmation
0, 0, 0, 0, 0, 0, 10) # param 1 ~ 7 (param 7 is the target altitude)

Monitor the flying status for a while

for _ in range(100):
print(master.recv_match().to_dict())
time.sleep(1)

But the drone in jmavsim doesn’t take off. I have tried taking off from the terminal by typing commander takeoff and it takes off. I am running the latest version of the code. Could someone let me know why is this happening ?

Thanks.

Hello @smishr13, did you find solution to the problem you are facing, now I am also facing the same problem, if you find it could you able to share.

Hi,

Well it works for me through Herelink - JMavsim-Ubuntu 22.04 combination in SIL flight mode on a Orange CUBE flight controller