Ubuntu 18.04.6 (course build); "Launch QGC with DK script part3" mode GUIDED loop hanging (launchSitl basic_template.py)


#1

Having issues with the Ubuntu 18.04.6 build

-(will prob just roll with the updated):
Full gz sim on 22.04 LTS - Drone Talk - Drone Dojo (dojofordrones.com)

Was really attempting to see if I made any missteps in setup; but I tried every angle I could see (through following forum threads)

Thank you all for the hard work and dedication!

ASSESSMENT:

Build based on course

VBox 7.0

Ubuntu 18.04.6
-with Guest Additions

gcc 7.5.0
g++ 7.5.0

repo:

-(attempted/failed)

~/courseRoot/apm$ git clone -p Copter-4.0.3 (did not work; see forum)

#####################################################################

-NOTE:
(The following worked up to “Script to Auto Launch QGC with DKScript part3”)

(dksitl) @:~/courseRoot/dk$ launchSitl basic_template.py

-[Resulted in same issue as mode_setter.py]

-SEE:

#####################################################################

repo:

~/courseRoot/apm/ardupilot$ git clone -p Copter-4.0.6 git@github.com:ArduPilot/ardupilot

~/courseRoot/apm/ardupilot$ git submodule update --init --recursive

~/courseRoot/apm/ardupilot$ Tools/environment_install/install-prereqs-ubuntu.sh -y

~/courseRoot/apm/ardupilot/ArduCopter$ . …/Tools/autotest/sim_vehicle.py --map --console

#####################################################################

-Dependencies:

dronekit==2.9.1
-(also tried 2.9.2)
dronekit-sitl==3.3.0
MAVProxy==1.6.2
-(also tried 1.8.17 and 1.8.34)
pymavlink==2.0.6
-(also tried 2.4.40 and 2.4.8)

-NOTE: ^^ (dksitl) ~/courseRoot/dk$ python basic_template.py

-WORKS WITH BOTH MAVProxy==1.6.2 (and 1.8.17)

-the issue seems to be with launchSitl executing the .py scripts (script represented by '$1' in the launchSitl script).

-SEE: launchSitl

-ERROR: (“Waiting for drone to enter GUIDED flight mode” hanging up)

^^ see mode_setter.py issue (

-NOTE: I built virtualenv using:

$ virtualenv -p /usr/bin/python2.7 --system-site-packages dksitl

-(as per the course)

-NOTE: I used QGC 4.0.10 (and attempted 4.0.3)
-both did not resolve issue
)

#####################################################################

-SEE:


repo:

~/courseRoot/apm/ardupilot$ git clone -p Copter-4.0.6 git@github.com:ArduPilot/ardupilot

~/courseRoot/apm/ardupilot$ git submodule update --init --recursive

~/courseRoot/apm/ardupilot$ Tools/environment_install/install-prereqs-ubuntu.sh -y

~/courseRoot/apm/ardupilot/ArduCopter$ . …/Tools/autotest/sim_vehicle.py -f gazebo-iris

-RESULT:

Framework to start a simulated vehicle and connect it to MAVProxy.

