Skip to content

Commit 7dabe24

Browse files
authored
Merge pull request #69 from AutoModality/BB-886/collision_avoidance
feat: added new RC controller for logitech
2 parents f1aac41 + fc58ef0 commit 7dabe24

File tree

5 files changed

+98
-4
lines changed

5 files changed

+98
-4
lines changed

include/vb_util_lib/rc_controls.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,14 @@ class RC_Controls
123123
bool setDJIGearSwitch(double gear_switch, RC_GEAR& state);
124124
void setDJIStickValue(double input, double& state) { state = input; }
125125

126+
// Logitech callback functions
127+
void logitechRemoteCB(const sensor_msgs::Joy::ConstPtr& msg);
128+
ros::Subscriber logitech_rc_channels_sub_;
129+
void setLogitechControls(const sensor_msgs::Joy::ConstPtr& msg);
130+
bool setLogitechModeSwitch(double mode_switch, RC_MODE& state);
131+
bool setLogitechGearSwitch(double gear_switch, RC_GEAR& state);
132+
void setLogitechStickValue(double input, double& state) { state = input; }
133+
126134
// PX4 callback functions
127135
void px4RemoteCB(const mavros_msgs::RCIn::ConstPtr& msg);
128136
ros::Subscriber px4_rc_channels_sub_;

include/vb_util_lib/rc_mapper.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,23 @@ class rc_mapper
6969
#define ACSL_RC_MAX_VALUE 2020
7070
#define ACSL_RC_MIN_VALUE 1020
7171

72+
// LOGITECH
73+
#define LOGITECH_RC_THROTTLE 1
74+
#define LOGITECH_RC_YAW 0
75+
#define LOGITECH_RC_ROLL 2
76+
#define LOGITECH_RC_PITCH 3
77+
#define LOGITECH_RC_GEAR 0
78+
#define LOGITECH_RC_MODE 0
79+
#define LOGITECH_RC_ARM 0
80+
81+
#define LOGITECH_RC_THROTTLE_SIGN 1
82+
#define LOGITECH_RC_YAW_SIGN 1
83+
#define LOGITECH_RC_ROLL_SIGN 1
84+
#define LOGITECH_RC_PITCH_SIGN 1
85+
86+
#define LOGITECH_RC_MAX_VALUE 1
87+
#define LOGITECH_RC_MIN_VALUE -1
88+
7289
// Default
7390
#define DEFAULT_MIN_VALUE 1020
7491
#define DEFAULT_MAX_VALUE 2020
@@ -99,6 +116,7 @@ class rc_mapper
99116
eRCT_PX4 = 0,
100117
eRCT_DJI,
101118
eRCT_ACSL,
119+
eRCT_LOGITECH,
102120
eRCT_Unknown,
103121
eEndOfRCTypes
104122
};

src/vb_util_lib/kinematics.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,9 @@ void Kinematics::setPosition(const ros::Time& update_time, double x, double y, d
218218
{
219219
Eigen::Vector3d vel_debug;
220220
getLinearVelocity(drone_ENU, vel_debug);
221-
ROS_INFO("Kinematics Velocity standard[%s : %0.3f %0.3f, %0.3f] body[%s : %0.3f %0.3f, %0.3f]",
222-
frame_id_.c_str(), velLinear_[0], velLinear_[1], velLinear_[2],
223-
drone_ENU, vel_debug[0], vel_debug[1], vel_debug[2]);
221+
// ROS_INFO("Kinematics Velocity standard[%s : %0.3f %0.3f, %0.3f] body[%s : %0.3f %0.3f, %0.3f]",
222+
// frame_id_.c_str(), velLinear_[0], velLinear_[1], velLinear_[2],
223+
// drone_ENU, vel_debug[0], vel_debug[1], vel_debug[2]);
224224
}
225225
}
226226

src/vb_util_lib/rc_controls.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ void RC_Controls::setSubscriber(ros::NodeHandle& n) {
156156
UPPER_VALUE_ = (MAX_VALUE_ - (RANGE_/2));
157157
LOWER_VALUE_ = (MIN_VALUE_ + (RANGE_/2));
158158

159+
logitech_rc_channels_sub_ = n.subscribe<sensor_msgs::Joy>("/joy", 10,
160+
&RC_Controls::logitechRemoteCB, this);
161+
159162
dji_rc_channels_sub_ = n.subscribe<sensor_msgs::Joy>(am_topics::DJI_SDK_RC, 10,
160163
&RC_Controls::djiRemoteCB, this);
161164

@@ -267,6 +270,53 @@ void RC_Controls::djiRemoteCB(const sensor_msgs::Joy::ConstPtr& rc_msg) {
267270
}
268271
}
269272

