[英]Publishing a value calculated in a function in ROS
我正在為自動駕駛系統開發 ROS。 我在 function 中定義並計算了一個值“優先級”,如下所示:
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 類型來發送關於我的主題的優先級值。 任何建議都會非常有幫助。
我自己有點菜鳥,你沒有創建一個 Float32 消息來發布。
msg=Float32(某個值)
pub.publish(味精)
看看基本的 ROS 發布者/訂閱者教程——這正是你想要的
http://wiki.ros.org/ROS/Tutorials/WritingPublisherSubscriber%28python%29
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.