ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

Create the variable outside of the switch statement ros::Subscriber h_sub; and initialize it within the switch statements splitcmd_sub = n.subscribe("/uav1/split_cmd", 1000, getsplitcmd);

Create the variable outside of the switch statement statement

ros::Subscriber h_sub; ros::Subscriber h_sub;

and initialize it within the switch statements statements

splitcmd_sub = n.subscribe("/uav1/split_cmd", 1000, getsplitcmd); getsplitcmd);

Create the variable outside of the switch statement

ros::Subscriber h_sub;

and initialize it within the switch statements

splitcmd_sub = n.subscribe("/uav1/split_cmd", 1000, getsplitcmd);

Use one subscriber variable, and now this way you wont go out of scope.

Create the variable outside of the switch statement

ros::Subscriber h_sub;

statement and initialize it within the switch statements

splitcmd_sub = n.subscribe("/uav1/split_cmd", 1000, getsplitcmd);

statements. Use one subscriber variable, variable for you cmd_vel, and now this way you wont go out of scope.

main(int argc, char **argv) {  
ros::init(argc, argv, "mycontrol_1");

 ros::NodeHandle n;

 ros::Subscriber h_sub = n.subscribe("/uav1/sonar_height",1000,hcontrol);
 ros::Subscriber splitcmd_sub;

switch (squad_leader_no)
{

case 1:
       splitcmd_sub = n.subscribe("/uav1/split_cmd", 1000, getsplitcmd);
       break;

case 2:
       splitcmd_sub = n.subscribe("/uav2/split_cmd", 1000, getsplitcmd);
       break;

case 3:
       splitcmd_sub = n.subscribe("/uav3/split_cmd", 1000, getsplitcmd);
       break;

.....
}