23 from robot_game
import rg_data
24 from geometry_msgs.msg
import Twist, Point
25 from nav_msgs.msg
import Odometry
26 from robot_game
import srv
35 srv_check_target =
None
52 request = srv.rg_get_target_srvRequest()
59 rospy.loginfo(
"Next target: [%f, %f]", recv.xt.x, recv.xt.y )
79 global xt, srv_check_target, srv_get_vel, sim_output
82 x = pose.pose.pose.position
85 req = srv.rg_check_srvRequest( x=x, xt=xt )
87 rospy.loginfo(
"Target Reached!" )
94 sim_output.publish( vel_data.vel )
100 rospy.loginfo(
"(Robot Game) Controller node closed." )
103 if __name__ ==
"__main__":
104 rospy.init_node(
"rg_controller_py" )
105 rospy.on_shutdown( controller_on_shutdown )
108 rospy.loginfo(
"(Controller) subscribing to: %s", rg_data.input_topic )
109 sim_input = rospy.Subscriber( rg_data.input_topic, Odometry, rg_controller_callback )
110 rospy.loginfo(
"(Controller) creating topic : %s", rg_data.output_topic )
111 sim_output = rospy.Publisher( rg_data.output_topic, Twist, queue_size=1 )
114 rospy.wait_for_service( rg_data.srv_name_check_target )
115 rospy.loginfo(
"(Controller) server : %s", rg_data.srv_name_check_target )
116 srv_check_target = rospy.ServiceProxy( rg_data.srv_name_check_target, srv.rg_check_srv )
118 rospy.wait_for_service( rg_data.srv_name_get_target )
119 rospy.loginfo(
"(Controller) server : %s", rg_data.srv_name_get_target )
120 srv_get_target = rospy.ServiceProxy( rg_data.srv_name_get_target, srv.rg_get_target_srv )
122 rospy.wait_for_service( rg_data.srv_name_get_velocity )
123 rospy.loginfo(
"(Controller) server : %s", rg_data.srv_name_get_velocity )
124 srv_get_vel = rospy.ServiceProxy( rg_data.srv_name_get_velocity, srv.rg_get_vel_srv )
127 rospy.wait_for_service( rg_data.srv_name_get_target )
128 rospy.loginfo(
"(Controller) getting initial target" )
131 rospy.loginfo(
"(Robot Game) Controller started! Spinning..." )
srv_get_vel
Service entry point for getting a linear planar twist.
srv_check_target
Service entry point for checking if the target is reached.
srv_get_target
Service entry point for requiring a nwe random target.
def get_new_target()
Ask the service for a new target to reach.
def controller_on_shutdown()
Called when shutdown signal is raised.
def rg_controller_callback(pose)
The main callback of the node.