I am currently working on building an autonomous drone in the simulation middleware of Gazebo using ROS and drone programming using dronekit API.
I have an Iris Copter model available in SDF format, which I am programming using the Dronekit API. I have integrated a Hokuyo Lidar sensor on the top of the drone from which I get the distances from all the 360 degrees respectively from the ROS topic the sensor generates. In all the values that I get from 360 degrees of direction, I get around 1024 values. I only had to get the values from 90, 180, 270, and 360(or 0). After getting them I fed those values into the script I made in python and somehow made it possible for the drone to avoid obstacles using the drone kit functions that are available.
Now, the problem I am facing is with the integration of the obstacle avoidance system in the waypoint navigation system that is done using Ardupilot (using the map in Ardupilot Plugin / Mission Planner).
How do I make such a project in which the drone tends to move autonomously using GPS whilst being able to avoid obstacles that come in its path?
I agree that the firmware of Ardupilot comes with a feature of something called the Bendy Ruler Algorithm. U I have no idea how to make use of it in the simulation environment of Gazebo. The details about this feature are also not available much.
Any help on this would be really awesome for me to continue with further development of the task!
Thanks,
Sanil Jain
from pymavlink import mavutil
master = mavutil.mavlink_connection(device="tcp:127.0.0.1:5762")
master.wait_heartbeat()
poli = [(35.63604046,34.53116655),
(35.63638925,34.53209996),
(35.63584863,34.53270078),
(35.63536032,34.53252912),
(35.63520337,34.53167081),
(35.63554344,34.53127384)]
#enable fence
master.mav.command_long_send(
master.target_system,
master.target_component,
mavutil.mavlink.MAV_CMD_DO_FENCE_ENABLE, 0,
1, 0, 0, 0, 0, 0, 0)
print(len(poli))
for i in range(len(poli)):
master.mav.command_long_send(
master.target_system,
master.target_component,
mavutil.mavlink.MAV_CMD_NAV_FENCE_POLYGON_VERTEX_INCLUSION, 0,
len(poli),
1,
0,
0,
poli[i][0],
poli[i][1],
0)
master.arducopter_arm()
print("Waiting for the vehicle to arm")
master.motors_armed_wait()
print('Armed!')
This is the script I am running to connect to a drone with px4 autopilot with a USB cable in com4.
from dronekit import connect
vehicle = connect(‘com4’, wait_ready=True)
print(“connection command run”)
This is the error it continually throws:
Traceback (most recent call last):
File “C:/Users/ethan/project/DroneKit Test.py”, line 6, in
vehicle = connect(‘com4’, wait_ready=True)
File “C:\Python27\lib\site-packages\dronekitinit.py”, line 3159, in connect
handler = MAVConnection(ip, baud=baud, source_system=source_system, source_component=source_component, use_native=use_native)
File “C:\Python27\lib\site-packages\dronekit\mavlink.py”, line 130, in init
self.master = mavutil.mavlink_connection(ip, baud=baud, source_system=source_system, source_component=source_component)
File “C:\Python27\lib\site-packages\pymavlink\mavutil.py”, line 1777, in mavlink_connection
force_connected=force_connected)
File “C:\Python27\lib\site-packages\pymavlink\mavutil.py”, line 935, in init
import serial
ImportError: No module named serial
I would really appreciate your help with this. I have been stuck at trying to connect to my drone for over a month. Also, if you have an alternative to dronekit that could you point me in the right direction and maybe include sample code to connect to the drone? Thank you!
Also there are most likely updates in the libraries, eg pymavlink where the newest version is compatible with ardupilot
Not speaking of security related updates and so on
Arducopter as well as arduplane both use mavlink
While some mavlink commands are the same for both others are not, I'm not sure which one are the same but you can look that up in the ardupilot documentation
I would expect that some features might work and others do not depending on the specific mavlink command
I'm not sure if there's any lib similar to dronekit but for arduplanes (I suppose you're using arduplane?), However you can write it yourself with pymavlink which is a generated (based on a c lib) mavlink wrapper in python
This is also what dronekit uses internally, it's just not as human readable as dronekit is
Be warned it's quite tedious but completely possible
Hello! I am trying to send a command to change the state of my hardware safety switch. I have found this definition:
self.master.mav.set_mode_send(self.target_system,
mavutil.mavlink.MAV_MODE_FLAG_DECODE_POSITION_SAFETY,
1)
But I need to construct the message using dronekit, how would I do this
Issue details
Unable to pull (obtain) GPS lat/long info on Raspberry Pi (RPi) using DroneKit SDK's API: vehicle.location.global_relative_frame from HolyBro Pixhawk 6C. Exact same .py script to pull this GPS info on RPi with same firmware version, GPS and other related setup parameters work with HolyBro Pixhawk 4 + RPi but it DOES NOT work with Pixhawk 6C + RPi. I can obtain vehicle.mode info from Pixhawk 6C on RPi but not vehicle.location.global_relative_frame info which provides GPS lat/long information on RPi from Pixhawk 6C; the output for lat/long remains blank. There seems to be a bug preventing this API to pull lat/long info from Pix6C with rover-stable-4.2.3 firmware. Just FYI: I'm upgrading my rover from HolyBro Pix4 to Pix6C. RPi <-> Pix6C connection setup: USB to micro-USB.
Version
ArduRover stable-4.2.3
Platform
[ ] All
[ ] AntennaTracker
[ ] Copter
[ ] Plane
[X] Rover
[ ] Submarine
Airframe type
X
Hardware type
Pixhawk 6C
Any idea what might the issue here? Thank you for your time and help in advance!
hi, i'm writing a simple script for a drone to take off 20m into the air, and i'm simulating on dronekit-sitl
but for some reason, it is lifting it up only by less than or equal to 3cm
i don't know what i can do to fix this, can someone please help?
```import dronekit
from dronekit import connect, VehicleMode
import time
vehicle = connect('tcp:127.0.0.1:5760', wait_ready=True)
def goSomewhere(target_altitude):
print("pre arming checks")
while not vehicle.is_armable:
print("waiting for vehicle to initialise")
time.sleep(1)
print("arming motors")
vehicle.mode = VehicleMode("GUIDED")
while not vehicle.armed:
vehicle.armed = True # commands to change a value are NOT GUARANTEED TO SUCCEED therefore put in a loop
print("arming...")
time.sleep(1)
if (vehicle.armed):
print("armed")
vehicle.simple_takeoff(target_altitude)
while True:
print(" Altitude: ", vehicle.location.global_relative_frame.alt)
# Break and return from function just below target altitude.
if vehicle.location.global_relative_frame.alt >= target_altitude * 0.95:
print("Reached target altitude")
break
time.sleep(1)
goSomewhere(30)
```