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

Revision history [back]

click to hide/show revision 1
initial version

Hi there, I solved my problem, I comment out the #include "stdafx.h" and then it works. In addition to that I add __cdecl and made same changes. Here is my code:

#include <string>    
#include <stdio.h>
#include "ros.h"
#include <geometry_msgs/Twist.h>
#include <windows.h>
extern "C"
{

    ros::NodeHandle nh;
    char *ros_master = "192.168.1.4";
    geometry_msgs::Twist twist_msg;
    ros::Publisher cmd_vel_pub("cmd_vel", &twist_msg);

    __declspec(dllexport) void __cdecl InitRosPublish() 
    {
        printf("Connecting to server at %s\n", ros_master);
        nh.initNode(ros_master);
        printf("Advertising cmd_vel message\n");
        nh.advertise(cmd_vel_pub);
    }

    __declspec(dllexport) void __cdecl PublishImuData(double roll, double pitch, double yaw)
    {
        printf("Go robot go!\n");
        twist_msg.linear.x = x;
        twist_msg.linear.y = y;
        twist_msg.linear.z = z;
        twist_msg.angular.x = 0;
        twist_msg.angular.y = 0;
        twist_msg.angular.z = -1.8;
        cmd_vel_pub.publish(&twist_msg);
        nh.spinOnce();
        Sleep(10);
        printf("All done!\n");
    }
}