Read and write parameter

Hi everyone,

I would like to automate some tests in HITL using MAVSDK.
For this I would like to read and write the parameters.

I started from the example takeoff_and_land, and I added the following line of code:

  • #include <mavsdk/plugins/param/param.h>, at the top of the file
  • auto param = std::make_shared<Param>(system); right after the declaration of telemetry and action
  • std::pair<Param::Result, float> result = param->get_param_float("MIS_TAKEOFF_ALT"); to read the parameter MIS_TAKEOFF_ALT
  • if (result.first != Param::Result::Success) {return 1}; and stop the program if it fails.

after a make command, I get the following errors

  • undefined reference to mavsdk::Param::get_param_float(), but I included param.h

@JulianOes any tips ? or any example code to read/write parameters ?

Thanks,

Romain

(full make command output)

Scanning dependencies of target takeoff_and_land
[ 50%] Building CXX object CMakeFiles/takeoff_and_land.dir/takeoff_and_land.cpp.o
[100%] Linking CXX executable takeoff_and_land
CMakeFiles/takeoff_and_land.dir/takeoff_and_land.cpp.o: In function `main':
takeoff_and_land.cpp:(.text+0xa24): undefined reference to `mavsdk::Param::get_param_float(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) const'
CMakeFiles/takeoff_and_land.dir/takeoff_and_land.cpp.o: In function `void __gnu_cxx::new_allocator<mavsdk::Param>::construct<mavsdk::Param, mavsdk::System&>(mavsdk::Param*, mavsdk::System&)':
takeoff_and_land.cpp:(.text._ZN9__gnu_cxx13new_allocatorIN6mavsdk5ParamEE9constructIS2_JRNS1_6SystemEEEEvPT_DpOT0_[_ZN9__gnu_cxx13new_allocatorIN6mavsdk5ParamEE9constructIS2_JRNS1_6SystemEEEEvPT_DpOT0_]+0x48): undefined reference to `mavsdk::Param::Param(mavsdk::System&)'
collect2: error: ld returned 1 exit status
CMakeFiles/takeoff_and_land.dir/build.make:97: recipe for target 'takeoff_and_land' failed
make[2]: *** [takeoff_and_land] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/takeoff_and_land.dir/all' failed
make[1]: *** [CMakeFiles/takeoff_and_land.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

undefined reference means that the symbol is not found during linking. This means that you are not linking to the param plugin that you are trying to use.

You need to add mavsdk_param here:

Also see: https://mavsdk.mavlink.io/develop/en/guide/toolchain.html#sdk_installed_system_wide

Yes, that works, thank you for this quick reply!

1 Like