Skip to content

Commit f7f669f

Browse files
Merge v0.5.0 (#138)
1 parent 1588c15 commit f7f669f

File tree

712 files changed

+15540
-12781
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

712 files changed

+15540
-12781
lines changed

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
# ROS-TCP-Connector
22

3-
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
3+
[![Version](https://img.shields.io/github/v/tag/Unity-Technologies/ROS-TCP-Connector)](https://github.com/Unity-Technologies/ROS-TCP-Connector/releases)
4+
[![License](https://img.shields.io/badge/license-Apache--2.0-green.svg)](LICENSE.md)
5+
![ROS](https://img.shields.io/badge/ros-melodic-brightgreen)
6+
![ROS](https://img.shields.io/badge/ros-noetic-brightgreen)
7+
![ROS](https://img.shields.io/badge/ros2-foxy-brightgreen)
8+
![Unity](https://img.shields.io/badge/unity-2020.2+-brightgreen)
49

510
## Installation
611
1. Using Unity 2020.2 or later, open the package manager from `Window` -> `Package Manager` and select "Add package from git URL..."
712
![image](https://user-images.githubusercontent.com/29758400/110989310-8ea36180-8326-11eb-8318-f67ee200a23d.png)
8-
2. Enter the following URL. If you don't want to use the latest version, substitute your desired version tag where we've put `v0.4.0` in this example:
9-
`https://github.com/Unity-Technologies/ROS-TCP-Connector.git?path=/com.unity.robotics.ros-tcp-connector#v0.4.0`
13+
2. Enter the following URL. If you don't want to use the latest version, substitute your desired version tag where we've put `v0.5.0` in this example:
14+
`https://github.com/Unity-Technologies/ROS-TCP-Connector.git?path=/com.unity.robotics.ros-tcp-connector#v0.5.0`
1015
3. Click `Add`.
1116

1217

Third Party Notices.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
1-
Component name: siemens/ros-sharp<br/>
2-
Copyright 2017-2020 Siemens AG<br/>
3-
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at<br/>
1+
Component name: ROS# (siemens/ros-sharp)
42

5-
http://www.apache.org/licenses/LICENSE-2.0<br/>
3+
License Type: Apache 2.0
64

7-
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
5+
Copyright 2017-2020 Siemens AG
6+
7+
```
8+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
9+
this file except in compliance with the License. You may obtain a copy of the
10+
License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0
13+
14+
Unless required by applicable law or agreed to in writing, software distributed
15+
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
16+
CONDITIONS OF ANY KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations under the License.
18+
```

com.unity.robotics.ros-tcp-connector/CHANGELOG.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,30 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
2020

2121
### Fixed
2222

23+
## [0.5.0-preview] - 2021-07-15
24+
25+
### Upgrade Notes
26+
27+
Update third party notices also
28+
29+
### Known Issues
30+
31+
### Added
32+
33+
Add the option to connect to ROS2. User can use a dropdown menu and choose ROS1 or ROS2 protocols to connect to the ROS side
34+
35+
Add badges to main README
36+
37+
### Changed
38+
39+
### Deprecated
40+
41+
### Removed
42+
43+
### Fixed
44+
45+
Fixed byte conversion method in the serialization process
46+
2347
## [0.4.0-preview] - 2021-05-27
2448

2549
Note: the logs only reflect the changes from 0.3.0-preview

com.unity.robotics.ros-tcp-connector/Runtime/MessageGeneration/ActionAutoGen.cs renamed to com.unity.robotics.ros-tcp-connector/Editor/MessageGeneration/ActionAutoGen.cs

Lines changed: 43 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static string[] GetActionClassPaths(string inFilePath, string outPath)
2727
string rosPackageName = MessageAutoGen.GetRosPackageName(inFilePath);
2828
string outFolder = MessageAutoGen.GetMessageOutFolder(outPath, rosPackageName);
2929
string extension = Path.GetExtension(inFilePath);
30-
string className = MsgAutoGenUtilities.MessageClassPrefix + MsgAutoGenUtilities.CapitalizeFirstLetter(Path.GetFileNameWithoutExtension(inFilePath));
30+
string className = MsgAutoGenUtilities.CapitalizeFirstLetter(Path.GetFileNameWithoutExtension(inFilePath)) + MsgAutoGenUtilities.ActionClassSuffix;
3131

3232
string[] result = new string[types.Length];
3333
for (int Idx = 0; Idx < types.Length; ++Idx)
@@ -73,10 +73,10 @@ public static List<string> GenerateSingleAction(string inPath, string outPath, s
7373
List<MessageToken> tokens = listsOfTokens[i];
7474

7575
// Action is made up of goal, result, feedback
76-
string className = MsgAutoGenUtilities.MessageClassPrefix + inFileName + types[i];
76+
string className = inFileName + types[i] + MsgAutoGenUtilities.ActionClassSuffix;
7777

7878
// Parse and generate goal, result, feedback messages
79-
MessageParser parser = new MessageParser(tokens, outPath, rosPackageName, "action", MsgAutoGenUtilities.builtInTypesMapping, MsgAutoGenUtilities.builtInTypesDefaultInitialValues, MsgAutoGenUtilities.numericTypeDeserializationFunctions, MsgAutoGenUtilities.numericTypeByteSize, className);
79+
MessageParser parser = new MessageParser(tokens, outPath, rosPackageName, "action", MsgAutoGenUtilities.builtInTypesMapping, MsgAutoGenUtilities.builtInTypesDefaultInitialValues, className);
8080
parser.Parse();
8181
warnings.AddRange(parser.GetWarnings());
8282

@@ -152,6 +152,7 @@ public class ActionWrapper
152152

153153
private const string ONE_TAB = " ";
154154
private const string TWO_TABS = " ";
155+
private const string THREE_TABS = " ";
155156

156157
private readonly string inPath;
157158
private readonly string inFileName;
@@ -199,12 +200,12 @@ private string GenerateParameterizedConstructor(string className, string msgType
199200

200201
if (msgType.Equals("Goal"))
201202
{
202-
paramsIn += "MHeader header, MGoalID goal_id, ";
203+
paramsIn += "HeaderMsg header, GoalIDMsg goal_id, ";
203204
paramsOut += "header, goal_id";
204205
}
205206
else if (msgType.Equals("Result") || msgType.Equals("Feedback"))
206207
{
207-
paramsIn += "MHeader header, MGoalStatus status, ";
208+
paramsIn += "HeaderMsg header, GoalStatusMsg status, ";
208209
paramsOut += "header, status";
209210
}
210211

@@ -228,47 +229,39 @@ private string GenerateParameterizedConstructor(string className, string msgType
228229
return constructor;
229230
}
230231

231-
private string GenerateSerializationStatements(string msgType)
232+
private string GenerateDeserializerConstructor(string className, bool callBase = true)
232233
{
233-
string function = "";
234-
function += MsgAutoGenUtilities.TWO_TABS + "public override List<byte[]> SerializationStatements()\n";
235-
function += MsgAutoGenUtilities.TWO_TABS + "{\n";
236-
function += MsgAutoGenUtilities.TWO_TABS + MsgAutoGenUtilities.ONE_TAB + "var listOfSerializations = new List<byte[]>();\n";
237-
238-
string[] inheritedParams = new string[0];
239-
240-
// Inherited params
241-
if (msgType.Equals("Goal"))
242-
{
243-
inheritedParams = new[] { "header", "goal_id" };
244-
245-
}
246-
else if (msgType.Equals("Result") || msgType.Equals("Feedback"))
247-
{
248-
inheritedParams = new[] { "header", "status" };
249-
}
250-
251-
foreach (string paramName in inheritedParams)
252-
{
253-
function += TWO_TABS + ONE_TAB + "listOfSerializations.AddRange(this." + paramName + ".SerializationStatements());\n";
254-
}
234+
string constructor = "";
235+
string assignments = "";
255236

256237
foreach (string identifier in symbolTable.Keys)
257238
{
258-
function += TWO_TABS + ONE_TAB + "listOfSerializations.AddRange(this." + identifier + ".SerializationStatements());\n";
239+
string type = symbolTable[identifier];
240+
241+
if (MsgAutoGenUtilities.nonMessageTypes.Contains(type))
242+
{
243+
assignments += THREE_TABS + $"deserializer.Read(out this.{identifier});\n";
244+
}
245+
else
246+
{
247+
assignments += THREE_TABS + $"this.{identifier} = {type}.Deserialize(deserializer);\n";
248+
}
259249
}
260250

261-
function += "\n" + MsgAutoGenUtilities.TWO_TABS + MsgAutoGenUtilities.ONE_TAB + "return listOfSerializations;\n";
262-
function += MsgAutoGenUtilities.TWO_TABS + "}\n\n";
251+
constructor += TWO_TABS + $"public static {className} Deserialize(MessageDeserializer deserializer) => new {className}(deserializer);\n\n";
252+
constructor += TWO_TABS + $"{className}(MessageDeserializer deserializer){(callBase ? " : base(deserializer)" : "")}\n";
253+
constructor += TWO_TABS + "{\n";
254+
constructor += assignments;
255+
constructor += TWO_TABS + "}\n";
263256

264-
return function;
257+
return constructor;
265258
}
266259

267-
private string GenerateDeserializationStatements(string msgType)
260+
private string GenerateSerializationStatements(string msgType)
268261
{
269262
string function = "";
270-
function += MsgAutoGenUtilities.TWO_TABS + "public override int Deserialize(byte[] data, int offset)\n";
271-
function += MsgAutoGenUtilities.TWO_TABS + "{\n";
263+
function += TWO_TABS + "public override void SerializeTo(MessageSerializer serializer)\n";
264+
function += TWO_TABS + "{\n";
272265

273266
string[] inheritedParams = new string[0];
274267

@@ -285,24 +278,23 @@ private string GenerateDeserializationStatements(string msgType)
285278

286279
foreach (string paramName in inheritedParams)
287280
{
288-
function += TWO_TABS + ONE_TAB + "offset = this." + paramName + ".Deserialize(data, offset);\n";
281+
function += THREE_TABS + "serializer.Write(this." + paramName + ");\n";
289282
}
290283

291284
foreach (string identifier in symbolTable.Keys)
292285
{
293-
function += TWO_TABS + ONE_TAB + "offset = this." + identifier + ".Deserialize(data, offset);\n";
286+
function += THREE_TABS + "serializer.Write(this." + identifier + ");\n";
294287
}
295288

296-
function += "\n" + MsgAutoGenUtilities.TWO_TABS + MsgAutoGenUtilities.ONE_TAB + "return offset;\n";
297-
function += MsgAutoGenUtilities.TWO_TABS + "}\n\n";
289+
function += TWO_TABS + "}\n\n";
298290

299291
return function;
300292
}
301293

302294
public void WrapActionSections(string type)
303295
{
304-
string wrapperName = MsgAutoGenUtilities.MessageClassPrefix + inFileName + "Action" + type;
305-
string msgName = MsgAutoGenUtilities.MessageClassPrefix + inFileName + type;
296+
string wrapperName = inFileName + "Action" + type + MsgAutoGenUtilities.ActionClassSuffix;
297+
string msgName = inFileName + type + MsgAutoGenUtilities.ActionClassSuffix;
306298

307299
string outPath = Path.Combine(this.outPath, wrapperName + ".cs");
308300

@@ -333,7 +325,8 @@ public void WrapActionSections(string type)
333325

334326
// Write ROS package name
335327
writer.Write(
336-
TWO_TABS + "public const string RosMessageName = \"" + rosPackageName + "/" + inFileName + "Action" + type + "\";\n"
328+
TWO_TABS + "public const string k_RosMessageName = \"" + rosPackageName + "/" + inFileName + "Action" + type + "\";\n" +
329+
TWO_TABS + "public override string RosMessageName => k_RosMessageName;\n\n"
337330
);
338331

339332
// Record goal/result/feedback declaration
@@ -347,8 +340,9 @@ public void WrapActionSections(string type)
347340
// Write parameterized constructor
348341
writer.Write(GenerateParameterizedConstructor(wrapperName, type));
349342

343+
writer.Write(GenerateDeserializerConstructor(wrapperName));
344+
350345
writer.Write(GenerateSerializationStatements(type));
351-
writer.Write(GenerateDeserializationStatements(type));
352346

353347
// Close class
354348
writer.Write(ONE_TAB + "}\n");
@@ -359,7 +353,7 @@ public void WrapActionSections(string type)
359353

360354
public void WrapAction()
361355
{
362-
string msgNamePrefix = MsgAutoGenUtilities.MessageClassPrefix + inFileName;
356+
string msgNamePrefix = inFileName + MsgAutoGenUtilities.ActionClassSuffix;
363357
string className = msgNamePrefix + "Action";
364358
string type = "wrapper";
365359

@@ -399,7 +393,8 @@ public void WrapAction()
399393

400394
// Write ROS package name
401395
writer.Write(
402-
TWO_TABS + "public const string RosMessageName = \"" + rosPackageName + "/" + inFileName + "Action" + "\";\n"
396+
TWO_TABS + "public const string k_RosMessageName = \"" + rosPackageName + "/" + inFileName + "Action" + "\";\n" +
397+
TWO_TABS + "public override string RosMessageName => k_RosMessageName;\n\n"
403398
);
404399

405400
// Record variables
@@ -411,10 +406,11 @@ public void WrapAction()
411406
symbolTable.Add("action_feedback", className + "Feedback");
412407

413408
// Write default value constructor
414-
writer.Write("\n" + GenerateDefaultValueConstructor(className) + "\n");
409+
writer.Write("\n");
410+
writer.Write(GenerateDefaultValueConstructor(className) + "\n");
411+
writer.Write(GenerateDeserializerConstructor(className, false) + "\n");
415412

416413
writer.Write(GenerateSerializationStatements(type));
417-
writer.Write(GenerateDeserializationStatements(type));
418414

419415
// Close class
420416
writer.Write(ONE_TAB + "}\n");

com.unity.robotics.ros-tcp-connector/Runtime/MessageGeneration/MessageAutoGen.cs renamed to com.unity.robotics.ros-tcp-connector/Editor/MessageGeneration/MessageAutoGen.cs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public static string GetMessageClassPath(string inFilePath, string outPath)
7171
string rosPackageName = MessageAutoGen.GetRosPackageName(inFilePath);
7272
string outFolder = MessageAutoGen.GetMessageOutFolder(outPath, rosPackageName);
7373
string extension = Path.GetExtension(inFilePath);
74-
string className = MsgAutoGenUtilities.MessageClassPrefix + MsgAutoGenUtilities.CapitalizeFirstLetter(Path.GetFileNameWithoutExtension(inFilePath));
74+
string className = MsgAutoGenUtilities.CapitalizeFirstLetter(Path.GetFileNameWithoutExtension(inFilePath)) + MsgAutoGenUtilities.MessageClassSuffix;
7575
return Path.Combine(outFolder, "msg", className + ".cs");
7676
}
7777

@@ -84,7 +84,16 @@ public static List<string> GenerateSingleMessage(string inPath, string outPath,
8484

8585
string inFileName = Path.GetFileNameWithoutExtension(inPath);
8686

87-
if (!(rosPackageName.Equals("std_msgs") && (inFileName.Equals("Time") || inFileName.Equals("Duration"))))
87+
if (MsgAutoGenUtilities.HasHandwrittenMessage(rosPackageName, inFileName))
88+
{
89+
// don't generate! we have a handwritten message for this one
90+
if (verbose)
91+
{
92+
Console.WriteLine(inFileName + " will not be generated");
93+
}
94+
return new List<string>();
95+
}
96+
else
8897
{
8998
if (verbose)
9099
{
@@ -100,18 +109,10 @@ public static List<string> GenerateSingleMessage(string inPath, string outPath,
100109
throw new MessageParserException("Unexpected number of sections. Simple message should have 1 section.");
101110
}
102111

103-
MessageParser parser = new MessageParser(listOfTokens[0], outPath, rosPackageName, "msg", MsgAutoGenUtilities.builtInTypesMapping, MsgAutoGenUtilities.builtInTypesDefaultInitialValues, MsgAutoGenUtilities.numericTypeDeserializationFunctions, MsgAutoGenUtilities.numericTypeByteSize);
112+
MessageParser parser = new MessageParser(listOfTokens[0], outPath, rosPackageName, "msg", MsgAutoGenUtilities.builtInTypesMapping, MsgAutoGenUtilities.builtInTypesDefaultInitialValues);
104113
parser.Parse();
105114
return parser.GetWarnings();
106115
}
107-
else
108-
{
109-
if (verbose)
110-
{
111-
Console.WriteLine(inFileName + " will not be generated");
112-
}
113-
return new List<string>();
114-
}
115116
}
116117

117118
public static List<string> GeneratePackageMessages(string inPath, string outPath, string rosPackageName = "", bool verbose = false)

0 commit comments

Comments
 (0)