Hi, I try to finish the services_quiz. I think I created everything according to the requirement. But the grader can’t find the “move_bb8_in_square_custom”. And the hint didn’t help. I tried to run the code I can see “/move_bb8_in_square_custom” using “rosservice list”
Thank you!
The following is my code and structure:
#include "geometry_msgs/Twist.h"
#include "ros/duration.h"
#include "ros/node_handle.h"
#include "ros/publisher.h"
#include "ros/service_server.h"
#include "services_quiz/BB8CustomServiceMessage.h"
#include "services_quiz/BB8CustomServiceMessageRequest.h"
#include "services_quiz/BB8CustomServiceMessageResponse.h"
#include <ros/ros.h>
ros::Publisher pub;
void move_square(float side) {
geometry_msgs::Twist msg;
for(int i = 0;i<4;i++){
msg.linear.x = 1;
msg.angular.z = 0;
pub.publish(msg);
ros::Duration(side).sleep();
msg.linear.x = 0;
msg.angular.z = 1;
pub.publish(msg);
ros::Duration(3.1415926 / 2).sleep();ƒ
}
msg.linear.x = 0;
msg.angular.z = 0;
pub.publish(msg);
}
bool mycallback(services_quiz::BB8CustomServiceMessageRequest &req,
services_quiz::BB8CustomServiceMessageResponse &res) {
for (int i = req.repetitions; i > 0; i--) {
move_square(req.side);
}
res.success = true;
return true;
}
int main(int argc, char **argv) {
ros::init(argc, argv, "bb8_move_custom_service_server");
ros::NodeHandle nh;
pub = nh.advertise<geometry_msgs::Twist>("/cmd_vel", 1);
ros::ServiceServer srvsvr =
nh.advertiseService("/move_bb8_in_square_custom", mycallback);
ros::spin();
return 0;
}
<launch>
<node pkg="services_quiz" type="bb8_move_custom_service_server" name="bb8_move_custom_service_server" output="screen"/>
</launch>