How to set mission mode in application in Pixhawk?

#1

Hello,
I’m using PX4/Firmware v1.8.2. I want to write an application based on it to set mission items and set the drone to mission mode. Is it possible to use an application to set the drone to mission mode and execute a mission based on the mission items generated in this application?

#2

Yes, have a look at the Dronecode SDK:
https://sdk.dronecode.org/en/

Especially, check out the mission plugin.

What is the platform you would use that? On a companion computer onboard the drone, or an Android or iOS device, or a desktop computer?

#3

@JulianOes Thank you for your reply. But I’m going to use just Pixhawk. I want to write an application like what is shown in https://dev.px4.io/en/apps/hello_sky.html.

#4

Ok, in that case you could look into how to create mission items and save them to the dataman (plus publish to uorb that a new mission is available). It would be in a similar way as done by mavlink:

It won’t be straightforward and you’ll have to learn quite a bit how PX4 internals work.

What are you trying to achieve actually? Maybe there is an easier way.

#5

@JulianOes I want the drone to receive target GPS position data via a serial port, then set the GPS points as mission items and fly in mission mode.

#6

Ok, why don’t you just set the GPS points as a mission over serial (using MAVLink and/or the Dronecode SDK) ?

#7

@JulianOes I’m not familiar with MAVLink protocol. I’ll get to learn about MAVLink. I’m using LoRa module to receive data sent from another LoRa module. I don’t use the Dronecode SDK because this drone will not be equipped with a companion computer. Should I follow the tutorial in https://mavlink.io/en/getting_started/ if I’m going to use MAVLink?

#8

How are you receiving the format in the LoRa module? And what is running on the LoRa module, I assume it’s also a small embedded environment?

#9

@JulianOes I’ll connect the LoRa module to PIxhawk via UART4/5. And then start an application in Pixhawk to initialize the serial port (LoRa) to receive data.

#10

Ok, so LoRa is essentially a serial bridge? In which case you can talk MAVLink through it?

#11

Hello excuseme, i have problemas with the install software.
I have Windows 10 32 bits and the install not accept the visual studio.

#12

Excuseme its win 64 bits

#13

I dont speak english

#14

@CarlosHMR please open a new thread for your issue. Also, you need to add more detail and copy paste output, otherwise it’s impossible to help you.

#15

thank you very much for your attention.

According to this instructions, gRPC server have to be build and run at the beginning, and it’s exactly right there where I have a problem, because the commands “make BUILD_BACKEND=1” and “make default” (the last one is taken of this instructions) show me up the next result:

-- The C compiler identification is GNU 7.3.0
-- The CXX compiler identification is GNU 7.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found CURL: /usr/lib/x86_64-linux-gnu/libcurl.so (found version "7.58.0") 
CMake Error at cmake/tinyxml2.cmake:19 (add_subdirectory):
  The source directory

    /home/manriver/DronecodeSDK/third_party/tinyxml2

  does not contain a CMakeLists.txt file.
Call Stack (most recent call first):
  CMakeLists.txt:34 (include)


CMake Error at cmake/zlib.cmake:6 (add_subdirectory):
  The source directory

    /home/manriver/DronecodeSDK/third_party/zlib

  does not contain a CMakeLists.txt file.
Call Stack (most recent call first):
  CMakeLists.txt:35 (include)


CMake Error at cmake/zlib.cmake:11 (set_property):
  set_property could not find TARGET zlibstatic.  Perhaps it has not yet been
  created.
Call Stack (most recent call first):
  CMakeLists.txt:35 (include)


CMake Error at CMakeLists.txt:39 (include):
  include could not find load file:

    third_party/cpp_rsc/cmake/modules/cpp_resource.cmake


CMake Error at CMakeLists.txt:42 (add_subdirectory):
  add_subdirectory given source "third_party/cpp_rsc/src" which is not an
  existing directory.


-- Version: 0.15.0-dirty
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
CMake Error at plugins/camera/CMakeLists.txt:2 (add_resource):
  Unknown CMake command "add_resource".


-- Configuring incomplete, errors occurred!
See also "/home/manriver/DronecodeSDK/build/default/CMakeFiles/CMakeOutput.log".
See also "/home/manriver/DronecodeSDK/build/default/CMakeFiles/CMakeError.log".
Build dir: build/default
/bin/sh: 1: cd: can't cd to build/default
Makefile:85: recipe for target 'default' failed
make: *** [default] Error 2

