launchSitl "can't find '__main__' in module in ' ' error


#7

jax200,
Once again, I really appreciate your help.
This is what I get when, I start the SITL and program independently,

gustavo@thinkpad-t430:~/courseRoot/dk$ python basic_template.py --connect 127.0.0.1:14550
WARNING:dronekit:Link timeout, no heartbeat in last 5 seconds
ERROR:dronekit.mavlink:Exception in MAVLink input loop
Traceback (most recent call last):
File “/usr/local/lib/python2.7/dist-packages/dronekit/mavlink.py”, line 211, in mavlink_thread_in
fn(self)
File “/usr/local/lib/python2.7/dist-packages/dronekit/init.py”, line 1371, in listener
self._heartbeat_error)
APIException: No heartbeat in 30 seconds, aborting.
Traceback (most recent call last):
File “basic_template.py”, line 63, in
vehicle = connectMyCopter()
File “basic_template.py”, line 26, in connectMyCopter
vehicle = connect(connection_string,wait_ready=True)
File “/usr/local/lib/python2.7/dist-packages/dronekit/init.py”, line 3166, in connect
vehicle.initialize(rate=rate, heartbeat_timeout=heartbeat_timeout)
File “/usr/local/lib/python2.7/dist-packages/dronekit/init.py”, line 2275, in initialize
raise APIException(‘Timeout in initializing connection.’)
dronekit.APIException: Timeout in initializing connection.
gustavo@thinkpad-t430:~/courseRoot/dk$


#8

I don’t mind helping, but at this point I am guessing.

You are taking note of the potential pymavlink conflicts with dronekit? Have you run this in virtualenv?

https://dojofordrones.com/topic/installing-virtualenv-for-multiple-pymavlink-versions/

What are you getting for -

pip freeze | grep -i mav
pip freeze | grep -i drone

I noticed a previous forum discussion on this…

https://community.dojofordrones.com/t/launchsitl/321

Can you communicate with the sim_vehicle ok just with mavproxy commands?


#9

I have looked at many different forums and even seen some of you suggestions on other posts. It seems this issue is persistent.
I tried uninstalling and installing the course suggested version, and also tried installing other versions, and still come up empty.

------------------ Virtual Environment Output for pip freeze | grep -i drone & mav --------------

(dksitl) gustavo@thinkpad-t430:~/courseRoot/dk$ pip freeze | grep -i mav
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
MAVProxy==1.6.2
pymavlink==2.0.6
(dksitl) gustavo@thinkpad-t430:~/courseRoot/dk$ pip freeze | grep -i drone
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
dronekit==2.9.1
dronekit-sitl==3.3.0
(dksitl) gustavo@thinkpad-t430:~/courseRoot/dk$

---------------------- Bare Metal Linux 18.04 pip freeze | grep -i drone & mav outputs -------
gustavo@thinkpad-t430:~/courseRoot/dk$ pip freeze | grep -i drone
dronekit==2.9.2
dronekit-sitl==3.3.0
gustavo@thinkpad-t430:~/courseRoot/dk$ pip freeze | grep -i mav
MAVProxy==1.8.17
pymavlink==2.4.29
gustavo@thinkpad-t430:~/courseRoot/dk$

Yes, I can communicate with the sim_vehicle using MAVProxy OK, although I did noticed something unusually different from the course video.
In the video, the MAVProxy Commands being typed on the terminal provided an output response being echoed into the same terminal. However in my case the MAVProxy Commands in the actual MAVProxy terminal did not echoed anything, the responses where echoed directly to the automatically opened terminal that pops up when executing the sim_vehicle command

So far tested several combinations of Ardupilot and Dronekit without success.
It seems the dronekit program is a few tacos short of a combination platter…

