Two windows apps communicate with the ROS master lost message

asked 2017-02-21 20:39:49 -0600

ChoBear35 gravatar image

I use two windows applications communicate to each other with the ROS master( rosserial_windows ).

I know i can't send any message before the initial time (rosserial_windows_common_problems).

I send messages after that time but some messages still miss in the duration.

I send 2500 messages and it will miss 10~150(different every time) .

My code are following.

Win32_Publisher main loop

int loop = 0;
while (1)
{
    if (loop < 12500) //make sure initialize
    {
        Camera_motion_msg.position.x = -9999.0; //useless data
        Camera_motion_msg.position.y = -9999.0;
        Camera_motion_msg.position.z = -9999.0;
        Camera_motion_msg.orientation.x = -9999.0;
        Camera_motion_msg.orientation.y = -9999.0;
        Camera_motion_msg.orientation.z = -9999.0;
        Camera_motion_msg.orientation.w = -9999.0;
    }
    else if (loop >= 12500 && loop < 15000)
    {
        Camera_motion_msg.position.x = loop - 12500;
        Camera_motion_msg.position.y = loop - 12500;
        Camera_motion_msg.position.z = loop - 12500;
        Camera_motion_msg.orientation.x = loop - 12500;
        Camera_motion_msg.orientation.y = loop - 12500;
        Camera_motion_msg.orientation.z = loop - 12500;
        Camera_motion_msg.orientation.w = loop - 12500;
    }
    if (loop >= 15000) break;

    loop++;

    Camera_motion_pub.publish(&Camera_motion_msg);

    nh.spinOnce();

    Sleep(10);
}

Win32_Subscriber full code

using std::string;

double Arm_joint_data[7];
int sub_loop; //global variable

void estimated_pose_callback(const geometry_msgs::Pose &Camera_motion_msg_s)
{
    if (Camera_motion_msg_s.position.x > -9998) //make sure initialize
    {
        printf("Received image data %d:",sub_loop);
        printf("%f ", Camera_motion_msg_s.position.x);
        printf("%f ", Camera_motion_msg_s.position.y);
        printf("%f ", Camera_motion_msg_s.position.z);
        printf("%f ", Camera_motion_msg_s.orientation.x);
        printf("%f ", Camera_motion_msg_s.orientation.y);
        printf("%f ", Camera_motion_msg_s.orientation.z);
        printf("%f ", Camera_motion_msg_s.orientation.w);
        Arm_joint_data[0] = Camera_motion_msg_s.position.x;
        Arm_joint_data[1] = Camera_motion_msg_s.position.y;
        Arm_joint_data[2] = Camera_motion_msg_s.position.z;
        Arm_joint_data[3] = Camera_motion_msg_s.orientation.x;
        Arm_joint_data[4] = Camera_motion_msg_s.orientation.y;
        Arm_joint_data[5] = Camera_motion_msg_s.orientation.z;
        Arm_joint_data[6] = Camera_motion_msg_s.orientation.w;
        printf("\n");
        sub_loop++;
    }
}

int _tmain(int argc, _TCHAR * argv[])
{

    ros::NodeHandle nh1;
    char *ros_master = "XX.XX.XXXX";

    printf("Connecting to server at %s\n", ros_master);
    nh1.initNode(ros_master);

    ros::Subscriber<geometry_msgs::Pose> Camera_motion_sub("Camera_motion", &estimated_pose_callback);

    nh1.subscribe(Camera_motion_sub);

    printf("Need data!\n");

    sub_loop = 0;

    while (sub_loop!=2500) //need 2500 messages
    {
        nh1.spinOnce();
        Sleep(10);
    }

    printf("All done!\n");
    system("pause");
    return 0;

}

Did I miss something and what else i can do ?

Thanks for any response.

edit retag flag offensive close merge delete