ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Hello chao,

I'm not 100% sure but my guess is that you get so many scan messages that you cannot publish anything (your node processes the callback function all the time).

To verify that you should use the command:

rostopic echo /cmd_vel

in your console. If you don't see any messages published to that topic, then it is obvious that you cannot publish. rostopic

Try doing this:

//#include ...    
ros::Publisher cmd_vel;
int z = 0;
void scanCallback(const sensor_msgs::LaserScan::ConstPtr& scan_msg)
{ 
    //cout << z; z++;
    /** this is to verify whether i am able to obtain the data i need*/
    ROS_INFO("I see: %u", scan_msg->header.seq);
    ROS_INFO("I see: %f", scan_msg->angle_min);
    ROS_INFO("I see: %f", scan_msg->time_increment);
    for (int y=150; y<=155; y++)
    {
    ROS_INFO("I see: %f", scan_msg->ranges[y]); 
    }

    for (int y=150; y<=1406; y++)
    {
        geometry_msgs::Twist move_cmd;
        move_cmd.angular.z = 0.2;
        move_cmd.linear.x = 0.5;
        cmd_vel.publish(move_cmd);
    }

}

int main(int argc, char **argv)
{
    ros::init(argc, argv, "wall_listener");
    ros::NodeHandle n;

    ros::Subscriber sub = n.subscribe("/base_scan", 1000, scanCallback);

    cmd_vel = n.advertise<geometry_msgs::Twist>("/base_controller/command", 1000);

    ros::spin();

    return 0;
}

This is not the best programming practice. Your code needs to be organized a lot however, it makes more sense to me and hopefully, you can understand the logic more easily this way. Now it says in your callback function that if you get a message from your laser, then publish cmd_vel commands.

Hello chao,

I'm not 100% sure but my guess is that you get so many scan messages that you cannot publish anything (your node processes the callback function all the time).

To verify that you should use the command:

rostopic echo /cmd_vel

in your console. If you don't see any messages published to that topic, then it is obvious that you cannot publish. rostopic

Try doing this:

//#include ...    
ros::Publisher cmd_vel;
int z = 0;
void scanCallback(const sensor_msgs::LaserScan::ConstPtr& scan_msg)
{ 
    //cout << z; z++;
    /** this is to verify whether i am able to obtain the data i need*/
    ROS_INFO("I see: %u", scan_msg->header.seq);
    ROS_INFO("I see: %f", scan_msg->angle_min);
    ROS_INFO("I see: %f", scan_msg->time_increment);
    for (int y=150; y<=155; y++)
    {
    ROS_INFO("I see: %f", scan_msg->ranges[y]); 
    }

    for (int y=150; y<=1406; y++)
    {
        geometry_msgs::Twist move_cmd;
        move_cmd.angular.z = 0.2;
        move_cmd.linear.x = 0.5;
        cmd_vel.publish(move_cmd);
    }

}

int main(int argc, char **argv)
{
    ros::init(argc, argv, "wall_listener");
    ros::NodeHandle n;

    ros::Subscriber sub = n.subscribe("/base_scan", n.subscribe("/scan", 1000, scanCallback);

    cmd_vel = n.advertise<geometry_msgs::Twist>("/base_controller/command", n.advertise<geometry_msgs::Twist>("/cmd_vel", 1000);

    ros::spin();

    return 0;
}

This is not the best programming practice. Your code needs to be organized a lot however, it makes more sense to me and hopefully, you can understand the logic more easily this way. Now it says in your callback function that if you get a message from your laser, then publish cmd_vel commands.

Hello chao,

I'm not 100% sure but my guess is that you get so many scan messages that you cannot publish anything (your node processes the callback function all the time).

To verify that you should use the command:

rostopic echo /cmd_vel

in your console. If you don't see any messages published to that topic, then it is obvious that you cannot publish. rostopic

Try doing this:

//#include ...    
ros::Publisher cmd_vel;
int z = 0;
void scanCallback(const sensor_msgs::LaserScan::ConstPtr& scan_msg)
{ 
    //cout << z; z++;
    /** this is to verify whether i am able to obtain the data i need*/
    ROS_INFO("I see: %u", scan_msg->header.seq);
    ROS_INFO("I see: %f", scan_msg->angle_min);
    ROS_INFO("I see: %f", scan_msg->time_increment);
    for (int y=150; y<=155; y++)
    {
    ROS_INFO("I see: %f", scan_msg->ranges[y]); 
    }

    for (int y=150; y<=1406; y++)
    {
        geometry_msgs::Twist move_cmd;
        move_cmd.angular.z = 0.2;
        move_cmd.linear.x = 0.5;
        cmd_vel.publish(move_cmd);
    }

}

int main(int argc, char **argv)
{
    ros::init(argc, argv, "wall_listener");
    ros::NodeHandle n;

    ros::Subscriber sub = n.subscribe("/scan", 1000, scanCallback);

    cmd_vel = n.advertise<geometry_msgs::Twist>("/cmd_vel", 1000);

    ros::spin();

    return 0;
}

This is not the best programming practice. Your code needs to be organized a lot however, lot, however; it makes more sense to me this way and hopefully, you can understand the logic more easily this way. easily. Now it says in your callback function that if you get a message from your laser, laser,if you see anything, then publish cmd_vel commands.