Skip to content

Commit 248b480

Browse files
committed
feat: added ability to engage a user defined mode of operation with the controller
1 parent f56ad1e commit 248b480

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

include/vb_util_lib/rc_controls.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
#define MAX_DJI_CONTROL 10000.0
1919

20+
#define ENGAGED_THRESHOLD 0.95
21+
2022
enum class RC_MODE
2123
{
2224
ATT = 0,
@@ -62,6 +64,10 @@ class RC_Controls
6264

6365
bool armed_switch {false};
6466

67+
// This is a special mode we can engage and disengage with the congtroler sticks
68+
//both up and in engage and both up and out disengage
69+
bool user_function_engaged {false};
70+
6571
// All stick values are between -1.0 and 1.0
6672
double throttle {0.0};
6773
double yaw {0.0};
@@ -139,6 +145,9 @@ class RC_Controls
139145
bool setPX4GearSwitch(double gear_switch, RC_GEAR& state);
140146
bool setPX4ArmSwitch(double arm_switch, bool& state);
141147
void setPX4StickValue(double input, double& state, double polarity);
148+
149+
// Routine to set the engaged state of the controller
150+
bool setEngagedState();
142151
};
143152

144153
#endif /* VISBOX_PACKAGES_COMMON_UTILS_UTIL_LIB_INCLUDE_VB_UTIL_LIB_RC_CONTROLS_H_ */

src/vb_util_lib/rc_controls.cpp

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,24 @@ void RC_Controls::setSubscriber(ros::NodeHandle& n) {
168168
stamp = ros::Time::now();
169169
}
170170

171+
bool RC_Controls::setEngagedState() {
172+
if (throttle > ENGAGED_THRESHOLD && pitch > ENGAGED_THRESHOLD)
173+
{
174+
if (yaw > ENGAGED_THRESHOLD && roll < -ENGAGED_THRESHOLD)
175+
{
176+
ROS_INFO(">>>>>>>> RC_CONTROL SPECIAL FUNCTION ENGAGED <<<<<<<<<<");
177+
user_function_engaged = true;
178+
}
179+
else if (yaw < -ENGAGED_THRESHOLD && roll > ENGAGED_THRESHOLD)
180+
{
181+
ROS_INFO("<<<<<<<<<< RC_CONTROL SPECIAL FUNCTION DISENGAGED >>>>>>>>>>");
182+
user_function_engaged = false;
183+
}
184+
}
185+
186+
return user_function_engaged;
187+
}
188+
171189
//===================================================
172190
// DJI specific RC stuff
173191
//===================================================
@@ -198,6 +216,9 @@ void RC_Controls::setDJIControls(const sensor_msgs::Joy::ConstPtr& msg) {
198216

199217
setDJIModeSwitch(mode_, mode);
200218
setDJIGearSwitch(gear_, gear);
219+
220+
setEngagedState();
221+
201222
// printf("XXX RC: roll[%0.2f], pitch[%0.2f], yaw[%0.2f], throttle[%0.2f], gear[%0.2f], mode[%0.2f]\n",
202223
// roll_, pitch_, yaw_, throttle_, gear_, mode_);
203224
}
@@ -290,8 +311,10 @@ void RC_Controls::setLogitechControls(const sensor_msgs::Joy::ConstPtr& msg) {
290311
setLogitechStickValue(roll_, roll);
291312
setLogitechStickValue(throttle_, throttle);
292313

293-
ROS_INFO_THROTTLE(1.0, "XXX RC: roll[%0.2f], pitch[%0.2f], yaw[%0.2f], throttle[%0.2f], gear[%0.2f], mode[%0.2f]\n",
294-
roll_, pitch_, yaw_, throttle_, gear_, mode_);
314+
setEngagedState();
315+
316+
ROS_INFO_THROTTLE(1.0, "XXX RC: roll[%0.2f], pitch[%0.2f], yaw[%0.2f], throttle[%0.2f], gear[%0.2f], mode[%0.2f], engaged[%d]\n",
317+
roll_, pitch_, yaw_, throttle_, gear_, mode_, user_function_engaged);
295318
}
296319

297320
bool RC_Controls::setLogitechModeSwitch(double mode_switch, RC_MODE& state) {
@@ -347,6 +370,9 @@ void RC_Controls::setPX4Controls(const mavros_msgs::RCIn::ConstPtr& msg) {
347370
setPX4ModeSwitch(mode_, mode);
348371
setPX4GearSwitch(gear_, gear);
349372
setPX4ArmSwitch(armed_, armed_switch);
373+
374+
setEngagedState();
375+
350376
//ROS_INFO_THROTTLE(2, "XXX RC: roll[%0.2f], pitch[%0.2f], yaw[%0.2f], throttle[%0.2f], gear[%d], mode[%d] armed[%d]\n",
351377
// roll, pitch, yaw, throttle, static_cast<int>(gear), static_cast<int>(mode), armed_switch);
352378
}

0 commit comments

Comments
 (0)