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

publishing a node by using a dll in Visual Basic 2015(Windows)

asked 2017-04-05 06:09:12 -0500

ChrisBecken gravatar image

updated 2017-04-12 04:57:18 -0500

Hi there,

I have a similar problem as described here and here. I want to send same IMU data from a Visual Basic .NET Application (WIndows) to a ROSmaster (Linux).

Therefore I am using ros_lib from rosserial. The Tutorial you can find here . This tutorial works well, but my appilcation which communicates with my IMU is written in vb.net . So my idea is to write a dll which published a node. Unfortunately several syntax errors appeared then.

Here is my header:

//SendMsgToROS.h
#ifdef SENDMSGDLL_EXPORTS
#define SENDMSGDLL_API __declspec(dllexport) 
#else
#define SENDMSGDLL_API __declspec(dllimport) 
#endif

namespace SendMsg
{
    class Message
    {
    public:
        SENDMSGDLL_API int sendingMsg(int x, int y, int z);
    };
}

Here is my main.cpp

#include "stdafx.h"
#include <string>
#include <stdio.h>
#include "ros.h"
#include <geometry_msgs/Twist.h>
#include <windows.h>
#include "SendMsgToROS.h" //Header-File where namespace SendMsg and class Message are defined

using std::string;

namespace SendMsg
{
    int Message::sendingMsg(int x, int y, int z)
    {
        ros::NodeHandle nh;
        char *ros_master = "1.1.3.1.1";//ID of ROS Masters'
        printf("Connecting to server at %s\n", ros_master);
        nh.initNode(ros_master);
        printf("Advertising cmd_vel message\n");
        geometry_msgs::Twist twist_msg;
        ros::Publisher cmd_vel_pub("cmd_vel", &twist_msg);
        nh.advertise(cmd_vel_pub);

        printf("Go robot go!\n");
        while (1)
        {
          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(100);
        }

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

Do someone know that I did wrong? Most of the errors appears in the files log.h, node_handle.h . And then there is one warning Warning C4273 'SendMsg::Message::sendingMsg': inconsistent dll linkage

EDIT: I found the following interesting link

Here several errors like C2238, C2143, C2059 appeared during compiling just like at my program.

The best answer in that post was to start a empty project with just putting the include's in it. I did this and in addition to that I add ros_lib to my project as described.

The header which causes all the errors was ros.h. When I tested the tutorial Hello World, I used a WIN32 console application and eyerthing worked fine. So the problem is how to get a dll of that. What have to be done what it works ? Has someone an idea?

It seems that ros_lib is not compatible with VS2015. What do you think ?

I thank you in advance!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-05-09 06:43:23 -0500

ChrisBecken gravatar image

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");
    }
}
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-04-05 06:09:12 -0500

Seen: 339 times

Last updated: May 09 '17