Skip to content

Commit 94b37c2

Browse files
author
Todd Keitel
authored
Merge pull request #24 from AutoModality/BB-820/Parameterize_rc
Bb 820/parameterize rc
2 parents 01592d0 + 2f29e0b commit 94b37c2

File tree

5 files changed

+424
-28
lines changed

5 files changed

+424
-28
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ add_library(am_utils
9595
src/vb_util_lib/dji_challenge_util.cpp
9696
src/vb_util_lib/am_histogram.cpp
9797
src/vb_util_lib/row_marker.cpp
98-
src/vb_util_lib/rc_controls.cpp
98+
src/vb_util_lib/rc_controls.cpp
99+
src/vb_util_lib/rc_mapper.cpp
99100
src/vb_util_lib/i2c.cpp
100101
src/vb_util_lib/circ_list.cpp
101102
src/vb_util_lib/time_synchronizer.cpp

include/vb_util_lib/rc_controls.h

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,37 @@
99
#define VISBOX_PACKAGES_COMMON_UTILS_UTIL_LIB_INCLUDE_VB_UTIL_LIB_RC_CONTROLS_H_
1010

1111
#include <stdio.h>
12-
13-
//3.3#include <dji_sdk/RCChannels.h>
12+
#include "rc_mapper.h"
13+
//#include <dji_sdk/RCChannels.h>
1414
#include <ros/ros.h>
1515
#include <sensor_msgs/Joy.h>
1616
#include <mavros_msgs/RCIn.h>
1717

1818
#define MAX_DJI_CONTROL 10000.0
1919

20-
enum class RC_MODE {ATT=0, ALT, POS, UNKNOWN};
21-
enum class RC_GEAR {DOWN=0, UP, UNKNOWN};
22-
enum class RC_TYPE {PX4=0, DJI, ACSL, UNKNOWN};
20+
enum class RC_MODE
21+
{
22+
ATT = 0,
23+
ALT,
24+
POS,
25+
UNKNOWN
26+
};
27+
enum class RC_GEAR
28+
{
29+
DOWN = 0,
30+
UP,
31+
UNKNOWN
32+
};
33+
enum class RC_TYPE
34+
{
35+
PX4 = rc_mapper::eRCT_PX4,
36+
DJI = rc_mapper::eRCT_DJI,
37+
ACSL = rc_mapper::eRCT_ACSL,
38+
UNKNOWN = rc_mapper::eRCT_Unknown
39+
};
2340

24-
class RC_Controls {
41+
class RC_Controls
42+
{
2543
public:
2644
RC_Controls();
2745
RC_Controls(ros::NodeHandle& n, RC_TYPE type = RC_TYPE::UNKNOWN);
@@ -51,6 +69,7 @@ class RC_Controls {
5169
double pitch {0.0};
5270

5371
ros::Time stamp;
72+
rc_mapper* rc_mapper_;
5473

5574
// const double MAX_DJI_CONTROL {10000.0};
5675
//
@@ -79,10 +98,10 @@ class RC_Controls {
7998
int MAX_VALUE_ {2000};
8099
int MIN_VALUE_ {1000};
81100

82-
int throttle_sign {1};
83-
int yaw_sign {1};
84-
int roll_sign {1};
85-
int pitch_sign {1};
101+
int throttle_sign_ {1};
102+
int yaw_sign_ {1};
103+
int roll_sign_ {1};
104+
int pitch_sign_ {1};
86105

87106
unsigned int RANGE_;
88107
unsigned int ZERO_VALUE_;

include/vb_util_lib/rc_mapper.h

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
/* rm_mapper.h
2+
*
3+
* Created on: 6 March 2020
4+
* Author: tkeitel
5+
*/
6+
7+
#ifndef VISBOX_PACKAGES_COMMON_UTILS_UTIL_LIB_INCLUDE_VB_UTIL_LIB_RC_MAPPER_H_
8+
#define VISBOX_PACKAGES_COMMON_UTILS_UTIL_LIB_INCLUDE_VB_UTIL_LIB_RC_MAPPER_H_
9+
10+
#include <stdio.h>
11+
#include <string>
12+
#include <ros/ros.h>
13+
//#include <sensor_msgs/Joy.h>
14+
//#include <mavros_msgs/RCIn.h>
15+
16+
17+
class rc_mapper
18+
{
19+
public:
20+
// DJI
21+
#define DJI_RC_THROTTLE 3
22+
#define DJI_RC_YAW 2
23+
#define DJI_RC_ROLL 0
24+
#define DJI_RC_PITCH 1
25+
#define DJI_RC_GEAR 5
26+
#define DJI_RC_MODE 4
27+
#define DJI_RC_ARM 6
28+
29+
#define DJI_RC_THROTTLE_SIGN 1
30+
#define DJI_RC_YAW_SIGN 1
31+
#define DJI_RC_ROLL_SIGN 1
32+
#define DJI_RC_PITCH_SIGN 1
33+
34+
35+
#define DJI_RC_MAX_VALUE 1987
36+
#define DJI_RC_MIN_VALUE 998
37+
38+
// PX4
39+
#define PX4_RC_THROTTLE 2
40+
#define PX4_RC_YAW 3
41+
#define PX4_RC_ROLL 0
42+
#define PX4_RC_PITCH 1
43+
#define PX4_RC_GEAR 7
44+
#define PX4_RC_MODE 5
45+
#define PX4_RC_ARM 6
46+
47+
#define PX4_RC_THROTTLE_SIGN 1
48+
#define PX4_RC_YAW_SIGN 1
49+
#define PX4_RC_ROLL_SIGN 1
50+
#define PX4_RC_PITCH_SIGN 1
51+
52+
#define PX4_RC_MAX_VALUE 1987
53+
#define PX4_RC_MIN_VALUE 998
54+
55+
// ACSL
56+
#define ACSL_RC_THROTTLE 2
57+
#define ACSL_RC_YAW 3
58+
#define ACSL_RC_ROLL 0
59+
#define ACSL_RC_PITCH 1
60+
#define ACSL_RC_GEAR 8
61+
#define ACSL_RC_MODE 6
62+
#define ACSL_RC_ARM 9
63+
64+
#define ACSL_RC_THROTTLE_SIGN -1
65+
#define ACSL_RC_YAW_SIGN 1
66+
#define ACSL_RC_ROLL_SIGN 1
67+
#define ACSL_RC_PITCH_SIGN -1
68+
69+
#define ACSL_RC_MAX_VALUE 2020
70+
#define ACSL_RC_MIN_VALUE 1020
71+
72+
// Default
73+
#define DEFAULT_MIN_VALUE 1020
74+
#define DEFAULT_MAX_VALUE 2020
75+
76+
enum RC_Definitions
77+
{
78+
eRCThrottle = 0,
79+
eRCYaw,
80+
eRCRoll,
81+
eRCPitch,
82+
eRCGear,
83+
eRCMode,
84+
eRCArm,
85+
eEndOfRCDefinitions
86+
};
87+
88+
enum RC_Signs
89+
{
90+
eThrottleSign = 0,
91+
eYawSign,
92+
eRollSign,
93+
ePitchSign,
94+
eEndOfRCSigns
95+
};
96+
97+
enum RC_TYPES
98+
{
99+
eRCT_PX4 = 0,
100+
eRCT_DJI,
101+
eRCT_ACSL,
102+
eRCT_Unknown,
103+
eEndOfRCTypes
104+
};
105+
106+
rc_mapper(ros::NodeHandle n);
107+
108+
virtual ~rc_mapper();
109+
110+
int GetChannel(int _chan);
111+
112+
bool SetChannel(int _chan, int _signal);
113+
114+
115+
int GetMax(void);
116+
int GetMin(void);
117+
118+
void SetMax(int _max);
119+
void SetMin(int _min);
120+
121+
int GetSign(int _chan);
122+
123+
bool SetSign(int _chan, int _sign);
124+
125+
std::string GetRCType(void);
126+
std::string GetRCTypeName(void);
127+
RC_TYPES GetSetRC(void);
128+
129+
private:
130+
ros::NodeHandle m_Handle;
131+
RC_TYPES m_SetRC;
132+
std::string m_RCType;
133+
std::string m_RCTypeNames[eEndOfRCTypes];
134+
int m_Channels[eEndOfRCDefinitions];
135+
int m_Signs[eEndOfRCSigns];
136+
int m_MinValue;
137+
int m_MaxValue;
138+
139+
static bool Valid(int _chan);
140+
141+
void SetFromDefaults(void);
142+
143+
RC_TYPES DetermineRCSetting(std::string* _rctype);
144+
145+
void SetFromParameters(void);
146+
};
147+
148+
#endif
149+

src/vb_util_lib/rc_controls.cpp

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
#include <vb_util_lib/rc_controls.h>
9+
#include <vb_util_lib/rc_mapper.h>
910
#include <vb_util_lib/topics.h>
1011

1112
using namespace am;
@@ -52,13 +53,15 @@ RC_Controls::~RC_Controls() {
5253
// TODO Auto-generated destructor stub
5354
}
5455

55-
RC_Controls::RC_Controls(ros::NodeHandle& n, RC_TYPE type) : rc_type_(type) {
56+
RC_Controls::RC_Controls(ros::NodeHandle& n, RC_TYPE type) : rc_type_(type)
57+
{
58+
rc_mapper_ = new rc_mapper(n);
5659
setSubscriber(n);
5760
}
5861

5962
void RC_Controls::setSubscriber(ros::NodeHandle& n) {
6063
// Initialize the min and max constants
61-
n.param("/RC/max_value", MAX_VALUE_, MAX_VALUE_);
64+
/*n.param("/RC/max_value", MAX_VALUE_, MAX_VALUE_);
6265
n.param("/RC/min_value", MIN_VALUE_, MIN_VALUE_);
6366
6467
std::string rc_type;
@@ -101,10 +104,10 @@ void RC_Controls::setSubscriber(ros::NodeHandle& n) {
101104
mode_idx_ = ACSL_MODE;
102105
arm_idx_ = ACSL_ARM;
103106
104-
throttle_sign = ACSL_THROTTLE_SIGN;
105-
yaw_sign = ACSL_YAW_SIGN;
106-
roll_sign = ACSL_ROLL_SIGN;
107-
pitch_sign = ACSL_PITCH_SIGN;
107+
throttle_sign_ = ACSL_THROTTLE_SIGN;
108+
yaw_sign_ = ACSL_YAW_SIGN;
109+
roll_sign_ = ACSL_ROLL_SIGN;
110+
pitch_sign_ = ACSL_PITCH_SIGN;
108111
109112
break;
110113
@@ -120,13 +123,33 @@ void RC_Controls::setSubscriber(ros::NodeHandle& n) {
120123
mode_idx_ = PX4_MODE;
121124
arm_idx_ = PX4_ARM;
122125
123-
throttle_sign = PX4_THROTTLE_SIGN;
124-
yaw_sign = PX4_YAW_SIGN;
125-
roll_sign = PX4_ROLL_SIGN;
126-
pitch_sign = PX4_PITCH_SIGN;
126+
throttle_sign_ = PX4_THROTTLE_SIGN;
127+
yaw_sign_ = PX4_YAW_SIGN;
128+
roll_sign_ = PX4_ROLL_SIGN;
129+
pitch_sign_ = PX4_PITCH_SIGN;
127130
128131
break;
129-
}
132+
}*/
133+
134+
rc_type_ = static_cast<RC_TYPE>(rc_mapper_->GetSetRC());
135+
136+
MIN_VALUE_ = rc_mapper_->GetMin();
137+
MAX_VALUE_ = rc_mapper_->GetMax();
138+
139+
throttle_idx_ = rc_mapper_->GetChannel(rc_mapper::eRCThrottle);
140+
yaw_idx_ = rc_mapper_->GetChannel(rc_mapper::eRCYaw);
141+
roll_idx_ = rc_mapper_->GetChannel(rc_mapper::eRCRoll);
142+
pitch_idx_ = rc_mapper_->GetChannel(rc_mapper::eRCPitch);
143+
gear_idx_ = rc_mapper_->GetChannel(rc_mapper::eRCGear);
144+
mode_idx_ = rc_mapper_->GetChannel(rc_mapper::eRCMode);
145+
arm_idx_ = rc_mapper_->GetChannel(rc_mapper::eRCArm);
146+
147+
throttle_sign_ = rc_mapper_->GetSign(rc_mapper::eThrottleSign);
148+
yaw_sign_ = rc_mapper_->GetSign(rc_mapper::eRCYaw);
149+
roll_sign_ = rc_mapper_->GetSign(rc_mapper::eRollSign);
150+
pitch_sign_ = rc_mapper_->GetSign(rc_mapper::eRCPitch);
151+
152+
ROS_INFO("RC: RC Param Settings: throttle[%d], yaw[%d], roll[%d], pitch[%d], gear[%d], mode[%d], arm[%d], throttle_sign_[%d], yaw_sign_[%d], roll_sign_[%d], pitch_sign_[%d], max[%d], min[%d]", throttle_idx_, yaw_idx_, roll_idx_, pitch_idx_, gear_idx_, mode_idx_, arm_idx_, throttle_sign_, yaw_sign_, roll_sign_, pitch_sign_, MAX_VALUE_, MIN_VALUE_);
130153

131154
RANGE_ = ((MAX_VALUE_ - MIN_VALUE_)/2);
132155
ZERO_VALUE_ = (MIN_VALUE_ + RANGE_);
@@ -151,12 +174,19 @@ void RC_Controls::setDJIControls(const sensor_msgs::Joy::ConstPtr& msg) {
151174
stamp = msg->header.stamp;
152175

153176
// Set the raw values;
154-
throttle_ = msg->axes[3];
177+
/*throttle_ = msg->axes[3];
155178
yaw_ = msg->axes[2];
156179
pitch_ = msg->axes[1];
157180
roll_ = msg->axes[0];
158181
gear_ = msg->axes[5];
159-
mode_ = msg->axes[4];
182+
mode_ = msg->axes[4];*/
183+
184+
throttle_ = msg->axes[throttle_idx_];
185+
yaw_ = msg->axes[yaw_idx_];
186+
pitch_ = msg->axes[pitch_idx_];
187+
roll_ = msg->axes[roll_idx_];
188+
gear_ = msg->axes[gear_idx_];
189+
mode_ = msg->axes[mode_idx_];
160190

161191
setDJIStickValue(yaw_, yaw);
162192
setDJIStickValue(pitch_, pitch);
@@ -259,10 +289,10 @@ void RC_Controls::setPX4Controls(const mavros_msgs::RCIn::ConstPtr& msg) {
259289
mode_ = msg->channels[mode_idx_];
260290
armed_ = msg->channels[arm_idx_];
261291

262-
setPX4StickValue(yaw_, yaw, yaw_sign);
263-
setPX4StickValue(pitch_, pitch, pitch_sign);
264-
setPX4StickValue(roll_, roll, roll_sign);
265-
setPX4StickValue(throttle_, throttle, throttle_sign);
292+
setPX4StickValue(yaw_, yaw, yaw_sign_);
293+
setPX4StickValue(pitch_, pitch, pitch_sign_);
294+
setPX4StickValue(roll_, roll, roll_sign_);
295+
setPX4StickValue(throttle_, throttle, throttle_sign_);
266296

267297
setPX4ModeSwitch(mode_, mode);
268298
setPX4GearSwitch(gear_, gear);

0 commit comments

Comments
 (0)