-
Notifications
You must be signed in to change notification settings - Fork 370
Dev_NewMessageTypes
Martin Bischoff edited this page Mar 23, 2018
·
13 revisions
1. Edit Message.cs
public class StandardFloat32 : Message
{
public float data;
public StandardFloat32()
{
data = 0;
}
}
2. Edit MessageTypes.cs
public static readonly Dictionary<string, Type> Dictionary = new Dictionary<string, Type>
{
...
{ "std_msgs/Float32", typeof(StandardFloat32) },
...
}
3. Build RosBridgeClient.sln in Visual Studio
- Open RosBridgeClient.sln in Visual Studio
- In Build > Configuration Manager select:
- Active Solution Configuration: Release
- Active Solution Platform: Any CPU
- Click Build > Build Solution
4. Update RosBridgeClient.dll in your Unity Project
Copy RosBridgeClient.dll
- from
..\RosBridgeClient\bin\Release\
- to
...\Unity3D\Assets\RosSharp\Plugins\
Example Publisher Script:
using UnityEngine;
using RosSharp.RosBridgeClient;
[RequireComponent(typeof(RosConnector))]
public class FloatPublisher : MonoBehaviour
{
public string Topic;
public float MessageData;
private StandardFloat32 message;
private RosSocket rosSocket;
private int publicationId;
private void Start()
{
rosSocket = GetComponent<RosConnector>().RosSocket;
publicationId = rosSocket.Advertise(Topic, "std_msgs/Float32");
message = new StandardFloat32();
}
private void Update()
{
message.data = MessageData;
rosSocket.Publish(publicationId, message);
}
}
Example Subscriber Script:
using UnityEngine;
using RosSharp.RosBridgeClient;
[RequireComponent(typeof(RosConnector))]
public class FloatSubscriber : MonoBehaviour
{
public string Topic;
public float MessageData;
private RosSocket rosSocket;
private void Start()
{
rosSocket = GetComponent<RosConnector>().RosSocket;
rosSocket.Subscribe(Topic, "std_msgs/Float32", Receive);
}
private void Receive(Message message)
{
MessageData = ((StandardFloat32)message).data;
}
}
© Siemens AG, 2017-2018 Author: Dr. Martin Bischoff (martin.bischoff@siemens.com)
-
- 1.3.1 R2D2 Setup
- 1.3.2 Gazebo Setup on VM
- 1.3.3 TurtleBot Setup (Optional for ROS2)
-
- 2.1 Quick Start
- 2.2 Transfer a URDF from ROS to Unity
- 2.3 Transfer a URDF from Unity to ROS
- 2.4 Unity Simulation Scene Example
- 2.5 Gazebo Simulation Scene Example
- 2.6 Fibonacci Action Client
- 2.7 Fibonacci Action Server
- 3.1 Import a URDF on Windows
- 3.2 Create, Modify and Export a URDF Model
- 3.3 Animate a Robot Model in Unity
- Message Handling: Readers & Writers
- Thread Safety for Message Reception
- File Server Package
- ROS-Unity Coordinate System Conversions
- Post Build Events
- Preprocessor Directives in ROS#
- Adding New Message Types
- RosBridgeClient Protocols
- RosBridgeClient Serializers
- Action Server State Machine Model
© Siemens AG, 2017-2024