Dronekit-python running in docker connecting to MAVProxy on host
I am using dronekit-python in a docker container and am attempting to connect to an instance of MAVProxy running on my host machine (Mac OSX) using the following command:
vehicle = connect('udp:host.docker.internal:14551', wait_ready=True)
but am getting the following error:
File "/usr/local/lib/python3.7/site-packages/pymavlink/mavutil.py", line 1015, in __init__ self.port.bind((a, int(a))) OSError: [Errno 99] Cannot assign requested address
Does anyone know what the issue is here? I am able to successfully connect using the above command when I run the python script locally on host but not when I have it running in a docker container.
I found a similar stackoverflow question here but the accepted answer did not work for me. Not sure if I need to be exposing ports or something like that.
Here is the command that I am running on my host machine to kick off MAVProxy:
mavproxy.py --master=127.0.0.1:14550 --out udp:127.0.0.1:14551 --out udp:10.55.222.120:14550 --out udp:127.0.0.1:14552
I ended up getting MAVProxy on host and dronekit-python in the docker flask container properly connected.
Seemus790's answer in this gitter thread did the trick.
Working solution: MAVProxy on host machine (Mac OS in my case)
mavproxy.py --master=127.0.0.1:14550 --out udp:127.0.0.1:14551 --out udp:10.55.222.120:14550 --out=tcpin:0.0.0.0:14552
dronekit-python command in docker container:
vehicle = connect('tcp:host.docker.internal:14552', wait_ready=True)
The trick was the --out=tcpin:0.0.0.0:14552 part of the mavproxy command which is documented here
See also questions close to this topic
Tokenize don't to dont using NLTK Python
When I use:
What I want is:
Python3: What is a better practice: loop = False or break
In python, is it a better practice (more readable/efficient) to exit a while loop by setting the while loop's looping variable to
Falseor by doing a
I've seen many other questions like this but in different languages.
Is there an archive file format that allows you to write, overwrite, and delete files?
I'm looking to combine multiple files into one archive (or something similar) but in a way that would allow me to write files, overwrite files, and delete files.
For example, the contents might look like this:
my-archive/ info.json files/ file1.json file2.json file2.json
I'm using Python and I've looked into
zipfilebut neither one would allow me to overwrite or delete specific files.
Is there any existing file format you could suggest or is it something I'd have to create myself?
I would only be working with text files, if that changes anything.
MongoDb in Azure Container Instance Fails after some time
I have mongoDB running in Azure Container Instance. DB run constantly and it was OK, but it happens 2 times that container went in Failed state. The Fail state happened in time range of one month. This is my Dockefile:
FROM ubuntu:xenial # Update the repository sources list RUN apt-get update && apt-get install -y wget gnupg apt-transport-https ca-certificates vim #Import GPG Key from https://www.mongodb.org/static/pgp/server-4.2.asc: RUN wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | apt-key add - #Create a list file /etc/apt/sources.list.d/mongodb-org-4.2.list for MongoDB RUN echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.2 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-4.2.list #Install the latest stable version of MongoDB RUN apt-get update && apt-get install -y mongodb-org RUN mkdir -p /data/db # Expose the default port EXPOSE 27017 CMD ["--port 27017", "--smallfiles"] # Set default container command and overwrite default address 127.0.0.1 with 0.0.0.0 ENTRYPOINT usr/bin/mongod --bind_ip 0.0.0.0
I don't have logs, so I believe it's hard to say what is the cause, but is there some reason why container fails looking on Dockerfile? The DB container must run without interruptions, so this is quite critical issue.
Best practice of performance and security in deployment
I have a general question. What is the best practices of security and performance on a deployment? If I want to specific it to a technology I can said Kubernetes and Docker and AWS. I know it is very general question But It help me a lot.
How to create a Docker container GitHub Action to provide executable for the main workflow?
I want to implement my own Docker GitHub Action that should provide an executable called
my-toolwhich I can use in my workflows. Ideally, I want to be able to write the following config in my workflow:
- name: Setup My Tool uses: actions/my-tool@v1 - name: Run My Tool run: my-tool --option1 --option2 arg1 arg2
My custom action that provides
my-toolis responsible for creating the
my-toolexecutable (either by downloading it or building from sources). And I want my action to make this executable available within the rest of my workflow. However, I can't find any way to copy my executable from the docker container back to host that runs my action. How can I transfer
my-toolfrom the Docker GitHub Action to my workflow?
Aborting & updating current waypoint with DroneKit
I'm new to drone programming & DroneKit-Python but have been reading up on the docs, watching tutorials, & trying out some scripts with the SITL sim drone.
I want to be able to continuously give my drone new waypoint information real-time while aborting the current waypoint. What I find in the docs require the current waypoint to be reached before going to the next. I would like to abort the current waypoint entirely and immediately go to the new waypoint.
The application here is to be able to navigate to a moving target based on its current lat/long location. I found this example in the docs which somewhat resembles what I would like to do. However, it appears to me that this program must finish the current waypoint before going to the next.
Is this an unreasonable request? How would I implement something like this? Would it be possible to update the current waypoint say every 0.5-1 seconds? Is there a better way?
Is ea.chine brand drone compatible with the dronekit sdk?
I want to buy a eachine racing drone but I want to know beforehand if it is compatible to program with the dronekit sdk.
How to efficiently connect to a vehicle through multiprocessing and MAVLink/dronekit-python?
I'm trying to automate the flight of a drone through computer vision with python. The system acquire images, detect a target and control a camera stabilizer (servos) accordingly to keep the target at the center of the frame. I'm working on a Jetson Nano and use dronekit to send appropriate MAVLink messages to the drone through a PixHawk board. I use the python 3.6 and the multiprocessing module to run 3 processes:
- Image taking and target detection
- PID calculation (error between center of target and center of frame)
- Sending PWM value (output of the PID) to servos to control the heading of the camera. The PWM is outputted by the PixHawk itself, through its AUX Port 9.
I connect to my drone in the main(). It creates the object 'vehicle' from which I can access the vehicle parameters. My PWM process continuously sends PWM values through the MAVLink message "SET_SERVO" that needs the "vehicle" object to work. I know that processes don't share the same memory space, that's why I use Managers.
My problem is that I think the "vehicle" object is correctly shared (with a NameSpace), but the PWM output is very random. Sometimes there is a PWM output, sometimes not. Sometimes the code is working fine, and after the next reboot it's not anymore... The connection is always successful though. I really don't understand what is the problem. I suspect I made a mistake in the multiprocessing use because continuously sending "SET_SERVO" command directly through main works. The object seems to be shared sometimes only...
Parts of my code below: -the function used to send the PWM message, the PWM process and the main()-
def send_pwm(servo_channel, pwm, cible): msg = cible.message_factory.command_long_encode(0, 0,#target_system #target_component mavutil.mavlink.MAV_CMD_DO_SET_SERVO, #command 0, # confirmation servo_channel, #servo number pwm, #servo position between 1000 and 2000 0, 0, 0, 0, 0) #params 3 ~ 7 not used cible.send_mavlink(msg) """PROCESS - GIMBALL MANAGER - Send PWM to the Gimbal to keep the camera pointing toward the target""" def set_gimbal(pwm, SWEEPING_FLAG, EXIT_FLAG, magic): send_pwm(9, 1500, magic) # Initializes camera in neutral position while True: # If it is time to shut down with EXIT_FLAG.get_lock(): if EXIT_FLAG.value == 1: break value = pwm.value if SWEEPING_FLAG.value == False: if(value < 1260): value = 1260 if(value > 1740): value = 1740 send_pwm(9, value, magic) elif SWEEPING_FLAG.value == True: value = 1500 send_pwm(9, value, magic) def main(): global vehicle, EXIT_FLAG '''Managers enable data to be shared between processes''' with Manager() as manager: # Set EXIT_FLAG EXIT_FLAG = Value('i',0) # Set SWEEPING_FLAG as boolean, initialized at False SWEEPING_FLAG = manager.Value("b", False) # Set pwm as float, initialized at 1500 pwm = manager.Value("i", 1500) # Set objY and ObjX as int, initialized at 0 objY = manager.Value("i", 0) objX = manager.Value("i", 0) # Set PID values for the Pitch k_P = manager.Value("f", 1.0) #1 1.5 k_I = manager.Value("f", 0.1) #0.1 1.0 k_D = manager.Value("f", 0.1) #0.1 2.5 # Set integer values for the object center (x, y)-coordinates centerX = manager.Value("i", 0) centerY = manager.Value("i", 0) # ~ time.sleep(5) '''Connecting to the vehicle''' drone_path = '/dev/ttyACM0' print("\n[INFO] - Connecting to vehicle...\n") vehicle = connect(drone_path, wait_ready = True) print("\n[INFO] - [CONNECTED] \n") time.sleep(5) magic = manager.Namespace() magic = vehicle # We have 3 processes # 1. image_process : find/locate the object # 2. pid_process : PID control loop that determines pitch angle # 3. set_gimbal : drives the gimbal to proper angles based on PID feedback to keep object in center processObjectLocator = Process(target = image_process, args = (args,objX,objY,SWEEPING_FLAG,centerX,centerY,pwm, EXIT_FLAG)) processPitching = Process(target = pid_process, args = (pwm, k_P, k_I, k_D, objY,centerY, EXIT_FLAG)) processSetGimbal = Process(target = set_gimbal, args = (pwm,SWEEPING_FLAG, EXIT_FLAG, magic)) # ~ # Start processes print("\n[INFO] - GIMBAL PROCESS") processSetGimbal.start() print("\n[INFO] - PID PROCESS") processPitching.start() print("\n[INFO] - IMAGE PROCESS") processObjectLocator.start() # Main control loop while True: # If it is time to shut down with EXIT_FLAG.get_lock(): if EXIT_FLAG.value == 1: break # Join processes processSetGimbal.join() processPitching.join() processObjectLocator.join() # ~ vehicle.close() # ~ magic.close() # ~ time.sleep(2) exit() if __name__ == '__main__': main()
Mavproxy + mission planner + dronekit with no companion computer
I’m trying to connect mavproxy, mission planner and dronekit to my hexa. i am not using a companion computer my setup is as follows: i have a pc running windows for mission planner and on that same pc im running a virtual machine with ubuntu 16.04 running dronekit and mavproxy.
first I'm running mavproxy and forking out 2 connections, 1 for mission planner and one for dronekit with the following code:
mavproxy.py --master=/dev/ttyUSB0(I'm telling mavproxy to use the serial which the telemetry dongle is connected to) --baudrate=57600 --out=127.0.0.1:14551(ip address on my virtual ubuntu) --out=10.0.0.7:14550 (IP for my windows machine)
I am able to connect to the drone in mission planner via the UDP at port 14550. and I am able to send commands via mavproxy console such as change modes/arm etc.
my problem is when I execute my connect script from dronekit to connect to the drone I'm getting a timeout error.
from dronekit import connect, VehicleMode, LocationGlobalRelative import time import argparse parser = argparse.ArgumentParser(description = ‘commands’) parser.add_argument(’–connect’) args =parser.parse_args() connection_string = args.connect vehicle = connect(connection_string ,wait_ready=True)
when I open a new terminal I run the command to launch and connect drone kit
python connect.py --connect 127.0.0.1:14551
once I run this it gets stuck and after 30 seconds I get the following output:
dronekit.TimeoutError: wait_ready experienced a timeout after 30 seconds.
sometimes I get the following output:
gcs failsafe cleared
and then it gets stuck and after 30 seconds:
dronekit.APIException: Timeout in initializing connection.
I searched for about 3 days for solutions and tried everything that is out there pretty much, such as telling dronekit to wait longer than 30 seconds, but still, I get the same error. I updated dronekit to the latest version, updated pymavlink and pyserial. also downgraded them to check if it will solve this but nothing works.
my main question is: is this error happening because dronekit can only run on a companion computer? and is not built for connecting threw telemetry radio? if not, what am I doing wrong?
I sincerely am lost and praying that someone can help me. thanks in advance. I would literally pay someone for a solution.
and again, sorry for the double post.