How to access a ros message in a launch file?
Hello Is it possible to access a ros message in a launch file and based on the value of the message publish to another topic? Moreor like a conditional statement. I checked online and seems no method to access the ros messages in a launch file.
#!/usr/bin/env python3
import ros_compatibility as roscomp from ros_compatibility.node import CompatibleNode from ros_compatibility.qos import QoSProfile, DurabilityPolicy
from carla_msgs.msg import CarlaEgoVehicleStatus from ra_comm.msg import DriverWish import rospy
import sys
class RAssistCondition(CompatibleNode):
def __init__(self):
"""
Constructor
"""
super(RAssistCondition, self).__init__("ra_assist_condition")
self.role_name = self.get_param("role_name", "ego_vehicle")
self.driver_wish_pub = rospy.Publisher('/ra/core/smach/driver_wish', DriverWish, queue_size=10)
self.new_subscription(
CarlaEgoVehicleStatus,
"/carla/{}/vehicle_status".format(self.role_name),
self.racondition,
qos_profile=QoSProfile(depth=1, durability=DurabilityPolicy.TRANSIENT_LOCAL))
self.published = False
def racondition(self, vehicle_status):
if not vehicle_status.velocity: # pylint: disable=no-member
self.logerr("Cannot determine the vehicle velocity")
sys.exit(1)
self.vehicle_velocity = vehicle_status.velocity
self.logerr("Vehicle velocity info received. velocity={}".format(self.vehicle_velocity))
if (self.vehicle_velocity > 0) and not self.published:
try:
self.pubDriverWish()
self.published = True
self.logerr("publishing driver wish")
except:
self.logerr("Vehicle velocity info received. velocity={}".format(self.vehicle_velocity))
self.logerr("Error while publishing driver wish")
# publish function
def pubDriverWish(self):
curr_ts = rospy.Time.now()
self.logerr("publishing driver wish")
rospy.loginfo('[Display] Publish driver wish')
msg = DriverWish()
msg.Header.stamp = curr_ts
msg.driver_wish = True
self.driver_wish_pub.publish(msg)
def main(args=None): """ main function
:return:
"""
roscomp.init("ra_assit_condition", args)
ra_assit_condition = None
rospy.sleep(15)
try:
ra_assit_condition = RAssistCondition()
ra_assit_condition.spin()
rospy.logerr("Condition for reverse assist")
except KeyboardInterrupt:
pass
finally:
if ra_assit_condition is not None:
ra_assit_condition.logerr("Done, deleting twist to control")
del ra_assit_condition
roscomp.shutdown()
if __name__ == '__main__':
main()