I tried executing the course’s python examples:
python attributes_fetcher.py and get…
gustavo@thinkpad-t430:~/courseRoot/dk$ python connection_template.py
Starting copter simulator (SITL)
SITL already Downloaded and Extracted.
Ready to boot.
CRITICAL:autopilot:APM:Copter V3.3 (d6053245)
CRITICAL:autopilot:Frame: QUAD
CRITICAL:autopilot:Calibrating barometer
CRITICAL:autopilot:Initialising APM…
CRITICAL:autopilot:barometer calibration complete
CRITICAL:autopilot:GROUND START
gustavo@thinkpad-t430:~/courseRoot/dk$

However when I tried running python basic_template.py, it never sets the mode to GUIDED. Dronekit doesn’t seem to be communicating consistently with the Sitl or sim_vehicle???
gustavo@thinkpad-t430:~/courseRoot/dk$ python basic_template.py
Starting copter simulator (SITL)
SITL already Downloaded and Extracted.
Ready to boot.
CRITICAL:autopilot:APM:Copter V3.3 (d6053245)
CRITICAL:autopilot:Frame: QUAD
CRITICAL:autopilot:Calibrating barometer
CRITICAL:autopilot:Initialising APM…
CRITICAL:autopilot:barometer calibration complete
CRITICAL:autopilot:GROUND START
Waiting for vehicle to become armable.
Waiting for vehicle to become armable.
Waiting for vehicle to become armable.
Waiting for vehicle to become armable.
Waiting for vehicle to become armable.
Vehicle is now armable
Waiting for drone to enter GUIDED flight mode
Waiting for drone to enter GUIDED flight mode
Waiting for drone to enter GUIDED flight mode
Waiting for drone to enter GUIDED flight mode
Waiting for drone to enter GUIDED flight mode
Waiting for drone to enter GUIDED flight mode
Waiting for drone to enter GUIDED flight mode
Waiting for drone to enter GUIDED flight mode

At this point, I am wondering, if I should get my money back for these courses, I am not sure where the problem lies, but it is definitely over my head…


#10

I know from experience it can be frustrating. But one thing I can say is I was always able to get through it.
I presently test rather complicated missions with a sitl.
I can offer this idea: let’s start from scratch and write down each step and I will do it with you.
We can use python2 or python3. Python2 is deprecated, but Caleb claims python3 runs into issues with ros. So normally I use python3 but for a ros environment I am using python2.

Let me know and I will write down the steps.


#11

Jax200,
Thank you for the help, it is truly frustrating. I have tested it several ways, please see below,

Using my bare metal linux box (thinkpad 430) & a serial to UART Adaptor, and using putty (as a hyperterminal substitute). And I confirmed, that some data comes across the line, because I see garbled characters going through from both ends.

With that setup, I can connect my linuxbox USB port or even the raspberry pi3 USB port directly to my controller (Kakute H7 FC).
The Kakute H7 FC is configured to serial port 3, as per ardupilot documentation
Serial 3 Baud: 921 (921600)
Serial 3 Protocol: 2 (Mavlink)
Serial 3 Options: 0

gustavo@thinkpad-t430:~/courseRoot/apm/ardupilot/ArduCopter$ mavproxy.py --master=/dev/ttyUSB0 --baudrate 921600
Connect /dev/ttyUSB0 source_system=255
Log Directory:
Telemetry log: mav.tlog
Waiting for heartbeat from /dev/ttyUSB0
MAV> link 1 down

Even using the raspberry PI connected via the USB to UART converter or even Serial to Serial, I get the same result
gustavo@dronepi:~ $ ls /dev/ttyUSB*
/dev/ttyUSB0
gustavo@dronepi:~ $ mavproxy.py --master=/dev/ttyUSB0 --baudrate 921600
Connect /dev/ttyUSB0 source_system=255
Log Directory:
Telemetry log: mav.tlog
Waiting for heartbeat from /dev/ttyUSB0
MAV> link 1 down

So far, neither the Sitl nor the actual hardware is able to communicate via MAVLink/MAVProxy to either the companion PC or the Ground Station PC. Considering the amount of time sunk into getting something this simple to work, it is foreshadowing a rather ominous end to this project.

