I tried setting a move command where the pick command was and it also doesn't return, but if I put the move command in the main function it returns normally. My code is like this:
// ros
#include <ros/ros.h>
// MoveIt!
#include <moveit/planning_scene_monitor/planning_scene_monitor.h>
#include <moveit/move_group_interface/move_group.h>
#include <shape_tools/solid_primitive_dims.h>
// transform library
#include <tf/tf.h>
#include <baxter_controller_communication/ObjectPosition.h>
static const std::string ROBOT_DESCRIPTION="robot_description";
bool IN_POSITION = false;
// callback of object recognized messages
void objectMoveCallback(const baxter_controller_communication::ObjectPosition::ConstPtr& msg, const ros::Publisher& collisionObject_pub, moveit::planning_interface::MoveGroup *group)
{
// checks if robot is in home position and, if not, does nothing
if (!IN_POSITION)
return;
// sets in home position as false
IN_POSITION = false;
ROS_INFO("Position:\tx: %lf\n\t\ty: %lf\n\t\tz: %lf", msg->position.x, msg->position.y, msg->position.z);
ROS_INFO("Size:\tw: %lf\n\t\tl: %lf", msg->size.width, msg->size.length);
// counts number of objects picked
static int count = 0;
count++;
// sends robot arm to drop position
// this is where the pick function would be ---------------------------------------
ROS_DEBUG("Going to drop position!");
group->setNamedTarget("drop_left");
group->move();
ROS_DEBUG("/Going to drop position!");
}
int main(int argc, char **argv)
{
// starts ros with a asyncronous spinner (needed for pick operations to return with success or failure)
ros::init (argc, argv, "left_arm_pick_place");
ros::AsyncSpinner spinner(1);
spinner.start();
// set verbosity/logging level to debug
log4cxx::LoggerPtr my_logger = log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME);
my_logger->setLevel(ros::console::g_level_lookup[ros::console::levels::Debug]);
// starts node handling and messages subscribing and publishing
ros::NodeHandle nh;
// subscribes to object recognition messages
// starts left arm as planning group
moveit::planning_interface::MoveGroup *group = new moveit::planning_interface::MoveGroup("left_arm");
group->allowReplanning(true);
group->setPlanningTime(195.0);
ros::WallDuration(1.0).sleep();
ros::Subscriber sub = nh.subscribe<baxter_controller_communication::ObjectPosition>("/roscv/left_hand_camera/objectPose", 1000, boost::bind(&objectMoveCallback, _1, collisionObject_pub, group));
// wait a moment
ros::WallDuration(1.0).sleep();
// sends robot arm to home position for object identification
ROS_DEBUG("Going to home position!");
group->setNamedTarget("home_left");
group->move();
ROS_DEBUG("/Going to home position!");
// waits for a period of time to be sure everything has started, sets robot as in home position
ros::WallDuration(2.0).sleep();
IN_POSITION = true;
// announces initialization is complete, wait wuns program while waits for shutdown
ROS_INFO("Initialization complete!");
ros::waitForShutdown();
// returns success
return 0;
}
The messages that get printed are:
[ INFO] [1374675664.614413482]: Ready to take MoveGroup commands for group left_arm.
[ INFO] [1374675664.614536410]: Replanning: yes
[DEBUG] [1374675670.619164547]: Going to home position!
[DEBUG] [1374675675.264773581]: /Going to home position!
[ INFO] [1374675677.264948128]: Initialization complete!
[ INFO] [1374675677.462830472]: Position: x: 0.791429
y: 0.409189
z: -0.180000
[ INFO] [1374675677.462903609]: Size: w: 0.106153
l: 0.132385
[DEBUG] [1374675679.463419504]: Going to drop position!
So it goes to home position and returns from the movement call, but when sent to drop the program stops forever. I think the problem is that, when the command is inside a callback function, it is not returning, but I don't know why.
Thank you for all the help,
Tiago Pimentel
On Friday, July 19, 2013 4:22:14 PM UTC-5, Tiago Pimentel wrote: