12
12
#include " px4_controller/px4_controller.h"
13
13
#include < boost/algorithm/string.hpp>
14
14
#include < mavros_msgs/ParamGet.h>
15
+ #include < mavros_msgs/ParamSet.h>
15
16
16
17
namespace px4_control
17
18
{
@@ -41,7 +42,8 @@ void PX4Controller::Drone::executeCommand(const PX4Controller& ctl, const geomet
41
42
42
43
bool PX4Controller::APMRover::init (ros::NodeHandle& nh)
43
44
{
44
- nh.param (" turn_angle_scale" , turn_angle_scale_, 1 .0f );
45
+ nh.param (" linear_speed_scale" , linear_speed_scale_, 1 .0f );
46
+ nh.param (" turn_angle_scale" , turn_angle_scale_, 1 .0f );
45
47
46
48
const int QUEUE_SIZE = 1 ;
47
49
rc_pub_ = nh.advertise <mavros_msgs::OverrideRCIn>(" /mavros/rc/override" , QUEUE_SIZE);
@@ -73,11 +75,26 @@ bool PX4Controller::APMRover::init(ros::NodeHandle& nh)
73
75
rc_throttle_dz_ = (int )param_get.response .value .integer ;
74
76
nh.param (" rc_throttle_dz" , rc_throttle_dz_, rc_throttle_dz_);
75
77
78
+ // APM requires setting SYSID_MYGCS to enable RC override.
79
+ auto set_param_client = nh.serviceClient <mavros_msgs::ParamSet>(" /mavros/param/set" );
80
+ mavros_msgs::ParamSet param_set;
81
+
82
+ param_set.request .param_id = " SYSID_MYGCS" ;
83
+ // REVIEW alexeyk: make a parameter?
84
+ const int gcs_id = 1 ;
85
+ param_set.request .value .integer = gcs_id;
86
+ if (set_param_client.call (param_set) && param_set.response .success )
87
+ ROS_INFO (" (%s) Set SYSID_MYGCS to %d" , getName ().c_str (), gcs_id);
88
+ else
89
+ ROS_WARN (" (%s) Failed to set SYSID_MYGCS to %d" , getName ().c_str (), gcs_id);
90
+
91
+ is_initialized_ = true ;
76
92
return true ;
77
93
}
78
94
79
95
void PX4Controller::APMRover::printArgs ()
80
96
{
97
+ ROS_INFO (" (%s) Speed scale : %.1f" , getName ().c_str (), linear_speed_scale_);
81
98
ROS_INFO (" (%s) Turn angle scale : %.1f" , getName ().c_str (), turn_angle_scale_);
82
99
ROS_INFO (" (%s) Steer trim : %d" , getName ().c_str (), rc_steer_trim_);
83
100
ROS_INFO (" (%s) Steer deadzone : %d" , getName ().c_str (), rc_steer_dz_);
@@ -101,7 +118,7 @@ void PX4Controller::APMRover::executeCommand(const PX4Controller& ctl, const geo
101
118
int steer_delta = turn_angle_scale_ * angular_control_val;
102
119
int steer_dz = steer_delta != 0 ? copysign (rc_steer_dz_, steer_delta) : 0 ;
103
120
rc_override.channels [0 ] = rc_steer_trim_ + steer_dz + steer_delta;
104
- int throttle_delta = ctl.linear_speed_ * linear_control_val;
121
+ int throttle_delta = linear_speed_scale_ * ctl.linear_speed_ * linear_control_val;
105
122
int throttle_dz = throttle_delta != 0 ? copysign (rc_throttle_dz_, throttle_delta) : 0 ;
106
123
rc_override.channels [2 ] = rc_throttle_trim_ + throttle_dz + throttle_delta;
107
124
if (has_command)
@@ -765,7 +782,12 @@ void PX4Controller::spin()
765
782
dnn_commands_count_++;
766
783
}
767
784
else
785
+ {
786
+ // We get here only when there is no commands from DNN or no joystick movements outside of deadzone.
787
+ // Clearing the flag is currently requried only for rover.
788
+ has_command = false ;
768
789
break ;
790
+ }
769
791
}
770
792
771
793
// Log
0 commit comments