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

Hardware Configuration Manager #115

Open
wants to merge 33 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
5ab60a3
Add conif_manager stuff to mavrosflight
BillThePlatypus Dec 6, 2019
a9a8462
Update gitignore to ignore clion files
BillThePlatypus Dec 6, 2019
e0c5fcb
Add service definitions for setting and getting configurations
BillThePlatypus Dec 6, 2019
938056d
Add line required by C++, but which doesn't really say anything
BillThePlatypus Dec 6, 2019
da785c1
Fix potential memory leak
BillThePlatypus Dec 6, 2019
4e73797
Basic functionality working for config_manager
BillThePlatypus Dec 7, 2019
c9770ea
Rename param_write to settings_write
BillThePlatypus Dec 12, 2019
9acc6ea
Receiving device and config names works
BillThePlatypus Dec 18, 2019
060b39a
Add getting and setting config via strings
BillThePlatypus Dec 19, 2019
d8eeedd
Refactoring to clean up
BillThePlatypus Dec 19, 2019
bb94581
Add more verbose error messages
BillThePlatypus Dec 19, 2019
177dde9
Add option to specify default
BillThePlatypus Dec 19, 2019
9ef24b5
Handle responses when setting a config
BillThePlatypus Jan 7, 2020
d240179
Add command for requesting configuration and device info
BillThePlatypus Jan 13, 2020
4396f62
Rename /settings_write to /memory_write
BillThePlatypus Jan 16, 2020
74fbdf1
Attach correct mavlink libraryclear
BillThePlatypus Jan 23, 2020
dc772e5
Merge branch 'battery_monitor' into config_manager
BillThePlatypus Jan 23, 2020
d863799
Merge branch 'master' into config_manager
BillThePlatypus Jan 24, 2020
c6f5124
Support calling devices by number
BillThePlatypus Jan 24, 2020
e9e62b9
Add message / service types for config_get
BillThePlatypus Mar 24, 2020
7336455
Add config_list service, to show available configurations
BillThePlatypus Mar 24, 2020
0cf567f
Add ability to rerequest config info if there are errors or interuptions
BillThePlatypus Mar 25, 2020
2b7d63a
Throttle warning messages
BillThePlatypus Mar 26, 2020
0394360
Small changes as recommended in Dan's review
BillThePlatypus Mar 26, 2020
104c68a
Fix indentation in rosflight_io.cpp
BillThePlatypus Mar 26, 2020
b42c68c
Update mavlink
BillThePlatypus Mar 26, 2020
5eac04a
Revert accidental whitespace changes
BillThePlatypus Mar 26, 2020
0929d6e
Merge branch 'master' into config_manager
BillThePlatypus Mar 27, 2020
f572bd6
Get simulation working with config_manager
BillThePlatypus Mar 27, 2020
563b89d
Add names for devices and configuration in the sil_board
BillThePlatypus Mar 31, 2020
7d55cd0
Add better responses to configuration changes
BillThePlatypus Mar 31, 2020
b373388
Code cleanup
BillThePlatypus Apr 1, 2020
0758f94
Use mavrosflight namespace properly to clean up code
BillThePlatypus Apr 1, 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@
*CMakeFiles*
*catkin_generated*
*Makefile
.idea/
cmake-build-*/
1 change: 1 addition & 0 deletions rosflight/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ add_library(mavrosflight
src/mavrosflight/param_manager.cpp
src/mavrosflight/param.cpp
src/mavrosflight/time_manager.cpp
src/mavrosflight/config_manager.cpp
)
add_dependencies(mavrosflight ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
target_link_libraries(mavrosflight
Expand Down
76 changes: 76 additions & 0 deletions rosflight/include/rosflight/mavrosflight/config_manager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#include <vector>
#include <future>
#include <chrono>
#include <string>
#include <utility>

#include "mavlink_listener_interface.h"
#include "mavlink_comm.h"

namespace mavrosflight
{

class ConfigManager : public MavlinkListenerInterface
{
public:
typedef struct
{
bool successful;
bool reboot_required;
std::string error_message;
} config_response_t;
BillThePlatypus marked this conversation as resolved.
Show resolved Hide resolved
ConfigManager(MavlinkComm *const comm);
~ConfigManager();
void handle_mavlink_message(const mavlink_message_t &msg) override;
std::tuple<bool, uint8_t> get_configuration(uint8_t device);
config_response_t set_configuration(uint8_t device, uint8_t config);
void request_config_info();

std::tuple<bool, uint8_t> get_device_from_str(const std::string &name) const;
std::tuple<bool, uint8_t> get_config_from_str(uint8_t device, const std::string &name) const;
bool is_valid_device(uint8_t device) const;
bool is_valid_config(uint8_t device, uint8_t config) const;
std::string get_device_name(uint8_t device) const;
std::string get_config_name(uint8_t device, uint8_t config) const;

static constexpr std::chrono::milliseconds timeout{500};
BillThePlatypus marked this conversation as resolved.
Show resolved Hide resolved
private:
typedef struct
BillThePlatypus marked this conversation as resolved.
Show resolved Hide resolved
{
std::promise<uint8_t> promise;
uint8_t device;
} config_promise_t;
MavlinkComm *const comm_;
std::vector<config_promise_t *> promises_;


typedef struct
BillThePlatypus marked this conversation as resolved.
Show resolved Hide resolved
{
std::promise<config_response_t> promise;
uint8_t device;
uint8_t config;
} config_response_promise_t;
std::vector<config_response_promise_t *> config_response_promises_;

typedef struct
BillThePlatypus marked this conversation as resolved.
Show resolved Hide resolved
{
std::string name;
std::string internal_name;
uint8_t max_value;
std::vector<std::string> config_names;
} device_info_t;
std::vector<device_info_t> device_info_;

void handle_config_message(const mavlink_message_t &msg);
void handle_device_info_message(const mavlink_message_t &msg);
void handle_config_info_message(const mavlink_message_t &msg);
void handle_config_response_message(const mavlink_message_t &msg);
void send_config_get_request(uint8_t device);
void send_config_set_request(uint8_t device, uint8_t config);

static std::string make_internal_name(const std::string &name);
static std::vector<std::string> get_words(const std::string &internal_name);
static bool is_uint8(const std::string &str);

}; // class ConfigManager
} // namespace mavrosflight
2 changes: 2 additions & 0 deletions rosflight/include/rosflight/mavrosflight/mavrosflight.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <rosflight/mavrosflight/mavlink_comm.h>
#include <rosflight/mavrosflight/param_manager.h>
#include <rosflight/mavrosflight/time_manager.h>
#include <rosflight/mavrosflight/config_manager.h>

#include <rosflight/mavrosflight/mavlink_listener_interface.h>
#include <rosflight/mavrosflight/param_listener_interface.h>
Expand Down Expand Up @@ -73,6 +74,7 @@ class MavROSflight
MavlinkComm& comm;
ParamManager param;
TimeManager time;
ConfigManager config_manager;

private:

Expand Down
6 changes: 6 additions & 0 deletions rosflight/include/rosflight/rosflight_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
#include <rosflight_msgs/ParamFile.h>
#include <rosflight_msgs/ParamGet.h>
#include <rosflight_msgs/ParamSet.h>
#include <rosflight_msgs/ConfigSet.h>
#include <rosflight_msgs/ConfigGet.h>

#include <rosflight/mavrosflight/mavrosflight.h>
#include <rosflight/mavrosflight/mavlink_comm.h>
Expand Down Expand Up @@ -144,6 +146,8 @@ class rosflightIO :
bool calibrateAirspeedSrvCallback(std_srvs::Trigger::Request &req, std_srvs::Trigger::Response &res);
bool rebootSrvCallback(std_srvs::Trigger::Request & req, std_srvs::Trigger::Response &res);
bool rebootToBootloaderSrvCallback(std_srvs::Trigger::Request &req, std_srvs::Trigger::Response &res);
bool configGetSrvCallback(rosflight_msgs::ConfigGet::Request &req, rosflight_msgs::ConfigGet::Response &res);
bool configSetSrvCallback(rosflight_msgs::ConfigSet::Request &req, rosflight_msgs::ConfigSet::Response &res);

// timer callbacks
void paramTimerCallback(const ros::TimerEvent &e);
Expand Down Expand Up @@ -204,6 +208,8 @@ class rosflightIO :
ros::ServiceServer calibrate_airspeed_srv_;
ros::ServiceServer reboot_srv_;
ros::ServiceServer reboot_bootloader_srv_;
ros::ServiceServer config_get_srv_;
ros::ServiceServer config_set_srv_;

ros::Timer param_timer_;
ros::Timer version_timer_;
Expand Down
Loading