Could you kindly write down the steps and I will execute them on my end, to the best of my ability, and perhaps get to the bottom of it.

Sincerely,
Gus


#12

I might want to try that board. It’s not the BT version is it?
You did make the appropriate changes in raspi-config?
I just got done configuring a MATEK F405STD fc and found a mix-up on the telemetry wiring.
Garbled characters often means use of an incorrect baud rate. So you might want to explore that.
The UART mapping shows GPS is Serial 3. So you might want to change that to -

Serial 3 Baud: 38
Serial 3 Protocol: 5

And for the radio -

Serial 1 Baud: 57
Serial 1 Protocol: 2

Like I said, if you want me to walk through the sitl with you let me know.

Jack


#13

Yes, please walk me through the sitl connection.
As far as the kakute H7, the board has Serial1 assigned to the JST Pins, so it isn’t as easy to physically connect as the other available pins.
I tried Serial3, 38400, 5 protocol, although the response is slightly less garbled and evenly space, it is still unintelligible…


#14

I don’t follow regarding the board as I see there are options https://ardupilot.org/plane/docs/common-holybro-kakuteh7.html. How are you connecting to the companion? Note the video series with this boad (https://www.youtube.com/watch?v=XO7gGvhSqO0&list=PL_O9QDs-WAVyozF4JOVFkxVpv-cKs6-DN&index=1)

Regarding the SITL, I just verified the following steps work (some optional). It is based on this forum link which I slightly modified and deviates a bit from the course. The link further discusses using launchSitl.

https://community.dojofordrones.com/t/ubuntu-20-python3-setup/304/26.

Create VBox Ubuntu 20.04 machine (minimal install)

sudo apt update && sudo apt upgrade -y

sudo apt install build-essential manpages-dev git -y

sudo apt-get install python3-dev python3-pip -y

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 10
NOTE: ‘–’ two dashes for ‘install’

sudo apt-get install python3-opencv python3-wxgtk4.0 -y

sudo apt install python3-matplotlib python3-lxml -y

sudo apt install python3-serial python3-scipy python3-pexpect python3-tk -y

python3 -m pip install -U pygame –user
NOTE: ‘–’ two dashes for ‘user’

pip3 install PyYAML mavproxy

echo “export PATH=$PATH:$HOME/.local/bin” >> ~/.bashrc

source ~/.bashrc

sudo usermod -a -G dialout $USER

sudo apt remove modemmanager -y

cd ~

mkdir drone

sudo echo “export drone= /home/$USER/drone” >> ~/.bashrc

source ~/.bashrc

cd drone

mkdir apm

cd apm

git clone -b Copter-4.1.1 https://github.com/ardupilot/ardupilot
NOTE: Check for latest version.

cd ardupilot

git submodule update –init –recursive
NOTE": ‘–’ two dashes for ‘init’ and ‘recursive’

cd

sudo -H pip3 install dronekit==2.9.2

sudo -H pip3 install dronekit-sitl==3.3.0

Example simple run (using two dashes)
cd /drone/apm/ardupilot/ArduCopter
…/Tools/autotest/sim_vehicle.py --console --map

Example run with Mission Planner outside of VBox
sim_vehicle.py --console –-out x.x.x.x:14551
NOTE: x.x.x.x is your local computer with pre-installed MP

I can run without a virtual environment, but conflicts are possible.


How to Incorporate https:// with "git submodule update --init --recursive"
#15

Hey Jax,
I was able to go through the list. I am running on bare metal ubuntu 20.04 LTS.
The good news is that sim_vehicle.py works like a charm.
Even launching the dronekit script “connection_template.py” works. As long as an IP address is not specified. See outputs below,
also one important note: python3 does not like the “exceptions” library.

