Dear all,
I followed the tutorial ´visual object recognition´. I was able to recognize a picture ´ARROW_LEFT´. However, in the provided node ´action_controller.cpp’ the ROSbot should be able to drive after recognition, but it does not drive at all.
This is my code:
#include <ros/ros.h>
#include <std_msgs/Float32MultiArray.h>
#include <geometry_msgs/Twist.h>
#define ARROW_LEFT 6
int id = 0;
ros::Publisher action_pub;
geometry_msgs::Twist set_vel;
void objectCallback(const std_msgs::Float32MultiArrayPtr &object) {
if (object->data.size() > 0) {
id = object->data[0];
switch (id) {
case ARROW_LEFT:
std::cout<<"photo recognized"<< std::endl;
set_vel.linear.x = 0;
set_vel.angular.z = 1;
break;
default: // other object
set_vel.linear.x = 0;
set_vel.angular.z = 0;
}
action_pub.publish(set_vel);
} else {
// No object detected
set_vel.linear.x = 0;
set_vel.angular.z = 0;
action_pub.publish(set_vel);
}
}
int main(int argc, char **argv) {
ros::init(argc, argv, “action_controller”);
ros::NodeHandle n("~");
ros::Rate loop_rate(50);
ros::Subscriber sub = n.subscribe("/objects", 1, objectCallback);
action_pub = n.advertise<geometry_msgs::Twist>("/cmd_vel", 1);
set_vel.linear.x = 0;
set_vel.linear.y = 0;
set_vel.linear.z = 0;
set_vel.angular.x = 0;
set_vel.angular.y = 0;
set_vel.angular.z = 0;
while (ros::ok()) {
ros::spinOnce();
loop_rate.sleep();
}
}
I know the photo is recognized because when I show the picture with ID 6 to the camera, it prints ’ photo recognized’. So the fault should be in set_vel.linear.x and set_vel.linear.y. I already tried several values for those msgs but the ROSbot did not respond to anything.
Can someone please tell me what I am doing wrong?
Kind regards,
Mark