fix(simulation): use PX4 rover offboard control level
This commit is contained in:
@@ -13,6 +13,7 @@ from k1link.simulation.contracts import AckermannControlSetpoint
|
||||
OFFBOARD_HEARTBEAT_SECONDS: Final = 0.1
|
||||
OFFBOARD_WARMUP_HEARTBEATS: Final = 12
|
||||
OFFBOARD_ADMISSION_TIMEOUT_SECONDS: Final = 25.0
|
||||
STOCK_ROVER_MAX_THROTTLE_SPEED_MPS: Final = 3.1
|
||||
VEHICLE_COMMAND_DO_SET_MODE: Final = 176
|
||||
VEHICLE_COMMAND_COMPONENT_ARM_DISARM: Final = 400
|
||||
|
||||
@@ -177,9 +178,9 @@ class Ros2Px4AckermannControl:
|
||||
"/fmu/in/offboard_control_mode",
|
||||
qos,
|
||||
)
|
||||
speed_publisher = node.create_publisher(
|
||||
messages.RoverSpeedSetpoint,
|
||||
"/fmu/in/rover_speed_setpoint",
|
||||
throttle_publisher = node.create_publisher(
|
||||
messages.RoverThrottleSetpoint,
|
||||
"/fmu/in/rover_throttle_setpoint",
|
||||
qos,
|
||||
)
|
||||
steering_publisher = node.create_publisher(
|
||||
@@ -187,16 +188,6 @@ class Ros2Px4AckermannControl:
|
||||
"/fmu/in/rover_steering_setpoint",
|
||||
qos,
|
||||
)
|
||||
attitude_publisher = node.create_publisher(
|
||||
messages.RoverAttitudeSetpoint,
|
||||
"/fmu/in/rover_attitude_setpoint",
|
||||
qos,
|
||||
)
|
||||
rate_publisher = node.create_publisher(
|
||||
messages.RoverRateSetpoint,
|
||||
"/fmu/in/rover_rate_setpoint",
|
||||
qos,
|
||||
)
|
||||
command_publisher = node.create_publisher(
|
||||
messages.VehicleCommand,
|
||||
"/fmu/in/vehicle_command",
|
||||
@@ -245,10 +236,8 @@ class Ros2Px4AckermannControl:
|
||||
self._publish_setpoint(
|
||||
messages,
|
||||
offboard_publisher,
|
||||
speed_publisher,
|
||||
throttle_publisher,
|
||||
steering_publisher,
|
||||
attitude_publisher,
|
||||
rate_publisher,
|
||||
timestamp_us,
|
||||
speed_mps,
|
||||
steering_normalized,
|
||||
@@ -306,10 +295,8 @@ class Ros2Px4AckermannControl:
|
||||
def _publish_setpoint(
|
||||
messages: Any,
|
||||
offboard_publisher: Any,
|
||||
speed_publisher: Any,
|
||||
throttle_publisher: Any,
|
||||
steering_publisher: Any,
|
||||
attitude_publisher: Any,
|
||||
rate_publisher: Any,
|
||||
timestamp_us: int,
|
||||
speed_mps: float,
|
||||
steering_normalized: float,
|
||||
@@ -317,35 +304,25 @@ class Ros2Px4AckermannControl:
|
||||
offboard = messages.OffboardControlMode()
|
||||
offboard.timestamp = timestamp_us
|
||||
offboard.position = False
|
||||
offboard.velocity = True
|
||||
offboard.velocity = False
|
||||
offboard.acceleration = False
|
||||
offboard.attitude = False
|
||||
offboard.body_rate = False
|
||||
offboard.thrust_and_torque = False
|
||||
offboard.thrust_and_torque = True
|
||||
offboard.direct_actuator = False
|
||||
offboard_publisher.publish(offboard)
|
||||
|
||||
speed = messages.RoverSpeedSetpoint()
|
||||
speed.timestamp = timestamp_us
|
||||
speed.speed_body_x = float(speed_mps)
|
||||
speed.speed_body_y = math.nan
|
||||
speed_publisher.publish(speed)
|
||||
throttle = messages.RoverThrottleSetpoint()
|
||||
throttle.timestamp = timestamp_us
|
||||
throttle.throttle_body_x = float(speed_mps / STOCK_ROVER_MAX_THROTTLE_SPEED_MPS)
|
||||
throttle.throttle_body_y = math.nan
|
||||
throttle_publisher.publish(throttle)
|
||||
|
||||
steering = messages.RoverSteeringSetpoint()
|
||||
steering.timestamp = timestamp_us
|
||||
steering.normalized_steering_setpoint = float(steering_normalized)
|
||||
steering_publisher.publish(steering)
|
||||
|
||||
attitude = messages.RoverAttitudeSetpoint()
|
||||
attitude.timestamp = timestamp_us
|
||||
attitude.yaw_setpoint = math.nan
|
||||
attitude_publisher.publish(attitude)
|
||||
|
||||
rate = messages.RoverRateSetpoint()
|
||||
rate.timestamp = timestamp_us
|
||||
rate.yaw_rate_setpoint = math.nan
|
||||
rate_publisher.publish(rate)
|
||||
|
||||
@staticmethod
|
||||
def _publish_vehicle_command(
|
||||
messages: Any,
|
||||
|
||||
Reference in New Issue
Block a user