----- without IP address specified -------------------
gustavo@thinkpad-t430:~/drone/dk$ python connection_template.py
Starting copter simulator (SITL)
SITL already Downloaded and Extracted.
Ready to boot.
CRITICAL:autopilot:APM:Copter V3.3 (d6053245)
CRITICAL:autopilot:Frame: QUAD
CRITICAL:autopilot:Calibrating barometer
CRITICAL:autopilot:Initialising APM…
CRITICAL:autopilot:barometer calibration complete
CRITICAL:autopilot:GROUND START

------------------ with IP address specified in the command ----------
gustavo@thinkpad-t430:~/drone/dk$ ^C
gustavo@thinkpad-t430:~/drone/dk$ python connection_template.py --connect 127.0.0.1:14550
WARNING:dronekit:Link timeout, no heartbeat in last 5 seconds
^CTraceback (most recent call last):
File “connection_template.py”, line 31, in
vehicle = connectMyCopter()
File “connection_template.py”, line 25, in connectMyCopter
vehicle = connect(connection_string,wait_ready=True)
File “/usr/local/lib/python3.8/dist-packages/dronekit/init.py”, line 3166, in connect
vehicle.initialize(rate=rate, heartbeat_timeout=heartbeat_timeout)
File “/usr/local/lib/python3.8/dist-packages/dronekit/init.py”, line 2271, in initialize
time.sleep(.1)
KeyboardInterrupt

Lastly the other script “basic_connection.py” also executes in a similar way, with the exception, that it gets hung up waiting for the Sitl drone to go into GUIDED Mode, for some odd reason…???

gustavo@thinkpad-t430:~/drone/dk$ python basic_template.py
Starting copter simulator (SITL)
SITL already Downloaded and Extracted.
Ready to boot.
CRITICAL:autopilot:APM:Copter V3.3 (d6053245)
CRITICAL:autopilot:Frame: QUAD
CRITICAL:autopilot:Calibrating barometer
CRITICAL:autopilot:Initialising APM…
CRITICAL:autopilot:barometer calibration complete
CRITICAL:autopilot:GROUND START
Waiting for vehicle to become armable.
Waiting for vehicle to become armable.
Waiting for vehicle to become armable.
Waiting for vehicle to become armable.
Waiting for vehicle to become armable.
Vehicle is now armable
Waiting for drone to enter GUIDED flight mode
Waiting for drone to enter GUIDED flight mode
Waiting for drone to enter GUIDED flight mode
Waiting for drone to enter GUIDED flight mode
Waiting for drone to enter GUIDED flight mode
Waiting for drone to enter GUIDED flight mode
Waiting for drone to enter GUIDED flight mode
Waiting for drone to enter GUIDED flight mode
Waiting for drone to enter GUIDED flight mode
Waiting for drone to enter GUIDED flight mode
Waiting for drone to enter GUIDED flight mode
Waiting for drone to enter GUIDED flight mode
Waiting for drone to enter GUIDED flight mode
Waiting for drone to enter GUIDED flight mode
^CTraceback (most recent call last):
File “basic_template.py”, line 63, in
arm_and_takeoff(10)
EOF on TCP socket
File “basic_template.py”, line 40, in arm_and_takeoff
EOF on TCP socket
EOF on TCP socket
time.sleep(1)
EOF on TCP socket
KeyboardInterrupt
EOF on TCP socket

Either way, it is still an improvement and movement in the right direction in my book.


#16

Good to hear on progress.

Exceptions library not used in python3, so just remove it.

I tested those programs and they worked fine for me.
You will have to post your code to know more.


#17

Jax,
Thank you for you help.
I got the Kakute H7 to communicate with my Raspberry Pi3.
Using its port 1 (telemetry port), instead of the general serial port 4.
It seems ardupilot’s Copter’s firmware hard assigns the ports, and won’t let the assign ports be used for anything else.

On the Dronekit and Sitl front,
Attached is my “slightly modified” basic_template.py.
######## DEPENDENCIES #############

from dronekit import connect, VehicleMode,LocationGlobalRelative, APIException
from pymavlink import mavutil
import time
import socket
#import exceptions
import math
import argparse

