Skip to content

Commit 5646ba4

Browse files
Crowdedlightvooon
authored andcommitted
removed prefix in enums in messages and changed to use existing functions for string and quaternion convert
1 parent 9635084 commit 5646ba4

File tree

5 files changed

+50
-68
lines changed

5 files changed

+50
-68
lines changed

mavros_extras/src/plugins/gimbal_control.cpp

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,8 @@ class GimbalControlPlugin : public plugin::Plugin
257257
gimbal_attitude_msg.target_system = mo.target_system;
258258
gimbal_attitude_msg.target_component = mo.target_component;
259259
gimbal_attitude_msg.flags = mo.flags;
260-
geometry_msgs::msg::Quaternion q;
261-
q.w = mo.q[0];
262-
q.x = mo.q[1];
263-
q.y = mo.q[2];
264-
q.z = mo.q[3];
265-
gimbal_attitude_msg.q = q;
260+
auto q = mavros::ftf::mavlink_to_quaternion(mo.q);
261+
gimbal_attitude_msg.q = tf2::toMsg(q);
266262
gimbal_attitude_msg.angular_velocity_x = mo.angular_velocity_x;
267263
gimbal_attitude_msg.angular_velocity_y = mo.angular_velocity_y;
268264
gimbal_attitude_msg.angular_velocity_z = mo.angular_velocity_z;
@@ -298,20 +294,6 @@ class GimbalControlPlugin : public plugin::Plugin
298294
gimbal_manager_status_pub->publish(gimbal_manager_status_msg);
299295
}
300296

301-
/**
302-
* @brief Helper function for converting char arrays from GimbalDeviceInformation msg to string
303-
*
304-
* @param a - array of chars from GimbalDeviceInformation Mavlink msg
305-
* @param size - The size of the char array
306-
*/
307-
std::string convertToString(std::array<char, 32> a, int size) {
308-
std::string s = "";
309-
for (int i=0; i<size; i++) {
310-
s += a[i];
311-
}
312-
return s;
313-
}
314-
315297
/**
316298
* @brief Publish gimbal device information - Note: this message is only published on request by default (see device_get_info_cb)
317299
*
@@ -326,9 +308,9 @@ class GimbalControlPlugin : public plugin::Plugin
326308
{
327309
mavros_msgs::msg::GimbalDeviceInformation gimbal_device_information_msg;
328310
gimbal_device_information_msg.header = uas->synchronized_header(frame_id, di.time_boot_ms);
329-
gimbal_device_information_msg.vendor_name = convertToString(di.vendor_name, sizeof(di.vendor_name));
330-
gimbal_device_information_msg.model_name = convertToString(di.model_name, sizeof(di.model_name));
331-
gimbal_device_information_msg.custom_name = convertToString(di.custom_name, sizeof(di.custom_name));
311+
gimbal_device_information_msg.vendor_name = mavlink::to_string(di.vendor_name);
312+
gimbal_device_information_msg.model_name = mavlink::to_string(di.model_name);
313+
gimbal_device_information_msg.custom_name = mavlink::to_string(di.custom_name);
332314
gimbal_device_information_msg.firmware_version = di.firmware_version;
333315
gimbal_device_information_msg.hardware_version = di.hardware_version;
334316
gimbal_device_information_msg.uid = di.uid;

mavros_msgs/msg/GimbalDeviceAttitudeStatus.msg

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ uint8 target_component # Component ID
88

99
uint16 flags # Current gimbal flags set (bitwise) - See GIMBAL_DEVICE_FLAGS
1010
#GIMBAL_DEVICE_FLAGS
11-
uint16 GIMBAL_DEVICE_FLAGS_RETRACT = 1 # Set to retracted safe position (no stabilization), takes presedence over all other flags.
12-
uint16 GIMBAL_DEVICE_FLAGS_NEUTRAL = 2 # Set to neutral/default position, taking precedence over all other flags except RETRACT. Neutral is commonly forward-facing and horizontal (pitch=yaw=0) but may be any orientation.
13-
uint16 GIMBAL_DEVICE_FLAGS_ROLL_LOCK = 4 # Lock roll angle to absolute angle relative to horizon (not relative to drone). This is generally the default with a stabilizing gimbal.
14-
uint16 GIMBAL_DEVICE_FLAGS_PITCH_LOCK = 8 # Lock pitch angle to absolute angle relative to horizon (not relative to drone). This is generally the default.
15-
uint16 GIMBAL_DEVICE_FLAGS_YAW_LOCK = 16 # Lock yaw angle to absolute angle relative to North (not relative to drone). If this flag is set, the quaternion is in the Earth frame with the x-axis pointing North (yaw absolute). If this flag is not set, the quaternion frame is in the Earth frame rotated so that the x-axis is pointing forward (yaw relative to vehicle).
11+
uint16 FLAGS_RETRACT = 1 # Set to retracted safe position (no stabilization), takes presedence over all other flags.
12+
uint16 FLAGS_NEUTRAL = 2 # Set to neutral/default position, taking precedence over all other flags except RETRACT. Neutral is commonly forward-facing and horizontal (pitch=yaw=0) but may be any orientation.
13+
uint16 FLAGS_ROLL_LOCK = 4 # Lock roll angle to absolute angle relative to horizon (not relative to drone). This is generally the default with a stabilizing gimbal.
14+
uint16 FLAGS_PITCH_LOCK = 8 # Lock pitch angle to absolute angle relative to horizon (not relative to drone). This is generally the default.
15+
uint16 FLAGS_YAW_LOCK = 16 # Lock yaw angle to absolute angle relative to North (not relative to drone). If this flag is set, the quaternion is in the Earth frame with the x-axis pointing North (yaw absolute). If this flag is not set, the quaternion frame is in the Earth frame rotated so that the x-axis is pointing forward (yaw relative to vehicle).
1616

1717
geometry_msgs/Quaternion q # Quaternion, x, y, z, w (0 0 0 1 is the null-rotation, the frame is depends on whether the flag GIMBAL_DEVICE_FLAGS_YAW_LOCK is set)
1818
float32 angular_velocity_x # X component of angular velocity (NaN if unknown)
@@ -21,12 +21,12 @@ float32 angular_velocity_z # Z component of angular velocity (NaN if unknow
2121

2222
uint32 failure_flags # Failure flags (0 for no failure) (bitwise) - See GIMBAL_DEVICE_ERROR_FLAGS
2323
#GIMBAL_DEVICE_ERROR_FLAGS
24-
uint32 GIMBAL_DEVICE_ERROR_FLAGS_AT_ROLL_LIMIT = 1 # Gimbal device is limited by hardware roll limit.
25-
uint32 GIMBAL_DEVICE_ERROR_FLAGS_AT_PITCH_LIMIT = 2 # Gimbal device is limited by hardware pitch limit.
26-
uint32 GIMBAL_DEVICE_ERROR_FLAGS_AT_YAW_LIMIT = 4 # Gimbal device is limited by hardware yaw limit.
27-
uint32 GIMBAL_DEVICE_ERROR_FLAGS_ENCODER_ERROR = 8 # There is an error with the gimbal encoders.
28-
uint32 GIMBAL_DEVICE_ERROR_FLAGS_POWER_ERROR = 16 # There is an error with the gimbal power source.
29-
uint32 GIMBAL_DEVICE_ERROR_FLAGS_MOTOR_ERROR = 32 # There is an error with the gimbal motor's.
30-
uint32 GIMBAL_DEVICE_ERROR_FLAGS_SOFTWARE_ERROR = 64 # There is an error with the gimbal's software.
31-
uint32 GIMBAL_DEVICE_ERROR_FLAGS_COMMS_ERROR = 128 # There is an error with the gimbal's communication.
32-
uint32 GIMBAL_DEVICE_ERROR_FLAGS_CALIBRATION_RUNNING = 256 # Gimbal is currently calibrating.
24+
uint32 ERROR_FLAGS_AT_ROLL_LIMIT = 1 # Gimbal device is limited by hardware roll limit.
25+
uint32 ERROR_FLAGS_AT_PITCH_LIMIT = 2 # Gimbal device is limited by hardware pitch limit.
26+
uint32 ERROR_FLAGS_AT_YAW_LIMIT = 4 # Gimbal device is limited by hardware yaw limit.
27+
uint32 ERROR_FLAGS_ENCODER_ERROR = 8 # There is an error with the gimbal encoders.
28+
uint32 ERROR_FLAGS_POWER_ERROR = 16 # There is an error with the gimbal power source.
29+
uint32 ERROR_FLAGS_MOTOR_ERROR = 32 # There is an error with the gimbal motor's.
30+
uint32 ERROR_FLAGS_SOFTWARE_ERROR = 64 # There is an error with the gimbal's software.
31+
uint32 ERROR_FLAGS_COMMS_ERROR = 128 # There is an error with the gimbal's communication.
32+
uint32 ERROR_FLAGS_CALIBRATION_RUNNING = 256 # Gimbal is currently calibrating.

mavros_msgs/msg/GimbalDeviceInformation.msg

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ uint64 uid # UID of gimbal hardware (0 if unknown).
1212

1313
uint32 cap_flags # Bitmap of gimbal capability flags - see GIMBAL_DEVICE_CAP_FLAGS
1414
#GIMBAL_DEVICE_CAP_FLAGS
15-
uint32 GIMBAL_DEVICE_CAP_FLAGS_HAS_RETRACT = 1 # Gimbal device supports a retracted position
16-
uint32 GIMBAL_DEVICE_CAP_FLAGS_HAS_NEUTRAL = 2 # Gimbal device supports a horizontal, forward looking position, stabilized
17-
uint32 GIMBAL_DEVICE_CAP_FLAGS_HAS_ROLL_AXIS = 4 # Gimbal device supports rotating around roll axis.
18-
uint32 GIMBAL_DEVICE_CAP_FLAGS_HAS_ROLL_FOLLOW = 8 # Gimbal device supports to follow a roll angle relative to the vehicle
19-
uint32 GIMBAL_DEVICE_CAP_FLAGS_HAS_ROLL_LOCK = 16 # Gimbal device supports locking to an roll angle (generally that's the default with roll stabilized)
20-
uint32 GIMBAL_DEVICE_CAP_FLAGS_HAS_PITCH_AXIS = 32 # Gimbal device supports rotating around pitch axis.
21-
uint32 GIMBAL_DEVICE_CAP_FLAGS_HAS_PITCH_FOLLOW = 64 # Gimbal device supports to follow a pitch angle relative to the vehicle
22-
uint32 GIMBAL_DEVICE_CAP_FLAGS_HAS_PITCH_LOCK = 128 # Gimbal device supports locking to an pitch angle (generally that's the default with pitch stabilized)
23-
uint32 GIMBAL_DEVICE_CAP_FLAGS_HAS_YAW_AXIS = 256 # Gimbal device supports rotating around yaw axis.
24-
uint32 GIMBAL_DEVICE_CAP_FLAGS_HAS_YAW_FOLLOW = 512 # Gimbal device supports to follow a yaw angle relative to the vehicle (generally that's the default)
25-
uint32 GIMBAL_DEVICE_CAP_FLAGS_HAS_YAW_LOCK = 1024 # Gimbal device supports locking to an absolute heading (often this is an option available)
26-
uint32 GIMBAL_DEVICE_CAP_FLAGS_SUPPORTS_INFINITE_YAW = 2048 # Gimbal device supports yawing/panning infinetely (e.g. using slip disk).
15+
uint32 CAP_FLAGS_HAS_RETRACT = 1 # Gimbal device supports a retracted position
16+
uint32 CAP_FLAGS_HAS_NEUTRAL = 2 # Gimbal device supports a horizontal, forward looking position, stabilized
17+
uint32 CAP_FLAGS_HAS_ROLL_AXIS = 4 # Gimbal device supports rotating around roll axis.
18+
uint32 CAP_FLAGS_HAS_ROLL_FOLLOW = 8 # Gimbal device supports to follow a roll angle relative to the vehicle
19+
uint32 CAP_FLAGS_HAS_ROLL_LOCK = 16 # Gimbal device supports locking to an roll angle (generally that's the default with roll stabilized)
20+
uint32 CAP_FLAGS_HAS_PITCH_AXIS = 32 # Gimbal device supports rotating around pitch axis.
21+
uint32 CAP_FLAGS_HAS_PITCH_FOLLOW = 64 # Gimbal device supports to follow a pitch angle relative to the vehicle
22+
uint32 CAP_FLAGS_HAS_PITCH_LOCK = 128 # Gimbal device supports locking to an pitch angle (generally that's the default with pitch stabilized)
23+
uint32 CAP_FLAGS_HAS_YAW_AXIS = 256 # Gimbal device supports rotating around yaw axis.
24+
uint32 CAP_FLAGS_HAS_YAW_FOLLOW = 512 # Gimbal device supports to follow a yaw angle relative to the vehicle (generally that's the default)
25+
uint32 CAP_FLAGS_HAS_YAW_LOCK = 1024 # Gimbal device supports locking to an absolute heading (often this is an option available)
26+
uint32 CAP_FLAGS_SUPPORTS_INFINITE_YAW = 2048 # Gimbal device supports yawing/panning infinetely (e.g. using slip disk).
2727

2828
uint16 custom_cap_flags # Bitmap for use for gimbal-specific capability flags.
2929
float32 roll_min # Minimum hardware roll angle (positive: rolling to the right, negative: rolling to the left)

mavros_msgs/msg/GimbalDeviceSetAttitude.msg

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ uint8 target_component # Component ID
66

77
uint16 flags # Low level gimbal flags (bitwise) - See GIMBAL_DEVICE_FLAGS
88
#GIMBAL_DEVICE_FLAGS
9-
uint16 GIMBAL_DEVICE_FLAGS_RETRACT = 1 # Based on GIMBAL_DEVICE_FLAGS_RETRACT
10-
uint16 GIMBAL_DEVICE_FLAGS_NEUTRAL = 2 # Based on GIMBAL_DEVICE_FLAGS_NEUTRAL
11-
uint16 GIMBAL_DEVICE_FLAGS_ROLL_LOCK = 4 # Based on GIMBAL_DEVICE_FLAGS_ROLL_LOCK
12-
uint16 GIMBAL_DEVICE_FLAGS_PITCH_LOCK = 8 # Based on GIMBAL_DEVICE_FLAGS_PITCH_LOCK
13-
uint16 GIMBAL_DEVICE_FLAGS_YAW_LOCK = 16 # Based on GIMBAL_DEVICE_FLAGS_YAW_LOCK
9+
uint16 FLAGS_RETRACT = 1 # Based on GIMBAL_DEVICE_FLAGS_RETRACT
10+
uint16 FLAGS_NEUTRAL = 2 # Based on GIMBAL_DEVICE_FLAGS_NEUTRAL
11+
uint16 FLAGS_ROLL_LOCK = 4 # Based on GIMBAL_DEVICE_FLAGS_ROLL_LOCK
12+
uint16 FLAGS_PITCH_LOCK = 8 # Based on GIMBAL_DEVICE_FLAGS_PITCH_LOCK
13+
uint16 FLAGS_YAW_LOCK = 16 # Based on GIMBAL_DEVICE_FLAGS_YAW_LOCK
1414

1515
geometry_msgs/Quaternion q # Quaternion, x, y, z, w (0 0 0 1 is the null-rotation, the frame is depends on whether the flag GIMBAL_DEVICE_FLAGS_YAW_LOCK is set)
1616
float32 angular_velocity_x # X component of angular velocity, positive is rolling to the right, NaN to be ignored.

mavros_msgs/msg/GimbalManagerInformation.msg

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@ std_msgs/Header header
55

66
uint32 cap_flags # Bitmap of gimbal capability flags - see GIMBAL_MANAGER_CAP_FLAGS
77
#GIMBAL_MANAGER_CAP_FLAGS
8-
uint32 GIMBAL_MANAGER_CAP_FLAGS_HAS_RETRACT = 1 # Based on GIMBAL_DEVICE_CAP_FLAGS_HAS_RETRACT.
9-
uint32 GIMBAL_MANAGER_CAP_FLAGS_HAS_NEUTRAL = 2 # Based on GIMBAL_DEVICE_CAP_FLAGS_HAS_NEUTRAL.
10-
uint32 GIMBAL_MANAGER_CAP_FLAGS_HAS_ROLL_AXIS = 4 # Based on GIMBAL_DEVICE_CAP_FLAGS_HAS_ROLL_AXIS.
11-
uint32 GIMBAL_MANAGER_CAP_FLAGS_HAS_ROLL_FOLLOW = 8 # Based on GIMBAL_DEVICE_CAP_FLAGS_HAS_ROLL_FOLLOW.
12-
uint32 GIMBAL_MANAGER_CAP_FLAGS_HAS_ROLL_LOCK = 16 # Based on GIMBAL_DEVICE_CAP_FLAGS_HAS_ROLL_LOCK.
13-
uint32 GIMBAL_MANAGER_CAP_FLAGS_HAS_PITCH_AXIS = 32 # Based on GIMBAL_DEVICE_CAP_FLAGS_HAS_PITCH_AXIS.
14-
uint32 GIMBAL_MANAGER_CAP_FLAGS_HAS_PITCH_FOLLOW = 64 # Based on GIMBAL_DEVICE_CAP_FLAGS_HAS_PITCH_FOLLOW.
15-
uint32 GIMBAL_MANAGER_CAP_FLAGS_HAS_PITCH_LOCK = 128 # Based on GIMBAL_DEVICE_CAP_FLAGS_HAS_PITCH_LOCK.
16-
uint32 GIMBAL_MANAGER_CAP_FLAGS_HAS_YAW_AXIS = 256 # Based on GIMBAL_DEVICE_CAP_FLAGS_HAS_YAW_AXIS.
17-
uint32 GIMBAL_MANAGER_CAP_FLAGS_HAS_YAW_FOLLOW = 512 # Based on GIMBAL_DEVICE_CAP_FLAGS_HAS_YAW_FOLLOW.
18-
uint32 GIMBAL_MANAGER_CAP_FLAGS_HAS_YAW_LOCK = 1024 # Based on GIMBAL_DEVICE_CAP_FLAGS_HAS_YAW_LOCK.
19-
uint32 GIMBAL_MANAGER_CAP_FLAGS_SUPPORTS_INFINITE_YAW = 2048 # Based on GIMBAL_DEVICE_CAP_FLAGS_SUPPORTS_INFINITE_YAW.
20-
uint32 GIMBAL_MANAGER_CAP_FLAGS_CAN_POINT_LOCATION_LOCAL = 65536 # Gimbal manager supports to point to a local position.
21-
uint32 GIMBAL_MANAGER_CAP_FLAGS_CAN_POINT_LOCATION_GLOBAL = 131072 # Gimbal manager supports to point to a global latitude, longitude, altitude position.
8+
uint32 CAP_FLAGS_HAS_RETRACT = 1 # Based on GIMBAL_DEVICE_CAP_FLAGS_HAS_RETRACT.
9+
uint32 CAP_FLAGS_HAS_NEUTRAL = 2 # Based on GIMBAL_DEVICE_CAP_FLAGS_HAS_NEUTRAL.
10+
uint32 CAP_FLAGS_HAS_ROLL_AXIS = 4 # Based on GIMBAL_DEVICE_CAP_FLAGS_HAS_ROLL_AXIS.
11+
uint32 CAP_FLAGS_HAS_ROLL_FOLLOW = 8 # Based on GIMBAL_DEVICE_CAP_FLAGS_HAS_ROLL_FOLLOW.
12+
uint32 CAP_FLAGS_HAS_ROLL_LOCK = 16 # Based on GIMBAL_DEVICE_CAP_FLAGS_HAS_ROLL_LOCK.
13+
uint32 CAP_FLAGS_HAS_PITCH_AXIS = 32 # Based on GIMBAL_DEVICE_CAP_FLAGS_HAS_PITCH_AXIS.
14+
uint32 CAP_FLAGS_HAS_PITCH_FOLLOW = 64 # Based on GIMBAL_DEVICE_CAP_FLAGS_HAS_PITCH_FOLLOW.
15+
uint32 CAP_FLAGS_HAS_PITCH_LOCK = 128 # Based on GIMBAL_DEVICE_CAP_FLAGS_HAS_PITCH_LOCK.
16+
uint32 CAP_FLAGS_HAS_YAW_AXIS = 256 # Based on GIMBAL_DEVICE_CAP_FLAGS_HAS_YAW_AXIS.
17+
uint32 CAP_FLAGS_HAS_YAW_FOLLOW = 512 # Based on GIMBAL_DEVICE_CAP_FLAGS_HAS_YAW_FOLLOW.
18+
uint32 CAP_FLAGS_HAS_YAW_LOCK = 1024 # Based on GIMBAL_DEVICE_CAP_FLAGS_HAS_YAW_LOCK.
19+
uint32 CAP_FLAGS_SUPPORTS_INFINITE_YAW = 2048 # Based on GIMBAL_DEVICE_CAP_FLAGS_SUPPORTS_INFINITE_YAW.
20+
uint32 CAP_FLAGS_CAN_POINT_LOCATION_LOCAL = 65536 # Gimbal manager supports to point to a local position.
21+
uint32 CAP_FLAGS_CAN_POINT_LOCATION_GLOBAL = 131072 # Gimbal manager supports to point to a global latitude, longitude, altitude position.
2222

2323
uint8 gimbal_device_id # Gimbal device ID that this gimbal manager is responsible for.
2424
float32 roll_min # Minimum hardware roll angle (positive: rolling to the right, negative: rolling to the left)

0 commit comments

Comments
 (0)