Ask Your Question
0

need help on rosserial windows using windows forms

asked 2017-05-02 22:57:02 -0500

lukevan gravatar image

updated 2017-05-03 03:23:37 -0500

Hi, rosserial windows works on visual studio win32 console mode but does not work on windows forms mode. Here is what I have done:

I am porting win32 Console rosserial_hello_world from http://wiki.ros.org/rosserial_windows... to windows forms in visual studio. It built successfully but when I run the app but the ROS master on Ubuntu did not receive any data. It works on Win32 console mode. Please help. Thanks.

The code for windows forms:

#pragma once

#include <string> #include <stdio.h> #include "ros.h" #include <geometry_msgs twist.h=""> #include <windows.h>

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

namespace rosserial_hello_world_forms {

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;

/// <summary>
/// Summary for Form1
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
    Form1(void)
    {
        InitializeComponent();
        //
        //TODO: Add the constructor code here
        //
    }

protected:
    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    ~Form1()
    {
        if (components)
        {
            delete components;
        }
    }
private: System::Windows::Forms::Timer^  timer1;
private: System::Windows::Forms::Button^  button1;
private: System::Windows::Forms::ListBox^  listBox1;
private: System::Windows::Forms::TextBox^  textBox1;
protected: 
private: System::ComponentModel::IContainer^  components;

private:
    /// <summary>
    /// Required designer variable.
    /// </summary>

#pragma region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> void InitializeComponent(void) { this->components = (gcnew System::ComponentModel::Container()); this->timer1 = (gcnew System::Windows::Forms::Timer(this->components)); this->button1 = (gcnew System::Windows::Forms::Button()); this->listBox1 = (gcnew System::Windows::Forms::ListBox()); this->textBox1 = (gcnew System::Windows::Forms::TextBox()); this->SuspendLayout(); // // timer1 // this->timer1->Interval = 1000; this->timer1->Tick += gcnew System::EventHandler(this, &Form1::timer1_Tick); // // button1 // this->button1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 10, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, static_cast<system::byte>(0))); this->button1->Location = System::Drawing::Point(135, 22); this->button1->Name = L"button1"; this->button1->Size = System::Drawing::Size(163, 52); this->button1->TabIndex = 0; this->button1->Text = L"button1"; this->button1->UseVisualStyleBackColor = true; this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click); // // listBox1 // this->listBox1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 10, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, static_cast<system::byte>(0))); this->listBox1->FormattingEnabled = true; this->listBox1->ItemHeight = 25; this->listBox1->Location = System::Drawing::Point(22, 111); this->listBox1->Name = L"listBox1"; this->listBox1->Size = System::Drawing::Size(383, 79); this->listBox1->TabIndex = 1; // // textBox1 // this->textBox1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 10, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, static_cast<system::byte>(0))); this->textBox1->Location = System::Drawing::Point(474, 37); this->textBox1->Name = L"textBox1"; this->textBox1->Size = System::Drawing::Size(336, 30); this->textBox1->TabIndex = 2; // // Form1 // this->AutoScaleDimensions = System::Drawing::SizeF(9, 20); this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; this->ClientSize = System::Drawing::Size(431, 244); this->Controls->Add(this->textBox1); this->Controls->Add ... (more)

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-05-03 04:36:42 -0500

lukevan gravatar image

FYI, I have already solved the problem. I need to call at least nh.SpinOnce() one time in the initialization thread before enable the timer.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2017-05-02 22:57:02 -0500

Seen: 99 times

Last updated: May 03 '17