Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CI #1175

Merged
merged 21 commits into from
Aug 26, 2020
Merged

Fix CI #1175

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
d458100
workflows: update before installing
julianoes Aug 25, 2020
5aa700e
follow_me: fix spelling
julianoes Aug 25, 2020
ceaf9a0
follow_me: remove unnecessary unlock
julianoes Aug 25, 2020
52755a0
follow_me: fix comment typo
julianoes Aug 25, 2020
926da03
follow_me: don't mess with cookie after reset
julianoes Aug 25, 2020
7c80a7b
follow_me: remove_call_every on destruction
julianoes Aug 25, 2020
8f9ac2d
mavlink_passthrough: fix stack use after free
julianoes Aug 25, 2020
7ea5e2d
ftp: use open instead of replacing the stream
julianoes Aug 25, 2020
827dd26
mavlink_passthrough: initialize shared_ptr
julianoes Aug 25, 2020
a8dfca7
core: move special Windows path to connection
julianoes Aug 25, 2020
78efa00
mission: fix style
julianoes Aug 25, 2020
4226501
integration_tests: try to make test less flaky
julianoes Aug 25, 2020
d2c14c9
integration_tests: increase resolution of check
julianoes Aug 26, 2020
11acc0d
docker: switch to v1.11.0 release candidate 3
julianoes Aug 26, 2020
09c1a51
integration_tests: make hover test more robust
julianoes Aug 26, 2020
760be60
integration_tests: try to fix PX4 losing datalink
julianoes Aug 26, 2020
af433ff
core: immediately send heartbeats after discovery
julianoes Aug 26, 2020
d6d0009
mavlink_passthrough: unregister message handlers
julianoes Aug 26, 2020
d365f6b
core: use call_every to send heartbeat
julianoes Aug 26, 2020
c84eb27
integration_tests: relax altitude check
julianoes Aug 26, 2020
c50a984
integration_tests: increase resolution again
julianoes Aug 26, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
with:
submodules: recursive
- name: install
run: sudo apt-get install -y libjsoncpp-dev libcurl4-openssl-dev libtinyxml2-dev
run: sudo apt-get update && sudo apt-get install -y libjsoncpp-dev libcurl4-openssl-dev libtinyxml2-dev
- name: configure
run: cmake -DCMAKE_BUILD_TYPE=Release -DSUPERBUILD=OFF -j 2 -Bbuild/release -H.
- name: build
Expand Down Expand Up @@ -300,7 +300,7 @@ jobs:
submodules: recursive
fetch-depth: 0
- name: Install lcov
run: sudo apt-get install -y build-essential debhelper fakeroot libjsoncpp-dev libcurl4-openssl-dev libtinyxml2-dev libjsoncpp1 libcurl4 libtinyxml2-6a
run: sudo apt-get update && sudo apt-get install -y build-essential debhelper fakeroot libjsoncpp-dev libcurl4-openssl-dev libtinyxml2-dev libjsoncpp1 libcurl4 libtinyxml2-6a
- name: Generate changelog
run: ./tools/generate_debian_changelog.sh > debian/changelog
- name: Build package
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile-Ubuntu-20.04-PX4-SITL-v1.11
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8

RUN git clone https://github.com/PX4/Firmware.git ${FIRMWARE_DIR}
RUN git -C ${FIRMWARE_DIR} checkout master # later: v1.11.0
RUN git -C ${FIRMWARE_DIR} checkout v1.11.0-rc3 # later: v1.11.0
RUN git -C ${FIRMWARE_DIR} submodule update --init --recursive
RUN cd ${FIRMWARE_DIR} && Tools/setup/ubuntu.sh --no-nuttx
RUN cd ${FIRMWARE_DIR} && DONT_RUN=1 make px4_sitl gazebo && DONT_RUN=1 make px4_sitl gazebo
1 change: 0 additions & 1 deletion src/core/cli_arg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ bool CliArg::find_path(std::string& rest)
_path = "";
return false;
}
_path = "\\\\.\\" + _path;
}
} else {
LogWarn() << "Invalid serial path";
Expand Down
5 changes: 4 additions & 1 deletion src/core/serial_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,11 @@ ConnectionResult SerialConnection::setup_port()
return ConnectionResult::ConnectionError;
}
#elif defined(WINDOWS)
// Required for COM ports > 9.
const auto full_serial_path = "\\\\.\\" + _serial_node;

