我正在为自动驾驶系统开发 ROS。我在函数中定义并计算了一个值“优先级”,如下所示:
def odometry_weight_model(velocity, orientation, steering_angle):
"""Odometry based camera view prioritization model"""
rospy.loginfo(velocity)
rospy.loginfo(orientation)
rospy.loginfo(steering_angle)
....
for yaw_ang in CAM_LOC:
force_dir = yaw_ang + steer_angle
force = np.array([velocity, force_dir])
delta = (np.linalg.norm(force)) / (2 * math.pi) * const
**priority = prio_orig + delta**
现在,我想通过我定义的发布者发布 ROS 中的值。我创建了一个新主题并使用了“std_msgs.msg”包中的“Float32”类型,因为“优先级”是一个浮点值。我对发布者的尝试如下:
def main():
"""Run the view prioritization"""
rospy.init_node("view_prioritization", anonymous=True)
role_name = rospy.get_param("~role_name", "ego_vehicle")
sensor_definition_file = rospy.get_param(
"~sensor_definition_file",
"$(find telecarla_manual_control)/config/multi_sensors.json",
)
global CAM_LOC
with open(sensor_definition_file) as sensor_data:
multi_sensors = json.load(sensor_data)
CAM_LOC = []
for i in multi_sensors["sensors"]:
camera_loc.append(i["yaw"])
pub = rospy.Publisher(
"/carla/{role_name}/camera/rgb/view/priority",
Float32,
queue_size=10,
)
rospy.Subscriber(
"/carla/{role_name}/vehicle_status",
CarlaEgoVehicleStatus,
vehicle_status_callback,
)
rate = rospy.Rate(1)
while not rospy.is_shutdown():
pub.publish()
r.sleep()
rospy.spin()
在上面的代码中 - 我正在创建这个主题 - /carla/{role_name}/camera/rgb/view/priority - 并且想将“优先级”的值发布到这个主题 - 但是,我无法弄清楚想办法做到这一点,我仍然坚持如何通过仅使用 msg 包中的 Float32 类型来发送关于我的主题的优先级值。任何建议都会非常有帮助。