############ FUNCTIONS #########

def connectMyCopter():

parser = argparse.ArgumentParser(description='commands')
parser.add_argument('--connect')
args = parser.parse_args()
connection_string = args.connect
if not connection_string:
	import dronekit_sitl
	sitl = dronekit_sitl.start_default()
	connection_string = sitl.connection_string()
vehicle = connect(connection_string,wait_ready=True)
return vehicle

def arm_and_takeoff(targetHeight):
while vehicle.is_armable!=True:
print(“Waiting for vehicle to become armable.”)
time.sleep(1)
print(“Vehicle is now armable”)
print(“Set Vehicle.mode = GUIDED (currently: %s)” %vehicle.mode.name)
vehicle.mode = VehicleMode(“GUIDED”)
time.sleep(1)
while vehicle.mode!=‘GUIDED’:
print(“Waiting for drone to enter GUIDED flight mode”)
print(" Mode: %s" % vehicle.mode.name)
time.sleep(1)
print(“Vehicle now is GUIDED MODE. Have fun!!”)
vehicle.armed = True
while vehicle.armed ==False:
print(“Waiting for vehicle to become armed”)
time.sleep(1)
print(“Look out! Virtual props are spinning!!”)
vehicle.simple_takeoff(targetHeight) ## meters
while True:
print(“Current Altitude: %d”%vehicle.location.global_relative_frame.alt)
if vehicle.location.global_relative_frame.alt>=.95*targetHeight:
break
time.sleep(1)
print(“Target altitude reached!!”)
return None

######### MAIN EXECUTABLE ########

vehicle = connectMyCopter()
arm_and_takeoff(10)

END OF SCRIPT

------------------------------ dronekit is causing a system error, it never actually switches to GUIDED Mode, the system keeps reporting the status as STABILIZED, and then the motors go to “ARMED” and boom!! a CRITICAL ERROR pops up more than once… --------------
gustavo@thinkpad-t430:~/drone/dk$ python basic_template.py
Starting copter simulator (SITL)
SITL already Downloaded and Extracted.
Ready to boot.
CRITICAL:autopilot:APM:Copter V3.3 (d6053245)
CRITICAL:autopilot:Frame: QUAD
CRITICAL:autopilot:Calibrating barometer
CRITICAL:autopilot:Initialising APM…
CRITICAL:autopilot:barometer calibration complete
CRITICAL:autopilot:GROUND START
Waiting for vehicle to become armable.
Vehicle is now armable
Set Vehicle.mode = GUIDED (currently: STABILIZE)
Waiting for vehicle to become armable.
Vehicle is now armable
Set Vehicle.mode = GUIDED (currently: STABILIZE)
Waiting for vehicle to become armable.
Vehicle is now armable
Set Vehicle.mode = GUIDED (currently: STABILIZE)
Waiting for drone to enter GUIDED flight mode
Mode: STABILIZE
Vehicle now is GUIDED MODE. Have fun!!
Waiting for drone to enter GUIDED flight mode
Mode: STABILIZE
Vehicle now is GUIDED MODE. Have fun!!
Waiting for drone to enter GUIDED flight mode
Mode: STABILIZE
Vehicle now is GUIDED MODE. Have fun!!
Waiting for drone to enter GUIDED flight mode
Mode: STABILIZE
Vehicle now is GUIDED MODE. Have fun!!
Waiting for drone to enter GUIDED flight mode
Mode: STABILIZE
ERROR:autopilot:ARMING MOTORS
CRITICAL:autopilot:GROUND START
Vehicle now is GUIDED MODE. Have fun!!
Waiting for drone to enter GUIDED flight mode
Mode: STABILIZE
CRITICAL:autopilot:Initialising APM…
Vehicle now is GUIDED MODE. Have fun!!
Waiting for drone to enter GUIDED flight mode
Mode: STABILIZE
Vehicle now is GUIDED MODE. Have fun!!
Waiting for drone to enter GUIDED flight mode
Mode: STABILIZE
Vehicle now is GUIDED MODE. Have fun!!
Waiting for drone to enter GUIDED flight mode
Mode: STABILIZE
Vehicle now is GUIDED MODE. Have fun!!
Waiting for drone to enter GUIDED flight mode
Mode: STABILIZE
Vehicle now is GUIDED MODE. Have fun!!
Waiting for drone to enter GUIDED flight mode
Mode: STABILIZE
Vehicle now is GUIDED MODE. Have fun!!
Waiting for drone to enter GUIDED flight mode
Mode: STABILIZE
Vehicle now is GUIDED MODE. Have fun!!
Waiting for drone to enter GUIDED flight mode
Mode: STABILIZE
Vehicle now is GUIDED MODE. Have fun!!
Waiting for drone to enter GUIDED flight mode
Mode: STABILIZE
Vehicle now is GUIDED MODE. Have fun!!
Waiting for drone to enter GUIDED flight mode
Mode: STABILIZE
ERROR:autopilot:DISARMING MOTORS
Vehicle now is GUIDED MODE. Have fun!!
Waiting for drone to enter GUIDED flight mode
Mode: STABILIZE
ERROR:autopilot:ARMING MOTORS
CRITICAL:autopilot:Initialising APM…
Vehicle now is GUIDED MODE. Have fun!!
Waiting for drone to enter GUIDED flight mode
Mode: STABILIZE
Vehicle now is GUIDED MODE. Have fun!!
Waiting for drone to enter GUIDED flight mode
Mode: STABILIZE
Vehicle now is GUIDED MODE. Have fun!!
Waiting for drone to enter GUIDED flight mode
Mode: STABILIZE
Vehicle now is GUIDED MODE. Have fun!!
Waiting for drone to enter GUIDED flight mode
Mode: STABILIZE
Vehicle now is GUIDED MODE. Have fun!!
Waiting for drone to enter GUIDED flight mode
Mode: STABILIZE
Vehicle now is GUIDED MODE. Have fun!!
Waiting for drone to enter GUIDED flight mode
Mode: STABILIZE
Vehicle now is GUIDED MODE. Have fun!!