As it says at the end, there is more information about the issue in “CMakeError.log” file, but that file doesn’t exists as “default” folder is always empty. My computer works with Ubuntu 18.04.2 LTS so I’ve tried to build it with Docker but I have got the same issue.

I really appreciate your help, I have seen a lot of good projects interesting projects developed by PX4 dronecode and I’d like to start my own projects. I’m sorry about my English.

#16

Please next time create a new post.

For your problem, have you tried: git submodule update --init --recursive?

#17

@JulianOes
I tried as shown in https://github.com/PX4/Firmware/blob/master/src/examples/bottle_drop/bottle_drop.cpp to try to set mission items and set vehicle to mission mode.

Code

    struct mission_item_s flight_wp_1 {};
    struct mission_item_s flight_wp_2 {};
    struct mission_item_s flight_wp_3 {};

    flight_wp_1.nav_cmd = NAV_CMD_DO_LAND_START;
    flight_wp_1.autocontinue = true;
    flight_wp_1.altitude_is_relative = true;
    flight_wp_1.acceptance_radius = 1; // meter
    flight_wp_1.loiter_radius = 1; // meter
    flight_wp_1.lat = 47.3979568; // degree
    flight_wp_1.lon = 8.5457124; // degree
    flight_wp_1.altitude = 5; // meter

    flight_wp_2.nav_cmd = NAV_CMD_WAYPOINT;
    flight_wp_2.autocontinue = true;
    flight_wp_2.altitude_is_relative = true;
    flight_wp_2.acceptance_radius = 1; // meter
    flight_wp_2.loiter_radius = 1; // meter
    flight_wp_2.lat = 47.3979415; // degree
    flight_wp_2.lon = 8.545413; // degree
    flight_wp_2.altitude = 5; // meter

    flight_wp_3.nav_cmd = NAV_CMD_TAKEOFF;
    flight_wp_3.autocontinue = true;
    flight_wp_3.altitude_is_relative = true;
    flight_wp_3.acceptance_radius = 1; // meter
    flight_wp_3.loiter_radius = 1; // meter
    flight_wp_3.lat = 47.3979415; // degree
    flight_wp_3.lon = 8.545413; // degree
    flight_wp_3.altitude = 5; // meter

    const ssize_t len = sizeof(struct mission_item_s);
    
    if(dm_write(DM_KEY_WAYPOINTS_ONBOARD, 0, DM_PERSIST_IN_FLIGHT_RESET, &flight_wp_1, len) != len){
        warnx("ERROR: could not save onboard WP");
    } else {
        warnx("waypoint 1 in dataman");
    }

    if(dm_write(DM_KEY_WAYPOINTS_ONBOARD, 0, DM_PERSIST_IN_FLIGHT_RESET, &flight_wp_2, len) != len){
        warnx("ERROR: could not save onboard WP");
    } else {
        warnx("waypoint 2 in dataman");
    }
    if(dm_write(DM_KEY_WAYPOINTS_ONBOARD, 0, DM_PERSIST_IN_FLIGHT_RESET, &flight_wp_3, len) != len){
        warnx("ERROR: could not save onboard WP");
    } else {
        warnx("waypoint 3 in dataman");
    }

    _onboard_mission.timestamp = hrt_absolute_time();
    _onboard_mission.count = 3;
    _onboard_mission.current_seq = 0;

    if(_onboard_mission_pub != nullptr){
        orb_publish(ORB_ID(mission), _onboard_mission_pub, &_onboard_mission);
    } else {
        _onboard_mission_pub = orb_advertise(ORB_ID(mission), &_onboard_mission);
    }

Then I ran a SITL simulation but errors occurred.

pxh> condor_mission start
pxh> WARN  [condor_mission] waypoint 1 in dataman
WARN  [condor_mission] waypoint 2 in dataman
WARN  [condor_mission] waypoint 3 in dataman
WARN  [navigator] Mission rejected: Cannot access SD card
ERROR [navigator] dataman read failure
ERROR [navigator] mission check failed

How could I solve this?

#18

Thanks for the nice minimal example. This looks all correct to me. Were you able to do some debugging in the meantime? Have you tried using storage 1 instead of 0?