Using SITL with python script

Hello,
I want to use python script to connect to the SITL that is running on my system. This is the command i use to connect:

from pymavlink import mavutil

import time

print(“before connecting”)
drone = mavutil.mavlink_connection(‘tcp:127.0.0.1:5760’)

drone.mav.command_long_send(
0, #system id
0, #component id
400,#command id
0,
1, #disarm/arm
0,
0,0,0,0,0)

the script executes without any error , but the Simulation plane is not armed.

Any suggestion as what can be the problem??

Check my video out:

1 Like

Thanks for the video. But this doesn’t solves my problem. I am unable to send the commands using python script. According to me I have being making some mistake while connecting i guess, but I am not so sure. So, please help me clarify this and solve the problem.

1 Like

I haven’t tried this yet, are you on linux? If so, do you see port 5760 open on 0.0.0.0 and 127.0.0.1 when you run ‘netstat -an’?

If on Windows, do you need to set an allow rule in the Windows Firewall?

D

Yes I am LInux. And te Problem is solved. I was not following tutorial properly… my bad.
Anyways Thanx for your input.

Sripad

I am glad. Most of the questions and problems people use to ask me are because they did not follow the tutorial step by step. It’s human nature, we (me too) tend to skip and fast forward :wink:

Good eveninig mr tiziano, is there any possiblity that I can override the controls of the plane just like controlling from a joystick using a python script? I didn’t read any possible functions that can be used in controlling the plane. If there’s not what are the things that I consider in order to achieve what I want? There’s no problem about coding

You can use channel override commands to override one or multiple channels as they came from your Transmitter. If you can help, I’d stick with higher level commands though