-
-
Notifications
You must be signed in to change notification settings - Fork 529
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds a calibration plugin which right now supports gyro, accelerometer, and magnetometer calibration.
- Loading branch information
Showing
14 changed files
with
1,127 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
#include <iostream> | ||
#include "integration_test_helper.h" | ||
#include "global_include.h" | ||
#include "dronecore.h" | ||
#include "plugins/calibration/calibration.h" | ||
|
||
using namespace dronecore; | ||
using namespace std::placeholders; // for `_1` | ||
|
||
static void receive_calibration_callback(Calibration::Result result, | ||
float progress, | ||
const std::string text, | ||
const std::string calibration_type, | ||
bool &done); | ||
|
||
TEST(HardwareTest, GyroCalibration) | ||
{ | ||
DroneCore dc; | ||
|
||
ConnectionResult ret = dc.add_serial_connection("/dev/ttyACM0"); | ||
ASSERT_EQ(ret, ConnectionResult::SUCCESS); | ||
|
||
// Wait for system to connect via heartbeat. | ||
std::this_thread::sleep_for(std::chrono::seconds(2)); | ||
System &system = dc.system(); | ||
|
||
auto calibration = std::make_shared<Calibration>(system); | ||
|
||
bool done = false; | ||
|
||
calibration->calibrate_gyro_async( | ||
std::bind(&receive_calibration_callback, _1, _2, _3, "gyro", std::ref(done))); | ||
|
||
while (!done) { | ||
std::this_thread::sleep_for(std::chrono::seconds(1)); | ||
} | ||
} | ||
|
||
TEST(HardwareTest, AccelerometerCalibration) | ||
{ | ||
DroneCore dc; | ||
|
||
ConnectionResult ret = dc.add_serial_connection("/dev/ttyACM0"); | ||
ASSERT_EQ(ret, ConnectionResult::SUCCESS); | ||
|
||
// Wait for system to connect via heartbeat. | ||
std::this_thread::sleep_for(std::chrono::seconds(2)); | ||
System &system = dc.system(); | ||
|
||
auto calibration = std::make_shared<Calibration>(system); | ||
|
||
bool done = false; | ||
|
||
calibration->calibrate_accelerometer_async( | ||
std::bind(&receive_calibration_callback, _1, _2, _3, "accelerometer", std::ref(done))); | ||
|
||
while (!done) { | ||
std::this_thread::sleep_for(std::chrono::seconds(1)); | ||
} | ||
} | ||
|
||
TEST(HardwareTest, MagnetometerCalibration) | ||
{ | ||
DroneCore dc; | ||
|
||
ConnectionResult ret = dc.add_serial_connection("/dev/ttyACM0"); | ||
ASSERT_EQ(ret, ConnectionResult::SUCCESS); | ||
|
||
// Wait for system to connect via heartbeat. | ||
std::this_thread::sleep_for(std::chrono::seconds(2)); | ||
System &system = dc.system(); | ||
|
||
auto calibration = std::make_shared<Calibration>(system); | ||
|
||
bool done = false; | ||
|
||
calibration->calibrate_magnetometer_async( | ||
std::bind(&receive_calibration_callback, _1, _2, _3, "magnetometer", std::ref(done))); | ||
|
||
while (!done) { | ||
std::this_thread::sleep_for(std::chrono::seconds(1)); | ||
} | ||
} | ||
|
||
void receive_calibration_callback(Calibration::Result result, | ||
float progress, | ||
const std::string text, | ||
const std::string calibration_type, | ||
bool &done) | ||
{ | ||
if (result == Calibration::Result::IN_PROGRESS) { | ||
LogInfo() << calibration_type << " calibration in progress: " << progress; | ||
} else if (result == Calibration::Result::INSTRUCTION) { | ||
LogInfo() << calibration_type << " calibration instruction: " << text; | ||
} else { | ||
EXPECT_EQ(result, Calibration::Result::SUCCESS); | ||
|
||
if (result != Calibration::Result::SUCCESS) { | ||
LogErr() << calibration_type | ||
<< " calibration error: " << Calibration::result_str(result); | ||
if (result == Calibration::Result::FAILED) { | ||
LogErr() << calibration_type << " cailbration failed: " << text; | ||
} | ||
} | ||
done = true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
add_library(dronecore_calibration ${PLUGIN_LIBRARY_TYPE} | ||
calibration.cpp | ||
calibration_impl.cpp | ||
calibration_statustext_parser.cpp | ||
) | ||
|
||
target_link_libraries(dronecore_calibration | ||
dronecore | ||
) | ||
|
||
install(FILES | ||
calibration.h | ||
DESTINATION ${dronecore_install_include_dir} | ||
) | ||
|
||
install(TARGETS dronecore_calibration | ||
#EXPORT dronecore-targets | ||
DESTINATION ${dronecore_install_lib_dir} | ||
) | ||
|
||
list(APPEND UNIT_TEST_SOURCES | ||
${CMAKE_CURRENT_SOURCE_DIR}/calibration_statustext_parser_test.cpp | ||
) | ||
set(UNIT_TEST_SOURCES ${UNIT_TEST_SOURCES} PARENT_SCOPE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#include "calibration.h" | ||
#include "calibration_impl.h" | ||
#include "calibration_messages.h" | ||
|
||
namespace dronecore { | ||
|
||
Calibration::Calibration(System &system) : PluginBase() | ||
{ | ||
_impl = new CalibrationImpl(system); | ||
} | ||
|
||
Calibration::~Calibration() | ||
{ | ||
delete _impl; | ||
} | ||
|
||
void Calibration::calibrate_gyro_async(calibration_callback_t callback) | ||
{ | ||
_impl->calibrate_gyro_async(callback); | ||
} | ||
|
||
void Calibration::calibrate_accelerometer_async(calibration_callback_t callback) | ||
{ | ||
_impl->calibrate_accelerometer_async(callback); | ||
} | ||
|
||
void Calibration::calibrate_magnetometer_async(calibration_callback_t callback) | ||
{ | ||
_impl->calibrate_magnetometer_async(callback); | ||
} | ||
|
||
const char *Calibration::result_str(Result result) | ||
{ | ||
switch (result) { | ||
case Result::SUCCESS: | ||
return "Success"; | ||
case Result::IN_PROGRESS: | ||
return "In progress"; | ||
case Result::INSTRUCTION: | ||
return "Instruction"; | ||
case Result::FAILED: | ||
return "Failed"; | ||
case Result::NO_SYSTEM: | ||
return "No system"; | ||
case Result::CONNECTION_ERROR: | ||
return "Connection error"; | ||
case Result::BUSY: | ||
return "Busy"; | ||
case Result::COMMAND_DENIED: | ||
return "Command denied"; | ||
case Result::TIMEOUT: | ||
return "Timeout"; | ||
case Result::CANCELLED: | ||
return "CANCELLED"; | ||
case Result::UNKNOWN: | ||
default: | ||
return "Unknown"; | ||
} | ||
} | ||
|
||
} // namespace dronecore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#pragma once | ||
|
||
#include <functional> | ||
#include "plugin_base.h" | ||
|
||
namespace dronecore { | ||
|
||
class CalibrationImpl; | ||
class System; | ||
|
||
class Calibration : public PluginBase { | ||
public: | ||
/** | ||
* @brief Constructor. Creates the plugin for a specific System. | ||
* | ||
* The plugin is typically created as shown below: | ||
* | ||
* ```cpp | ||
* auto calibration = std::make_shared<Calibration>(system); | ||
* ``` | ||
* | ||
* @param system The specific system associated with this plugin. | ||
*/ | ||
explicit Calibration(System &system); | ||
|
||
/** | ||
* @brief Destructor (internal use only). | ||
*/ | ||
~Calibration(); | ||
|
||
/** | ||
* @brief Possible results returned for camera commands. | ||
*/ | ||
enum class Result { | ||
UNKNOWN, | ||
SUCCESS, | ||
IN_PROGRESS, | ||
INSTRUCTION, | ||
FAILED, | ||
NO_SYSTEM, | ||
CONNECTION_ERROR, | ||
BUSY, | ||
COMMAND_DENIED, | ||
TIMEOUT, | ||
CANCELLED | ||
}; | ||
|
||
/** | ||
* @brief Returns a human-readable English string for Calibration::Result. | ||
* | ||
* @param result The enum value for which a human readable string is required. | ||
* @return Human readable string for the Calibration::Result. | ||
*/ | ||
static const char *result_str(Result result); | ||
|
||
/** | ||
* @brief Callback type for asynchronous calibration call. | ||
*/ | ||
typedef std::function<void(Result result, float progress, const std::string &text)> | ||
calibration_callback_t; | ||
|
||
/** | ||
* @brief Perform gyro calibration (asynchronous call). | ||
* | ||
* @param callback Function to receive result and progress of calibration. | ||
*/ | ||
void calibrate_gyro_async(calibration_callback_t callback); | ||
|
||
/** | ||
* @brief Perform accelerometer calibration (asynchronous call). | ||
* | ||
* @param callback Function to receive result and progress of calibration. | ||
*/ | ||
void calibrate_accelerometer_async(calibration_callback_t callback); | ||
|
||
/** | ||
* @brief Perform magnetometer calibration (asynchronous call). | ||
* | ||
* @param callback Function to receive result and progress of calibration. | ||
*/ | ||
void calibrate_magnetometer_async(calibration_callback_t callback); | ||
|
||
/** | ||
* @brief Copy constructor (object is not copyable). | ||
*/ | ||
Calibration(const Calibration &) = delete; | ||
|
||
/** | ||
* @brief Equality operator (object is not copyable). | ||
*/ | ||
const Calibration &operator=(const Calibration &) = delete; | ||
|
||
private: | ||
/** @private Underlying implementation, set at instantiation */ | ||
CalibrationImpl *_impl; | ||
}; | ||
|
||
} // namespace dronecore |
Oops, something went wrong.