How to call spin in ROS with boost MSM(meta state machine) integration?

asked 2016-07-08 10:20:24 -0500

anilmullapudi gravatar image

I am new to state machines. I have created a meta state machine in a ROS node, using boost API. However, i am not sure how to spin ROS nodes. is it possible to integrate external state machines with ROS? Where i need to call spin. Below is the sample code, but here i am not subscribed any nodes. what is best way communicating state machines with ROS subscription and publishing.

ros::init(argc, argv, "StateMachine_Node");
ros::NodeHandle n;
ros::Publisher chatter_pub = n.advertise<std_msgs::String>("chatter", 1000);

ros::Rate loop_rate(10);
while (ros::ok()) {
    std_msgs::String msg;

    std::stringstream ss;
    ss << "hello world"
    msg.data = ss.str();

    ROS_INFO("%s", msg.data.c_str());

    std::cout << "\nBuilding a state machine";
    pickupMachine p;
    // needed to start the highest-level SM. This will call on_entry and mark the start of the SM
    p.start();
    p.process_event(activate());
    p.process_event(navigate());
    p.process_event(pick("water", BOTTLE));
    p.process_event(pick("drink", COKE));
    p.process_event(navigate());
    p.process_event(place());
    p.process_event(navigate());
    p.process_event(sm::wait());
    std::cout << "stop fsm" << std::endl;
    p.stop();

    chatter_pub.publish(msg);

    ros::spinOnce();

    loop_rate.sleep();
    ++count;
}
edit retag flag offensive close merge delete