make subscriber example use the new param api

This commit is contained in:
Thomas Gubler 2015-02-08 12:35:10 +01:00
parent df5ad88df7
commit 69f5726d70
2 changed files with 14 additions and 17 deletions

View File

@ -49,20 +49,18 @@ void rc_channels_callback_function(const px4_rc_channels &msg) {
SubscriberExample::SubscriberExample() :
_n(),
_p_sub_interv(PX4_PARAM_INIT(SUB_INTERV)),
_interval(0),
_p_test_float(PX4_PARAM_INIT(SUB_TESTF)),
_test_float(0.0f)
_p_sub_interv("SUB_INTERV", PARAM_SUB_INTERV_DEFAULT),
_p_test_float("SUB_TESTF", PARAM_SUB_TESTF_DEFAULT)
{
/* Read the parameter back as example */
PX4_PARAM_GET(_p_sub_interv, &_interval);
PX4_INFO("Param SUB_INTERV = %d", _interval);
PX4_PARAM_GET(_p_test_float, &_test_float);
PX4_INFO("Param SUB_TESTF = %.3f", (double)_test_float);
_p_sub_interv.update();
_p_test_float.update();
PX4_INFO("Param SUB_INTERV = %d", _p_sub_interv.get());
PX4_INFO("Param SUB_TESTF = %.3f", (double)_p_test_float.get());
/* Do some subscriptions */
/* Function */
_n.subscribe<px4_rc_channels>(rc_channels_callback_function, _interval);
_n.subscribe<px4_rc_channels>(rc_channels_callback_function, _p_sub_interv.get());
/* No callback */
_sub_rc_chan = _n.subscribe<px4_rc_channels>(500);
@ -98,8 +96,8 @@ void SubscriberExample::vehicle_attitude_callback(const px4_vehicle_attitude &ms
void SubscriberExample::parameter_update_callback(const px4_parameter_update &msg) {
PX4_INFO("parameter_update_callback (method): [%llu]",
msg.data().timestamp);
PX4_PARAM_GET(_p_sub_interv, &_interval);
PX4_INFO("Param SUB_INTERV = %d", _interval);
PX4_PARAM_GET(_p_test_float, &_test_float);
PX4_INFO("Param SUB_TESTF = %.3f", (double)_test_float);
_p_sub_interv.update();
PX4_INFO("Param SUB_INTERV = %d", _p_sub_interv.get());
_p_test_float.update();
PX4_INFO("Param SUB_TESTF = %.3f", (double)_p_test_float.get());
}

View File

@ -52,12 +52,11 @@ public:
void spin() {_n.spin();}
protected:
px4::NodeHandle _n;
px4_param_t _p_sub_interv;
int32_t _interval;
px4_param_t _p_test_float;
float _test_float;
px4::ParameterInt _p_sub_interv;
px4::ParameterFloat _p_test_float;
px4::Subscriber<px4_rc_channels> * _sub_rc_chan;
void rc_channels_callback(const px4_rc_channels &msg);
void vehicle_attitude_callback(const px4_vehicle_attitude &msg);
void parameter_update_callback(const px4_parameter_update &msg);