Skip to content

Commit

Permalink
Merge pull request #1703 from ykhedar/apm-devel
Browse files Browse the repository at this point in the history
param: changes for making param set/get work with ArduPilot
  • Loading branch information
julianoes authored Apr 13, 2022
2 parents 790e793 + 6be007a commit 0c13d0f
Show file tree
Hide file tree
Showing 6 changed files with 909 additions and 463 deletions.
66 changes: 66 additions & 0 deletions src/integration_tests/param.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "integration_test_helper.h"
#include "mavsdk.h"
#include "plugins/param/param.h"
#include <map>

using namespace mavsdk;

Expand Down Expand Up @@ -123,3 +124,68 @@ TEST_F(SitlTest, PX4ParamHappy)
EXPECT_FLOAT_EQ(get_result3.second, get_result1.second);
}
}

TEST_F(SitlTest, GetAllParams)
{
Mavsdk mavsdk;

ConnectionResult ret = mavsdk.add_udp_connection();
ASSERT_EQ(ret, ConnectionResult::Success);

// Wait for system to connect via heartbeat.
std::this_thread::sleep_for(std::chrono::seconds(2));

ASSERT_EQ(mavsdk.systems().size(), 1);

auto system = mavsdk.systems().at(0);
ASSERT_TRUE(system->has_autopilot());

auto param = Param{system};

auto all_params = param.get_all_params();

std::map<std::string, float> all_mixed{};

LogInfo() << "Int params: " << all_params.int_params.size();
for (const auto& int_param : all_params.int_params) {
std::cout << int_param.name << " : " << int_param.value << '\n';
all_mixed[int_param.name] = static_cast<float>(int_param.value);
}

LogInfo() << "Float params: " << all_params.float_params.size();
for (const auto& float_param : all_params.float_params) {
std::cout << float_param.name << " : " << float_param.value << '\n';
all_mixed[float_param.name] = float_param.value;
}

LogInfo() << "Combined params: " << all_mixed.size();
for (const auto& mixed_param : all_mixed) {
std::cout << mixed_param.first << " : " << mixed_param.second << '\n';
}
}

TEST_F(SitlTest, APParam)
{
Mavsdk mavsdk;

ConnectionResult ret = mavsdk.add_udp_connection();
ASSERT_EQ(ret, ConnectionResult::Success);

// Wait for system to connect via heartbeat.
std::this_thread::sleep_for(std::chrono::seconds(2));

auto system = mavsdk.systems().at(0);
ASSERT_TRUE(system->has_autopilot());

auto param = std::make_shared<Param>(system);

Param::Result set_result1 = param->set_param_int("TERRAIN_ENABLE", 1);

ASSERT_EQ(set_result1, Param::Result::Success);

std::this_thread::sleep_for(std::chrono::seconds(1));

const std::pair<Param::Result, int> get_result2 = param->get_param_int("TERRAIN_ENABLE");
EXPECT_EQ(get_result2.first, Param::Result::Success);
EXPECT_EQ(get_result2.second, 1);
}
Loading

0 comments on commit 0c13d0f

Please sign in to comment.