_handle = CreateFile(
_serial_node.c_str(),
full_serial_path.c_str(),
GENERIC_READ | GENERIC_WRITE,
0, // exclusive-access
NULL, // default security attributes
Expand Down
19 changes: 10 additions & 9 deletions src/core/system_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,16 +263,7 @@ void SystemImpl::heartbeats_timed_out()

void SystemImpl::system_thread()
{
dl_time_t last_time{};

while (!_should_exit) {
if (_time.elapsed_since_s(last_time) >= SystemImpl::_HEARTBEAT_SEND_INTERVAL_S) {
if (_parent.is_connected()) {
send_heartbeat();
}
last_time = _time.steady_time();
}

_call_every_handler.run_once();
_params.do_work();
_commands.do_work();
Expand Down Expand Up @@ -525,6 +516,14 @@ void SystemImpl::set_connected()
_parent.notify_on_discover(_uuid);
_connected = true;

// Send a heartbeat back immediately.
send_heartbeat();
// And then schedule sending one at a fixed interval.
add_call_every(
[this]() { send_heartbeat(); },
SystemImpl::_HEARTBEAT_SEND_INTERVAL_S,
&_heartbeat_send_cookie);

if (!_always_connected) {
register_timeout_handler(
std::bind(&SystemImpl::heartbeats_timed_out, this),
Expand Down Expand Up @@ -560,6 +559,8 @@ void SystemImpl::set_disconnected()
_parent.notify_on_timeout(_uuid);
}

remove_call_every(_heartbeat_send_cookie);

{
std::lock_guard<std::mutex> lock(_plugin_impls_mutex);
for (auto plugin_impl : _plugin_impls) {
Expand Down
1 change: 1 addition & 0 deletions src/core/system_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ class SystemImpl : public Sender {
std::mutex _connection_mutex{};
bool _connected{false};
void* _heartbeat_timeout_cookie = nullptr;
void* _heartbeat_send_cookie = nullptr;

std::atomic<bool> _autopilot_version_pending{false};
void* _autopilot_version_timed_out_cookie = nullptr;
Expand Down
28 changes: 17 additions & 11 deletions src/integration_tests/action_hover_sync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,35 +43,41 @@ void takeoff_and_hover_at_altitude(float altitude_m)

LogInfo() << "Waiting for system to be ready";
ASSERT_TRUE(poll_condition_with_timeout(
[&telemetry]() { return telemetry->health_all_ok(); }, std::chrono::seconds(10)));
[telemetry]() { return telemetry->health_all_ok(); }, std::chrono::seconds(10)));

auto action = std::make_shared<Action>(system);
Action::Result action_ret = action->arm();
EXPECT_EQ(action_ret, Action::Result::Success);

EXPECT_EQ(Action::Result::Success, action->set_takeoff_altitude(altitude_m));
auto takeoff_altitude_result = action->get_takeoff_altitude();
EXPECT_EQ(takeoff_altitude_result.first, Action::Result::Success);
EXPECT_FLOAT_EQ(takeoff_altitude_result.second, altitude_m);

Action::Result action_ret = action->arm();
EXPECT_EQ(action_ret, Action::Result::Success);

action_ret = action->takeoff();
EXPECT_EQ(action_ret, Action::Result::Success);

// TODO: The wait time should not be hard-coded because the
// simulation might run faster.
EXPECT_TRUE(poll_condition_with_timeout(
[telemetry]() { return telemetry->flight_mode() == Telemetry::FlightMode::Takeoff; },
std::chrono::seconds(10)));

EXPECT_TRUE(poll_condition_with_timeout(
[telemetry]() { return telemetry->flight_mode() == Telemetry::FlightMode::Hold; },
std::chrono::seconds(10)));

// We wait 2s / m plus a margin of 5s.
const int wait_time_s = static_cast<int>(altitude_m * 2.0f + 5.0f);
std::this_thread::sleep_for(std::chrono::seconds(wait_time_s));
// We need to wait a bit until it stabilizes.
std::this_thread::sleep_for(std::chrono::seconds(5));

EXPECT_GT(telemetry->position().relative_altitude_m, altitude_m - 0.25f);
EXPECT_LT(telemetry->position().relative_altitude_m, altitude_m + 0.25f);
// FIXME: we can't expect too much precision apparently.
EXPECT_GT(telemetry->position().relative_altitude_m, altitude_m - 0.5f);
EXPECT_LT(telemetry->position().relative_altitude_m, altitude_m + 0.5f);

action_ret = action->land();
EXPECT_EQ(action_ret, Action::Result::Success);

EXPECT_TRUE(poll_condition_with_timeout(
[&telemetry]() { return !telemetry->in_air(); }, std::chrono::seconds(wait_time_s)));
[telemetry]() { return !telemetry->in_air(); }, std::chrono::seconds(10)));

action_ret = action->disarm();
EXPECT_EQ(action_ret, Action::Result::Success);
Expand Down
4 changes: 2 additions & 2 deletions src/integration_tests/integration_test_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ bool poll_condition_with_timeout(

unsigned iteration = 0;
while (!fun()) {
std::this_thread::sleep_for(duration_ms / 10);
if (iteration++ >= 10) {
std::this_thread::sleep_for(duration_ms / 1000);
if (iteration++ >= 1000) {
return false;
}
}
Expand Down
9 changes: 4 additions & 5 deletions src/integration_tests/mavlink_passthrough.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <atomic>
#include <iostream>
#include <future>
#include "log.h"
Expand Down Expand Up @@ -48,19 +47,19 @@ TEST_F(SitlTest, MavlinkPassthrough)
}

{
std::atomic<unsigned> counter{0};
auto counter = std::make_shared<unsigned>(0);

mavlink_passthrough->subscribe_message_async(
MAVLINK_MSG_ID_HIGHRES_IMU, [&counter](const mavlink_message_t& message) {
MAVLINK_MSG_ID_HIGHRES_IMU, [counter](const mavlink_message_t& message) {
mavlink_highres_imu_t highres_imu;
mavlink_msg_highres_imu_decode(&message, &highres_imu);

LogInfo() << "HIGHRES_IMU.temperature [1] (" << counter << ")"
<< highres_imu.temperature << " degrees C";
++counter;
++(*counter);
});

std::this_thread::sleep_for(std::chrono::seconds(3));
EXPECT_GT(counter, 100);
EXPECT_GT(*counter, 100);
}
}
28 changes: 19 additions & 9 deletions src/integration_tests/telemetry_modes.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <atomic>
#include <iostream>
#include "mavsdk.h"
#include "plugins/action/action.h"
Expand All @@ -7,7 +8,7 @@
using namespace mavsdk;

void observe_mode(Telemetry::FlightMode flight_mode);
static Telemetry::FlightMode _flight_mode = Telemetry::FlightMode::Unknown;
static std::atomic<Telemetry::FlightMode> _flight_mode{Telemetry::FlightMode::Unknown};

TEST_F(SitlTest, TelemetryFlightModes)
{
Expand All @@ -29,14 +30,23 @@ TEST_F(SitlTest, TelemetryFlightModes)
std::this_thread::sleep_for(std::chrono::seconds(1));
}

action->arm();
std::this_thread::sleep_for(std::chrono::seconds(2));
action->takeoff();
std::this_thread::sleep_for(std::chrono::seconds(2));
ASSERT_EQ(_flight_mode, Telemetry::FlightMode::Takeoff);
action->land();
std::this_thread::sleep_for(std::chrono::seconds(2));
ASSERT_EQ(_flight_mode, Telemetry::FlightMode::Land);
EXPECT_EQ(action->arm(), Action::Result::Success);

EXPECT_EQ(action->takeoff(), Action::Result::Success);

EXPECT_TRUE(poll_condition_with_timeout(
[]() { return _flight_mode == Telemetry::FlightMode::Takeoff; }, std::chrono::seconds(10)));

EXPECT_TRUE(poll_condition_with_timeout(
[]() { return _flight_mode == Telemetry::FlightMode::Hold; }, std::chrono::seconds(10)));

EXPECT_EQ(action->land(), Action::Result::Success);

EXPECT_TRUE(poll_condition_with_timeout(
[]() { return _flight_mode == Telemetry::FlightMode::Land; }, std::chrono::seconds(10)));

EXPECT_TRUE(poll_condition_with_timeout(
[&telemetry]() { return !telemetry->armed(); }, std::chrono::seconds(10)));
}

void observe_mode(Telemetry::FlightMode flight_mode)
Expand Down
11 changes: 6 additions & 5 deletions src/plugins/follow_me/follow_me_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ FollowMeImpl::FollowMeImpl(System& system) : PluginImplBase(system)

FollowMeImpl::~FollowMeImpl()
{
if (_target_location_cookie) {
_parent->remove_call_every(_target_location_cookie);
}
_parent->unregister_plugin(this);
}

Expand Down Expand Up @@ -136,7 +139,7 @@ FollowMe::Result FollowMeImpl::set_target_location(const FollowMe::TargetLocatio
_mutex.lock();
_target_location = location;
// We're interested only in lat, long.
_estimatation_capabilities |= (1 << static_cast<int>(EstimationCapabilites::POS));
_estimation_capabilities |= (1 << static_cast<int>(EstimationCapabilities::POS));

if (_mode != Mode::ACTIVE) {
_mutex.unlock();
Expand All @@ -145,9 +148,8 @@ FollowMe::Result FollowMeImpl::set_target_location(const FollowMe::TargetLocatio
// If set already, reschedule it.
if (_target_location_cookie) {
_parent->reset_call_every(_target_location_cookie);
_target_location_cookie = nullptr;
} else {
// Regiter now for sending in the next cycle.
// Register now for sending in the next cycle.
_parent->add_call_every(
[this]() { send_target_location(); }, SENDER_RATE, &_target_location_cookie);
}
Expand Down Expand Up @@ -283,7 +285,7 @@ void FollowMeImpl::send_target_location()
_parent->get_own_component_id(),
&msg,
elapsed_msec,
_estimatation_capabilities,
_estimation_capabilities,
lat_int,
lon_int,
alt,
Expand Down Expand Up @@ -337,7 +339,6 @@ void FollowMeImpl::process_heartbeat(const mavlink_message_t& message)
} else if (follow_me_active && _mode == Mode::NOT_ACTIVE) {
// We're in FollowMe mode now
_mode = Mode::ACTIVE;
_mutex.unlock(); // we must unlock to avoid deadlock in send_target_location()
return;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/follow_me/follow_me_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class FollowMeImpl : public PluginImplBase {
void send_target_location();
void stop_sending_target_location();

enum class EstimationCapabilites { POS, VEL };
enum class EstimationCapabilities { POS, VEL };

enum class Mode { NOT_ACTIVE, ACTIVE } _mode = Mode::NOT_ACTIVE;

Expand Down Expand Up @@ -89,7 +89,7 @@ class FollowMeImpl : public PluginImplBase {
void* _target_location_cookie = nullptr;

Time _time{};
uint8_t _estimatation_capabilities = 0; // sent to vehicle
uint8_t _estimation_capabilities = 0; // sent to vehicle
FollowMe::Config _config{}; // has FollowMe configuration settings

const float SENDER_RATE = 1.0f; // send location updates once in a second
Expand Down
29 changes: 13 additions & 16 deletions src/plugins/ftp/ftp_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ void FtpImpl::_process_ack(PayloadHeader* payload)
break;

case CMD_READ_FILE:
_ofstream->stream.write(reinterpret_cast<const char*>(payload->data), payload->size);
if (!(_ofstream->stream)) {
_ofstream.stream.write(reinterpret_cast<const char*>(payload->data), payload->size);
if (!_ofstream.stream) {
_session_result = ServerResult::ERR_FILE_IO_ERROR;
_end_read_session();
return;
Expand Down Expand Up @@ -314,9 +314,9 @@ void FtpImpl::download_async(

std::string local_path = local_folder + path_separator + fs_filename(remote_path);

_ofstream.reset(new OfstreamWithPath{
std::ofstream(local_path, std::fstream::trunc | std::fstream::binary), local_path});
if (!_ofstream->stream) {
_ofstream.stream.open(local_path, std::fstream::trunc | std::fstream::binary);
_ofstream.path = local_path;
if (!_ofstream.stream) {
_end_read_session();
Ftp::ProgressData empty{};
callback(Ftp::Result::FileIoError, empty);
Expand All @@ -336,14 +336,12 @@ void FtpImpl::download_async(
void FtpImpl::_end_read_session(bool delete_file)
{
_curr_op = CMD_NONE;
if (_ofstream->stream) {
_ofstream->stream.close();
if (_ofstream.stream.is_open()) {
_ofstream.stream.close();

if (delete_file) {
fs_remove(_ofstream->path);
fs_remove(_ofstream.path);
}

_ofstream.reset(nullptr);
}
_terminate_session();
}
Expand Down Expand Up @@ -384,8 +382,8 @@ void FtpImpl::upload_async(
return;
}

_ifstream.reset(new std::ifstream(local_file_path, std::fstream::binary));
if (!*_ifstream) {
_ifstream.open(local_file_path, std::fstream::binary);
if (!_ifstream) {
_end_write_session();
Ftp::ProgressData empty{};
callback(Ftp::Result::FileIoError, empty);
Expand All @@ -409,8 +407,7 @@ void FtpImpl::_end_write_session()
{
_curr_op = CMD_NONE;
if (_ifstream) {
_ifstream->close();
_ifstream = nullptr;
_ifstream.close();
}
_terminate_session();
}
Expand All @@ -429,8 +426,8 @@ void FtpImpl::_write()
payload->session = _session;
payload->opcode = _curr_op = CMD_WRITE_FILE;
payload->offset = _bytes_transferred;
int bytes_read = _ifstream->readsome(reinterpret_cast<char*>(payload->data), max_data_length);
if (!*_ifstream) {
int bytes_read = _ifstream.readsome(reinterpret_cast<char*>(payload->data), max_data_length);
if (!_ifstream) {
_end_write_session();
_call_op_result_callback(ServerResult::ERR_FILE_IO_ERROR);
return;
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/ftp/ftp_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ class FtpImpl : public PluginImplBase {
uint32_t _last_command_retries = 0;
std::string _last_path{};
uint16_t _seq_number = 0;
std::unique_ptr<std::ifstream> _ifstream{};
std::unique_ptr<OfstreamWithPath> _ofstream{};
std::ifstream _ifstream{};
OfstreamWithPath _ofstream{};
bool _session_valid = false;
uint8_t _session = 0;
ServerResult _session_result = ServerResult::SUCCESS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ void MavlinkPassthroughImpl::deinit()
{
_parent->intercept_incoming_messages(nullptr);
_parent->intercept_outgoing_messages(nullptr);
_parent->unregister_all_mavlink_message_handlers(this);
}

void MavlinkPassthroughImpl::enable() {}
Expand Down
Loading