Hi, I have questions regarding exercise 6.3,
I’ve been dealing with this for hours but I couldn’t solve it.
the code is below
bb8_move_custom_service_server.py
#! /usr/bin/env python
import rospkg
import rospy
from my_custom_srv_msg_pkg import MyCustomServiceMessage, MyCustomServiceMessageResponse
from geometry_msgs.msg import Twist
def my_callback(request):
rospy.loginfo("The Service move_bb8_in_circle_custom has been called")
move_circle.linear.x = 0.2
move_circle.angular.z = 0.2
i = 0
while i <= request.duration:
my_pub.publish(move_circle)
rate.sleep()
i=i+1
move_circle.linear.x = 0
move_circle.angular.z = 0
my_pub.publish(move_circle)
rospy.loginfo("Finished service move_bb8_in_circle_custom")
response = MyCustomServiceMessageResponse()
response.success = True
return response # the service Response class, in this case EmptyResponse
rospy.init_node('service_move_bb8_in_circle_custom_server')
my_service = rospy.Service('/move_bb8_in_circle_custom', MyCustomServiceMessage , my_callback) # create the Service called move_bb8_in_circle with the defined callback
my_pub = rospy.Publisher('/cmd_vel', Twist, queue_size=1)
move_circle = Twist()
rate = rospy.Rate(1)
rospy.loginfo("Service /move_bb8_in_circle_custom Ready")
rospy.spin() # mantain the service open.
launch file
<launch>
<node pkg ="my_custom_srv_msg_pkg"
type="bb8_move_custom_service_server.py"
name="service_server"
output="screen">
</node>
</launch>
Cmakelist
cmake_minimum_required(VERSION 2.8.3)
project(my_custom_srv_msg_pkg)
find_package(catkin REQUIRED COMPONENTS
std_msgs
message_generation
)
add_service_files(
FILES
MyCustomServiceMessage.srv
)
generate_messages(
DEPENDENCIES
std_msgs
)
catkin_package(
CATKIN_DEPENDS rospy
)
include_directories(
${catkin_INCLUDE_DIRS}
)
package.xml
<?xml version="1.0"?>
<package format="2">
<name>my_custom_srv_msg_pkg</name>
<version>0.0.0</version>
<description>The my_custom_srv_msg_pkg package</description>
<maintainer email="user@todo.todo">user</maintainer>
<license>TODO</license>
<buildtool_depend>catkin</buildtool_depend>
<build_depend>rospy</build_depend>
<build_depend>std_msgs</build_depend>
<build_depend>message_generation</build_depend>
<build_export_depend>rospy</build_export_depend>
<exec_depend>rospy</exec_depend>
<build_export_depend>std_msgs</build_export_depend>
<exec_depend>std_msgs</exec_depend>
<build_export_depend>message_runtime</build_export_depend>
<exec_depend>message_runtime</exec_depend>
<export>
</export>
</package>
I already compile the package, delete “build” and “devel” folder and compile it again, but it seems when i tried to launch it, the results are always same.
could someone please help? thanks in advanced