@@ -79,54 +79,62 @@ def vector2PoseMsg(frame_id, position, attitude):
79
79
class SpacecraftMPC (Node ):
80
80
81
81
def __init__ (self ):
82
- super ().__init__ ('minimal_publisher' )
83
- qos_profile = QoSProfile (
84
- reliability = QoSReliabilityPolicy .RMW_QOS_POLICY_RELIABILITY_BEST_EFFORT ,
85
- durability = QoSDurabilityPolicy .RMW_QOS_POLICY_DURABILITY_TRANSIENT_LOCAL ,
86
- history = QoSHistoryPolicy .RMW_QOS_POLICY_HISTORY_KEEP_LAST ,
87
- depth = 1
82
+ super ().__init__ ('spacecraft_mpc' )
83
+
84
+ # Declare and retrieve the namespace parameter
85
+ self .declare_parameter ('namespace' , '' ) # Default to empty namespace
86
+ self .namespace = self .get_parameter ('namespace' ).value
87
+ self .namespace_prefix = f'/{ self .namespace } ' if self .namespace else ''
88
+
89
+ # QoS profiles
90
+ qos_profile_pub = QoSProfile (
91
+ reliability = QoSReliabilityPolicy .BEST_EFFORT ,
92
+ durability = QoSDurabilityPolicy .TRANSIENT_LOCAL ,
93
+ history = QoSHistoryPolicy .KEEP_LAST ,
94
+ depth = 0
95
+ )
96
+
97
+ qos_profile_sub = QoSProfile (
98
+ reliability = QoSReliabilityPolicy .BEST_EFFORT ,
99
+ durability = QoSDurabilityPolicy .VOLATILE ,
100
+ history = QoSHistoryPolicy .KEEP_LAST ,
101
+ depth = 0
88
102
)
89
103
90
104
# Get mode; rate, wrench, direct_allocation
91
105
self .mode = self .declare_parameter ('mode' , 'rate' ).value
92
106
93
107
self .status_sub = self .create_subscription (
94
108
VehicleStatus ,
95
- ' /fmu/out/vehicle_status' ,
109
+ f' { self . namespace_prefix } /fmu/out/vehicle_status' ,
96
110
self .vehicle_status_callback ,
97
- qos_profile )
111
+ qos_profile_sub )
98
112
99
113
self .attitude_sub = self .create_subscription (
100
114
VehicleAttitude ,
101
- ' /fmu/out/vehicle_attitude' ,
115
+ f' { self . namespace_prefix } /fmu/out/vehicle_attitude' ,
102
116
self .vehicle_attitude_callback ,
103
- qos_profile )
104
- self .angular_vel_sub = self .create_subscription (
105
- VehicleAngularVelocity ,
106
- '/fmu/out/vehicle_angular_velocity' ,
107
- self .vehicle_angular_velocity_callback ,
108
- qos_profile )
117
+ qos_profile_sub )
109
118
self .angular_vel_sub = self .create_subscription (
110
119
VehicleAngularVelocity ,
111
- ' /fmu/out/vehicle_angular_velocity' ,
120
+ f' { self . namespace_prefix } /fmu/out/vehicle_angular_velocity' ,
112
121
self .vehicle_angular_velocity_callback ,
113
- qos_profile )
122
+ qos_profile_sub )
114
123
self .local_position_sub = self .create_subscription (
115
124
VehicleLocalPosition ,
116
- ' /fmu/out/vehicle_local_position' ,
125
+ f' { self . namespace_prefix } /fmu/out/vehicle_local_position' ,
117
126
self .vehicle_local_position_callback ,
118
- qos_profile )
127
+ qos_profile_sub )
119
128
120
- self .set_pose_srv = self .create_service (SetPose , ' /set_pose' , self .add_set_pos_callback )
129
+ self .set_pose_srv = self .create_service (SetPose , f' { self . namespace_prefix } /set_pose' , self .add_set_pos_callback )
121
130
122
- self .publisher_offboard_mode = self .create_publisher (OffboardControlMode , '/fmu/in/offboard_control_mode' , qos_profile )
123
- self .publisher_rates_setpoint = self .create_publisher (VehicleRatesSetpoint , '/fmu/in/vehicle_rates_setpoint' , qos_profile )
124
- self .publisher_direct_actuator = self .create_publisher (ActuatorMotors , '/fmu/in/actuator_motors' , qos_profile )
125
- self .publisher_thrust_setpoint = self .create_publisher (VehicleThrustSetpoint , '/fmu/in/vehicle_thrust_setpoint' , qos_profile )
126
- self .publisher_torque_setpoint = self .create_publisher (VehicleTorqueSetpoint , '/fmu/in/vehicle_torque_setpoint' , qos_profile )
127
- self .predicted_path_pub = self .create_publisher (Path , '/px4_mpc/predicted_path' , 10 )
128
- self .reference_pub = self .create_publisher (Marker , "/px4_mpc/reference" , 10 )
129
- self .reference_pub = self .create_publisher (Marker , "/px4_mpc/reference" , 10 )
131
+ self .publisher_offboard_mode = self .create_publisher (OffboardControlMode , f'{ self .namespace_prefix } /fmu/in/offboard_control_mode' , qos_profile_pub )
132
+ self .publisher_rates_setpoint = self .create_publisher (VehicleRatesSetpoint , f'{ self .namespace_prefix } /fmu/in/vehicle_rates_setpoint' , qos_profile_pub )
133
+ self .publisher_direct_actuator = self .create_publisher (ActuatorMotors , f'{ self .namespace_prefix } /fmu/in/actuator_motors' , qos_profile_pub )
134
+ self .publisher_thrust_setpoint = self .create_publisher (VehicleThrustSetpoint , f'{ self .namespace_prefix } /fmu/in/vehicle_thrust_setpoint' , qos_profile_pub )
135
+ self .publisher_torque_setpoint = self .create_publisher (VehicleTorqueSetpoint , f'{ self .namespace_prefix } /fmu/in/vehicle_torque_setpoint' , qos_profile_pub )
136
+ self .predicted_path_pub = self .create_publisher (Path , f'{ self .namespace_prefix } /px4_mpc/predicted_path' , 10 )
137
+ self .reference_pub = self .create_publisher (Marker , f"{ self .namespace_prefix } /px4_mpc/reference" , 10 )
130
138
131
139
timer_period = 0.02 # seconds
132
140
self .timer = self .create_timer (timer_period , self .cmdloop_callback )
@@ -218,7 +226,7 @@ def publish_reference(self, pub, reference):
218
226
def publish_rate_setpoint (self , u_pred ):
219
227
thrust_rates = u_pred [0 , :]
220
228
# Hover thrust = 0.73
221
- thrust_command = thrust_rates [0 :3 ] * 0.07 # NOTE: Tune in thrust multiplier
229
+ thrust_command = thrust_rates [0 :3 ]
222
230
rates_setpoint_msg = VehicleRatesSetpoint ()
223
231
rates_setpoint_msg .timestamp = int (Clock ().now ().nanoseconds / 1000 )
224
232
rates_setpoint_msg .roll = float (thrust_rates [3 ])
0 commit comments