39 #include <yaml-cpp/yaml.h> 48 unsaved_changes_(false),
49 write_request_in_progress_(false),
50 first_param_received_(false),
52 got_all_params_(false),
53 param_set_in_progress_(false)
93 *value =
params_[name].getValue();
107 mavlink_message_t msg;
108 params_[name].requestSet(value, &msg);
129 mavlink_message_t msg;
146 if (listener == NULL)
149 bool already_registered =
false;
154 already_registered =
true;
159 if (!already_registered)
165 if (listener == NULL)
182 yaml << YAML::BeginSeq;
183 std::map<std::string, Param>::iterator it;
187 yaml << YAML::BeginMap;
188 yaml << YAML::Key <<
"name" << YAML::Value << it->second.getName();
189 yaml << YAML::Key <<
"type" << YAML::Value << (int) it->second.getType();
190 yaml << YAML::Key <<
"value" << YAML::Value << it->second.getValue();
191 yaml << YAML::EndMap;
193 yaml << YAML::EndSeq;
199 fout.open(filename.c_str());
200 fout << yaml.c_str();
215 YAML::Node root = YAML::LoadFile(filename);
216 assert(root.IsSequence());
218 for (
int i = 0; i < root.size(); i++)
220 if (root[i].IsMap() && root[i][
"name"] && root[i][
"type"] && root[i][
"value"])
222 if (
is_param_id(root[i][
"name"].as<std::string>()))
227 set_param_value(root[i][
"name"].as<std::string>(), root[i][
"value"].as<double>());
261 mavlink_message_t param_list_msg;
268 mavlink_message_t param_request_msg;
295 std::string name(c_name);
314 if (
params_[name].handleUpdate(param))
346 ROS_INFO(
"Param write failed - maybe disarm the aricraft and try again?");
bool save_to_file(std::string filename)
void param_set_timer_callback(const ros::TimerEvent &event)
static uint16_t mavlink_msg_param_request_list_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t *msg, uint8_t target_system, uint8_t target_component)
Pack a param_request_list message.
void register_param_listener(ParamListenerInterface *listener)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val)
std::vector< ParamListenerInterface * > listeners_
static void mavlink_msg_rosflight_cmd_ack_decode(const mavlink_message_t *msg, mavlink_rosflight_cmd_ack_t *rosflight_cmd_ack)
Decode a rosflight_cmd_ack message into a struct.
ParamManager(MavlinkComm *const comm)
bool is_param_id(std::string name)
bool first_param_received_
virtual void handle_mavlink_message(const mavlink_message_t &msg)
The handler function for mavlink messages to be implemented by derived classes.
void register_mavlink_listener(MavlinkListenerInterface *const listener)
Register a listener for mavlink messages.
void unregister_param_listener(ParamListenerInterface *listener)
bool set_param_value(std::string name, double value)
bool param_set_in_progress_
#define MAVLINK_MSG_PARAM_VALUE_FIELD_PARAM_ID_LEN
void handle_param_value_msg(const mavlink_message_t &msg)
bool load_from_file(std::string filename)
Timer createTimer(Rate r, Handler h, Obj o, bool oneshot=false, bool autostart=true) const
static uint16_t mavlink_msg_rosflight_cmd_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t *msg, uint8_t command)
Pack a rosflight_cmd message.
#define MAVLINK_MSG_ID_PARAM_VALUE
Describes an interface classes can implement to receive and handle mavlink messages.
int get_params_received()
std::map< std::string, Param > params_
void request_param_list()
ros::Timer param_set_timer_
bool get_param_value(std::string name, double *value)
std::deque< mavlink_message_t > param_set_queue_
static void mavlink_msg_param_value_decode(const mavlink_message_t *msg, mavlink_param_value_t *param_value)
Decode a param_value message into a struct.
MAV_PARAM_TYPE getType() const
#define MAVLINK_MSG_ID_ROSFLIGHT_CMD_ACK
void request_param(int index)
bool write_request_in_progress_
void handle_command_ack_msg(const mavlink_message_t &msg)
void send_message(const mavlink_message_t &msg)
Send a mavlink message.
static uint16_t mavlink_msg_param_request_read_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t *msg, uint8_t target_system, uint8_t target_component, const char *param_id, int16_t param_index)
Pack a param_request_read message.