Peter Barker, April 2016
based on sim_vehicle.sh by Andrew Tridgell, October 2011
: command not found
from: can’t read /var/mail/future
import-im6.q16: not authorized atexit' @ error/constitute.c/WriteImage/1037. import-im6.q16: not authorizederrno’ @ error/constitute.c/WriteImage/1037.
import-im6.q16: not authorized optparse' @ error/constitute.c/WriteImage/1037. import-im6.q16: not authorizedos’ @ error/constitute.c/WriteImage/1037.
import-im6.q16: not authorized re' @ error/constitute.c/WriteImage/1037. import-im6.q16: not authorizedsignal’ @ error/constitute.c/WriteImage/1037.
import-im6.q16: not authorized subprocess' @ error/constitute.c/WriteImage/1037. import-im6.q16: not authorizedsys’ @ error/constitute.c/WriteImage/1037.
import-im6.q16: not authorized tempfile' @ error/constitute.c/WriteImage/1037. import-im6.q16: not authorizedtextwrap’ @ error/constitute.c/WriteImage/1037.
import-im6.q16: not authorized time' @ error/constitute.c/WriteImage/1037. import-im6.q16: not authorizedshlex’ @ error/constitute.c/WriteImage/1037.
from: can’t read /var/mail/pymavlink
from: can’t read /var/mail/pysim
windowID: command not found
bash: …/Tools/autotest/sim_vehicle.py: line 32: syntax error near unexpected token (' bash: ../Tools/autotest/sim_vehicle.py: line 32:class CompatError(Exception):’

#####################################################################

-NOTE: I am not experiencing a heartbeat timeout error
but rather am experiencing the .py script getting hung up at the GUIDED mode Loop.
-(WHEN USING launchSitl script to run .py (’$1’) scripts).


#2

I was able to get past the GUIDED mode infinite loop by writing my basic_template.py script as such

Emphasizing:

Vehicle.mode = VehicleMode(“GUIDED”)

-rather than:

vehicle.mode = VehicleMode(“GUIDE”)
-[as this causes the infinite loop]

  • for some reason the script prefers this (maybe there is an issue in the Dronekit implementation of classes/attributes that causes it to be uppercase for some attributes and lowercase for others)?

I am now working on preventing the following errors:

ERROR:autopilot:ARMING MOTORS
ERROR:autopilot:DISARMING MOTORS
Current Altitude: 0

-(as per the lines):

vehicle.armed = True
while vehicle.armed==False:
print(“Waiting for vehicle to become armed!: %s” % vehicle.armed)
time.sleep(1)
print(“Look out! Virtual props are spinning!!: %s” % vehicle.armed)
time.sleep(2)

-it shows True then ends up False due to the above errors ^^

-resulting in an infinite loop at the lines:

   vehicle.simple_takeoff(targetHeight) ##meters

while True:
	print("Current Altitude: %d"%vehicle.location.global_relative_frame.alt)

#3

launchSitl script:

#!/bin/bash

kill -9 $(ps -eF | grep QG | awk -F ’ ’ ‘{print $2}’) > /dev/null 2>&1

kill -9 $(ps -eF | grep ardu | awk -F ’ ’ ‘{print $2}’) > /dev/null 2>&1

kill -9 $(ps -eF | grep mav | awk -F ’ ’ ‘{print $2}’) > /dev/null 2>&1

kill -9 $(ps -eF | grep apm | awk -F ’ ’ ‘{print $2}’) > /dev/null 2>&1

##Launch a SITL instance

/usr/local/bin/dronekit-sitl copter --home=44.5013,-88.0622,0,180&

#/home/greap/courseRoot/apm/ardupilot/build/sitl/bin/arducopter -S -I0 --home=44.5013,-88.0622,0,180 --model “+” --speedup 1 --defaults

#/home/greap/courseRoot/apm/ardupilot/Tools/autotest/default_params/copter.parm &

sleep 30

##Launch QGroundControl

/usr/local/bin/QGC.AppImage 2>/dev/null&

sleep 40

##Start MAVProxy

screen -dm mavproxy.py --master=tcp:127.0.0.1:5760 --out=127.0.0.1:14550 --out=127.0.0.1:5762

sleep 30

##Launch the dronekit-python script

/usr/bin/python “$1” --connect 127.0.0.1:5762

function finish {

kill -9 $(ps -eF | grep QG | awk -F ’ ’ ‘{print $2}’) > /dev/null 2>&1

kill -9 $(ps -eF | grep ardu | awk -F ’ ’ ‘{print $2}’) > /dev/null 2>&1

kill -9 $(ps -eF | grep mav | awk -F ’ ’ ‘{print $2}’) > /dev/null 2>&1

kill -9 $(ps -eF | grep apm | awk -F ’ ’ ‘{print $2}’) > /dev/null 2>&1

}

trap finish EXIT


#5

basic_template.py (in .txt format)basic_template.txt (1.7 KB)


#6

There is a lot here. Perhaps you can list your questions in a simple fashion.

Also see this post:
https://community.dojofordrones.com/t/mode-setter-py-getting-hung-up-on-waiting-for-guided-mode/138/7


#7

I am referencing all forums that I have searched through in order to find a solution.

As well as giving the steps/specs that I attempted to use (following the course then searching forum threads for possible solutions).

I mentioned the post you provided in my post.

Dunno at this point maybe I will figure it out, maybe I won’t.

My question is why the infinite loop occurs when using dronekit to execute the python script?

launchSitl basic_template.py

-when I use python basic_template.py it processes the script just fine.

Is it an issue with the dronekit API, MAVProxy, or the SITL vehicle itself?


#8

I explored this issue earlier this year with another member. As you note, you can run the .py file no problem separately. There is an issue with the bash file and I think it has something to do with current pymavlink and dronekit-sitl compatibility. This is mentioned in the course and why virtualenv is used. But I also think there is an issue with the current version of ardupilot and why virtualenv might not solve the issue. You can try reverting back to all the older versions and see what happens. But there is an easier way using current versions and without using virtualenv which you seem to have already started.

In your launchSitl file try commenting out the dronekit-sitl instance and uncommenting the next line, remembering to add a ‘&’ at the end. Also don’t change ‘v’ to ‘V’ in the py script. That should solve the issue.


#9

Thank you, will keep testing.

I attempted to revert Ubuntu 18.04 (manually rather than using pre-configured image). followed the steps according to the course.

Maybe there is an issue with how virtualenv sets/utilizes the seed packages [pip, setuptools, wheel])? Will continue to investigate.

Will attempt downgrade to Ubuntu 16.04 (per course) and attempting python2 solution again.

Will try 20.04 solution

I found this
(
(
A potential fix could be downgrading pymavlink to 2.4.8
Try
pip uninstall pymavlink
then
pip install pymavlink==2.4.8

Usage of pip command depends on your environment setup defaults, I assume you’re on python 2.7 as you mentioned.

Another observation - If you’re using python 3 , the above workaround might not work with python 3.7+, will work with upto python 3.6

All credit to @Git-Ilan and @Nilasstohr for pointing this out at #1083

EDIT: I was using Windows Platform, didn’t ever test it on linux

at Dronekit-Sitl " Error Disarming Motors " ¡ Issue #1058 ¡ dronekit/dronekit-python ¡ GitHub
)
)

in terms of the .py script (changing ‘v’ to ‘V’)
-this was the only way that the VehicleMode would transition from “STABILIZE” to “GUIDED”.
-I am not sure as to why but I tried keeping it lowercase (resulting in an infinite loop at that call).

Thank you for your help and work.


#10

When I said to use older versions I mistakenly thought you were on a newer version. It should work on 18.04.

I am using python3 and all current versions of ubuntu, ardupilot and all dependencies. As you found earlier, I am successfully exploring all current versions of ROS and Gazebo.
I am using a linux guest machine installed on a virtualbox Windows 11 host.
If you need more help installing the basic structure see this.


#11

I’ve tried 18.04 (most likely me misconfiguring)
-i’ll retry and make sure I am not missing steps in configuring dependencies/virtualenv

22.04 (your recommendation is working fine) for ROS/Gazebo

I will attempt 20.04 to see what works best for me.

Thank you so much.


#12

Try first without virtualenv.