#18

Don’t know, runs ok with me. Can’t see the true code formatting, but assume indents are ok.
The only difference I removed ‘APIExcpetion’, but I wouldn’t think that matters.


#19

May I ask you, which version of DroneKit are you running?
gustavo@thinkpad-t430:~$ pip freeze | grep -i drone
dronekit==2.9.2
dronekit-sitl==3.3.0
gustavo@thinkpad-t430:~$ pip freeze | grep -i mav
MAVProxy==1.8.49
pymavlink==2.4.29
gustavo@thinkpad-t430:~$


#20

Same as yours. If you want me to run your code, send it to jack-dronedojo@moremobileprivacy.com.


#21

Can you post your requirements.txt or requirements.in that you are using on your most updated linux version? Thanks. I’ve spent hours arguing with my python venv.


#22

Sorry for the long delay Jax.
I got tied up with actual work. I emailed you the scripts I have tried to use.
None are able to launch the Simulated Drone.


#23

I gave up on the virtual environment. no combination worked, even the same combination as the one provided in the documentation fails.
I upgraded to Ubuntu 20.04 LTS and use the latest python3 libraries. The DroneKit Software is to say it politely, in need of upgrading. And to be honest the entire video and documentation provided in these courses is so far behind, it made thing more difficult to implement, that if I just did it on my own. I literally invested hours on these for very little gains.


#24

There are a number of errors in your code, some insignificant, some significant. Once they are corrected it will work. As you know, in coding a very small thing can bring down a big thing.

The most significant, which is Reason #5 in my blog on connections, was a missing ‘tcp’ argument:

Other errors were:




#25

Hello
i am also facing the same challenge. did you identify a solution?
please help me out


#26

After reading all of the above, it would help to be more specific.