How can I get status in Rviz goal_tool.cpp?

asked 2015-12-30 21:09:53 -0500

zzzZuo gravatar image

updated 2016-01-04 02:34:18 -0500

I want to modify the function GoalTool::onPoseSet(double x, double y, double theta) in Rviz to achive MultiPoints. (MultiPoints: that we can send many points one by one). In this way, we need to know the status with the robot(because we can only send second point after the first point is sent successfully).

I find some answers in answers.ros.org(the number in void GoalTool::onPoseSet be annonated),but them don't work.

Sry for my English and thanks for your time.

  1. I run spin() in boost::thread, but it also block my GUI.
  2. I run spin() in QThread, and also block.
  3. ros::MultiThreadedSpinner spinner;
  4. ros::AsyncSpinner myspinner;
  5. ros::Duration(0.1).sleep();

and so on. Above,that either block the GUI,or can't run the callback function in subscribe.

thats my code:

namespace rviz

{



void fun_cb(const actionlib_msgs::GoalStatusArrayConstPtr &msg)

{
    qDebug()<<"test call back";
//    actionlib_msgs::GoalStatus globalStatus = msg->status_list.at(0);
//    int state = globalStatus.status;
//    qDebug()<<state;
//    qDebug()<<globalStatus.text.c_str();
}

void thread_fun()
{
    qDebug()<<"thread_fun";
    ros::spin();
}

Goal_Thread *gt;

GoalTool::GoalTool()
{
    shortcut_key_ = 'g';
    topic_property_ = new StringProperty( "Topic", "goal",
                                        "The topic on which to publish navigation goals.",
                                        getPropertyContainer(), SLOT( updateTopic() ), this );

    ros::Subscriber sub = nh_.subscribe<actionlib_msgs::GoalStatusArray>("/move_base/status",100,fun_cb);
    goal_timer = new QTimer(this);
    gt = new Goal_Thread(nh_);

    //start thread
//    gt->start();

    //timer slot
    connect(goal_timer,SIGNAL(timeout()),this,SLOT(tiemr_slot()));
}

void GoalTool::onInitialize()
{
    PoseTool::onInitialize();
    setName( "目标" );
    updateTopic();
}

void GoalTool::updateTopic()
{
    qDebug()<<"updateTopic";
    pub_ = nh_.advertise<geometry_msgs::PoseStamped>( topic_property_->getStdString(), 1);
//    ros::Subscriber sub = nh_.subscribe<actionlib_msgs::GoalStatusArray>("/move_base/status",100,fun_cb);
    //    ros::spin();
}

void GoalTool::tiemr_slot()
{
    qDebug()<<"timer_slot";
    ros::spin();
}

void GoalTool::onPoseSet(double x, double y, double theta)
{
    std::string fixed_frame = context_->getFixedFrame().toStdString();
    tf::Quaternion quat;
    quat.setRPY(0.0, 0.0, theta);
    tf::Stamped<tf::Pose> p = tf::Stamped<tf::Pose>(tf::Pose(quat, tf::Point(x, y, 0.0)), ros::Time::now(), fixed_frame);
    geometry_msgs::PoseStamped goal;
    tf::poseStampedTFToMsg(p, goal);
    ROS_INFO("Setting goal: Frame:%s, Position(%.3f, %.3f, %.3f), Orientation(%.3f, %.3f, %.3f, %.3f) = Angle: %.3f\n", fixed_frame.c_str(), goal.pose.position.x, goal.pose.position.y, goal.pose.position.z, goal.pose.orientation.x, goal.pose.orientation.y, goal.pose.orientation.z, goal.pose.orientation.w, theta);

    pub_.publish(goal);

    //subscribe
//    ros::Subscriber sub = nh_.subscribe<actionlib_msgs::GoalStatusArray>("/move_base/status",1000,fun_cb);

    //0.use boost:thread to run spin
//    boost::thread spin_thread(&thread_fun);
//    spin_thread.join();

    //1.use thread to run spin()
//    gt->start();

    //2.run spin() in main-thread
//    ros::spin();

    //3.use MultiThreadedSpinner to block
//    ros::MultiThreadedSpinner spinner(2);
//    spinner.spin();

    //4.
//    ros::AsyncSpinner myspinner(4);
//    myspinner.start();
//    ros::waitForShutdown();

    //5
//    ros::Duration(0.1).sleep();
//    ros::spin();

    //6
//    ros::Rate rate_loop(10);

//    while(nh_.ok())
//    {
//        ros::spinOnce();
//        rate_loop.sleep();
//    }

    //7.use QThread to run spin()
//    QThread *test_thread = new QThread(this);
//    this->moveToThread(test_thread);
//    ros::spin();

    //8
//    goal_timer->start(100);

//9
//    nh_.getCallbackQueue()

/*

    //2015.12.22 by ZMD
    queue_goal.push(goal);
    while(!queue_goal.empty())
    {
        //neet to judge ros'state
        qDebug()<<"before pop"<<queue_goal.size();
        pub_.publish(queue_goal ...
(more)
edit retag flag offensive close merge delete