Skip to content

Commit 1d773b9

Browse files
committed
control: Update tilt_sensor node for attitude topic
1 parent e45c545 commit 1d773b9

File tree

2 files changed

+46
-49
lines changed

2 files changed

+46
-49
lines changed

oasis_control/oasis_control/launch/control_descriptions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ def add_tilt_sensor(ld: LaunchDescription, host_id: str) -> None:
222222
name=f"tilt_sensor_{host_id}",
223223
output="screen",
224224
remappings=[
225+
("attitude", f"{host_id}/attitude"),
225226
("imu", f"{host_id}/imu"),
226227
("imu_calibration", f"{host_id}/imu_calibration"),
227228
("tilt", f"{host_id}/tilt"),

oasis_control/oasis_control/nodes/tilt_sensor_node.py

Lines changed: 45 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
import rclpy.publisher
1818
import rclpy.qos
1919
import rclpy.subscription
20-
from builtin_interfaces.msg import Time
21-
from geometry_msgs.msg import Vector3Stamped
22-
from sensor_msgs.msg import Imu
20+
from builtin_interfaces.msg import Time as TimeMsg
21+
from geometry_msgs.msg import Vector3Stamped as Vector3StampedMsg
22+
from sensor_msgs.msg import Imu as ImuMsg
2323

2424
from oasis_control.localization.tilt_pose_estimator import ImuCalibration
2525
from oasis_control.localization.tilt_pose_estimator import TiltPoseEstimator
@@ -34,6 +34,7 @@
3434
NODE_NAME: str = "tilt_sensor"
3535

3636
# ROS topics
37+
ATTITUDE_TOPIC: str = "attitude"
3738
IMU_TOPIC: str = "imu"
3839
IMU_CALIBRATION_TOPIC: str = "imu_calibration"
3940
TILT_TOPIC: str = "tilt"
@@ -46,7 +47,6 @@
4647
PARAM_MAX_ACCEL_INFLATION: str = "max_accel_inflation"
4748
# Units: (rad/s)^2. Meaning: gyro bias random-walk variance parameter.
4849
PARAM_GYRO_BIAS_RW_VAR_RADS2: str = "gyro_bias_rw_var_rads2"
49-
PARAM_PUBLISH_TILT_RP: str = "publish_tilt_rp"
5050

5151
DEFAULT_NAMESPACE: str = "oasis"
5252
DEFAULT_ROBOT_NAME: str = "falcon"
@@ -72,6 +72,7 @@ def __init__(self) -> None:
7272
"""
7373
super().__init__(NODE_NAME)
7474

75+
# ROS parameter definitions
7576
self.declare_parameter(PARAM_FRAME_ID, "")
7677
self.declare_parameter(
7778
PARAM_ACCEL_TRUST_THRESHOLD, DEFAULT_ACCEL_TRUST_THRESHOLD_MPS2
@@ -82,12 +83,8 @@ def __init__(self) -> None:
8283
self.declare_parameter(
8384
PARAM_GYRO_BIAS_RW_VAR_RADS2, DEFAULT_GYRO_BIAS_RW_VAR_RADS2
8485
)
85-
self.declare_parameter(PARAM_PUBLISH_TILT_RP, False)
86-
87-
imu_topic: str = IMU_TOPIC
88-
imu_calib_topic: str = IMU_CALIBRATION_TOPIC
89-
tilt_topic: str = TILT_TOPIC
9086

87+
# ROS parameter state
9188
self._frame_id: str = str(self.get_parameter(PARAM_FRAME_ID).value)
9289
accel_trust_threshold: float = float(
9390
self.get_parameter(PARAM_ACCEL_TRUST_THRESHOLD).value
@@ -102,12 +99,13 @@ def __init__(self) -> None:
10299
gyro_bias_rw_var_rads2: float = float(
103100
self.get_parameter(PARAM_GYRO_BIAS_RW_VAR_RADS2).value
104101
)
105-
publish_tilt_rp: bool = bool(self.get_parameter(PARAM_PUBLISH_TILT_RP).value)
106102

107-
qos_profile: rclpy.qos.QoSProfile = (
108-
rclpy.qos.QoSPresetProfiles.SENSOR_DATA.value
109-
)
103+
# Node state
104+
self._calibration: Optional[ImuCalibration] = None
105+
self._last_imu_time: Optional[float] = None
106+
self._last_dt_spike_log_time: Optional[float] = None
110107

108+
# Tilt estimator
111109
self._estimator: TiltPoseEstimator = TiltPoseEstimator(
112110
accel_trust_threshold_mps2=accel_trust_threshold,
113111
yaw_variance_rad2=yaw_variance,
@@ -116,37 +114,36 @@ def __init__(self) -> None:
116114
gyro_bias_rw_var_rads2=gyro_bias_rw_var_rads2,
117115
)
118116

119-
self._tilt_pub: rclpy.publisher.Publisher = self.create_publisher(
120-
msg_type=Imu,
121-
topic=tilt_topic,
122-
qos_profile=qos_profile,
117+
# ROS QoS profile
118+
qos_profile: rclpy.qos.QoSProfile = (
119+
rclpy.qos.QoSPresetProfiles.SENSOR_DATA.value
123120
)
124121

125-
self._tilt_rp_pub: Optional[rclpy.publisher.Publisher] = None
126-
if publish_tilt_rp:
127-
self._tilt_rp_pub = self.create_publisher(
128-
msg_type=Vector3Stamped,
129-
topic=f"{tilt_topic}_rp",
130-
qos_profile=qos_profile,
131-
)
132-
133-
self._imu_calib_sub: rclpy.subscription.Subscription = self.create_subscription(
134-
msg_type=ImuCalibrationMsg,
135-
topic=imu_calib_topic,
136-
callback=self._handle_calibration,
122+
# ROS publishers
123+
self._attitude_pub: rclpy.publisher.Publisher = self.create_publisher(
124+
msg_type=Vector3StampedMsg,
125+
topic=ATTITUDE_TOPIC,
126+
qos_profile=qos_profile,
127+
)
128+
self._tilt_pub: rclpy.publisher.Publisher = self.create_publisher(
129+
msg_type=ImuMsg,
130+
topic=TILT_TOPIC,
137131
qos_profile=qos_profile,
138132
)
139133

134+
# ROS subscribers
140135
self._imu_sub: rclpy.subscription.Subscription = self.create_subscription(
141-
msg_type=Imu,
142-
topic=imu_topic,
136+
msg_type=ImuMsg,
137+
topic=IMU_TOPIC,
143138
callback=self._handle_imu,
144139
qos_profile=qos_profile,
145140
)
146-
147-
self._calibration: Optional[ImuCalibration] = None
148-
self._last_imu_time: Optional[float] = None
149-
self._last_dt_spike_log_time: Optional[float] = None
141+
self._imu_calib_sub: rclpy.subscription.Subscription = self.create_subscription(
142+
msg_type=ImuCalibrationMsg,
143+
topic=IMU_CALIBRATION_TOPIC,
144+
callback=self._handle_calibration,
145+
qos_profile=qos_profile,
146+
)
150147

151148
self.get_logger().info("Tilt sensor initialized")
152149

@@ -167,11 +164,11 @@ def _handle_calibration(self, message: ImuCalibrationMsg) -> None:
167164

168165
self._calibration = calibration
169166

170-
def _handle_imu(self, message: Imu) -> None:
167+
def _handle_imu(self, message: ImuMsg) -> None:
171168
if self._calibration is None:
172169
return
173170

174-
stamp: Time = message.header.stamp
171+
stamp: TimeMsg = message.header.stamp
175172
timestamp: float = float(stamp.sec) + float(stamp.nanosec) * 1.0e-9
176173
if self._last_imu_time is None:
177174
dt_s: float = 0.0
@@ -211,7 +208,7 @@ def _handle_imu(self, message: Imu) -> None:
211208
if not updated:
212209
return
213210

214-
tilt_message: Imu = Imu()
211+
tilt_message: ImuMsg = ImuMsg()
215212
tilt_message.header.stamp = message.header.stamp
216213
tilt_message.header.frame_id = (
217214
self._frame_id if self._frame_id else message.header.frame_id
@@ -242,17 +239,16 @@ def _handle_imu(self, message: Imu) -> None:
242239

243240
self._tilt_pub.publish(tilt_message)
244241

245-
if self._tilt_rp_pub is not None:
246-
roll: float
247-
pitch: float
248-
roll, pitch, _ = self._estimator.attitude_rpy()
249-
rp_message: Vector3Stamped = Vector3Stamped()
250-
rp_message.header.stamp = message.header.stamp
251-
rp_message.header.frame_id = tilt_message.header.frame_id
252-
rp_message.vector.x = roll
253-
rp_message.vector.y = pitch
254-
rp_message.vector.z = 0.0
255-
self._tilt_rp_pub.publish(rp_message)
242+
roll: float
243+
pitch: float
244+
roll, pitch, _ = self._estimator.attitude_rpy()
245+
attitude_message: Vector3StampedMsg = Vector3StampedMsg()
246+
attitude_message.header.stamp = message.header.stamp
247+
attitude_message.header.frame_id = tilt_message.header.frame_id
248+
attitude_message.vector.x = roll
249+
attitude_message.vector.y = pitch
250+
attitude_message.vector.z = 0.0
251+
self._attitude_pub.publish(attitude_message)
256252

257253
def _calibration_from_message(
258254
self, message: ImuCalibrationMsg

0 commit comments

Comments
 (0)