273+
//===================================================
274+
// Logitech specific RC stuff
275+
//===================================================
276+
277+
void RC_Controls::setLogitechControls(const sensor_msgs::Joy::ConstPtr& msg) {
278+
279+
stamp = msg->header.stamp;
280+
281+
throttle_ = msg->axes[throttle_idx_];
282+
yaw_ = msg->axes[yaw_idx_];
283+
pitch_ = msg->axes[pitch_idx_];
284+
roll_ = msg->axes[roll_idx_];
285+
gear_ = 0;
286+
mode_ = 0;
287+
288+
setLogitechStickValue(yaw_, yaw);
289+
setLogitechStickValue(pitch_, pitch);
290+
setLogitechStickValue(roll_, roll);
291+
setLogitechStickValue(throttle_, throttle);
292+
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_);
295+
}
296+
297+
bool RC_Controls::setLogitechModeSwitch(double mode_switch, RC_MODE& state) {
298+
bool change_state = false;
299+
state = RC_MODE::POS;
300+
301+
return change_state;
302+
}
303+
304+
bool RC_Controls::setLogitechGearSwitch(double gear_switch, RC_GEAR& state) {
305+
bool change = false;
306+
state = RC_GEAR::DOWN;
307+
308+
return change;
309+
}
310+
311+
void RC_Controls::logitechRemoteCB(const sensor_msgs::Joy::ConstPtr& rc_msg) {
312+
setLogitechControls(rc_msg);
313+
314+
if (callback_ != NULL)
315+
{
316+
callback_(this);
317+
}
318+
}
319+
270320
//===================================================
271321
// PX4 specific RC stuff
272322
//===================================================

src/vb_util_lib/rc_mapper.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@ rc_mapper::rc_mapper(ros::NodeHandle n)
1818
m_RCTypeNames[eRCT_PX4].assign("PX4");
1919
m_RCTypeNames[eRCT_DJI].assign("DJI");
2020
m_RCTypeNames[eRCT_ACSL].assign("ACSL");
21+
m_RCTypeNames[eRCT_LOGITECH].assign("LOGITECH");
2122
m_RCTypeNames[eRCT_Unknown].assign("Unknown");
2223

2324
//default settings
2425
m_RCType.assign(m_RCTypeNames[m_SetRC].c_str());
2526
SetFromDefaults();
2627

27-
//set parameters form the input parameters (if present)
28+
//set parameters from the input parameters (if present)
2829
SetFromParameters();
2930
}
3031

@@ -190,6 +191,23 @@ void rc_mapper::SetFromParameters(void)
190191
m_Handle.param("/RC/maxvalue", m_MaxValue, ACSL_RC_MAX_VALUE);
191192
break;
192193
}
194+
case eRCT_LOGITECH:
195+
{
196+
m_Handle.param("/RC/throttle", m_Channels[eRCThrottle], LOGITECH_RC_THROTTLE);
197+
m_Handle.param("/RC/yaw", m_Channels[eRCYaw], LOGITECH_RC_YAW);
198+
m_Handle.param("/RC/roll", m_Channels[eRCRoll], LOGITECH_RC_ROLL);
199+
m_Handle.param("/RC/pitch", m_Channels[eRCPitch], LOGITECH_RC_PITCH);
200+
m_Handle.param("/RC/gear", m_Channels[eRCGear], LOGITECH_RC_GEAR);
201+
m_Handle.param("/RC/mode", m_Channels[eRCMode], LOGITECH_RC_MODE);
202+
m_Handle.param("/RC/arm", m_Channels[eRCArm], LOGITECH_RC_ARM);
203+
m_Handle.param("/RC/throttle_sign", m_Signs[eThrottleSign], LOGITECH_RC_THROTTLE_SIGN);
204+
m_Handle.param("/RC/yaw_sign", m_Signs[eYawSign], LOGITECH_RC_YAW_SIGN);
205+
m_Handle.param("/RC/roll_sign", m_Signs[eRollSign], LOGITECH_RC_ROLL_SIGN);
206+
m_Handle.param("/RC/pitch_sign", m_Signs[ePitchSign], LOGITECH_RC_PITCH_SIGN);
207+
m_Handle.param("/RC/minvalue", m_MinValue, LOGITECH_RC_MIN_VALUE);
208+
m_Handle.param("/RC/maxvalue", m_MaxValue, LOGITECH_RC_MAX_VALUE);
209+
break;
210+
}
193211
}
194212
ROS_INFO("RC: Parameter driven values: throttle[%d], yaw[%d], roll[%d], pitch[%d], gear[%d], mode[%d], arm[%d], min[%d], max[%d]",
195213
m_Channels[eRCThrottle], m_Channels[eRCYaw], m_Channels[eRCRoll], m_Channels[eRCPitch],

0 commit comments

Comments
 (0)