Skip to content

Commit

Permalink
Merge v0.5.0 (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
peifeng-unity authored Jul 16, 2021
1 parent 1588c15 commit f7f669f
Show file tree
Hide file tree
Showing 712 changed files with 15,540 additions and 12,781 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
# ROS-TCP-Connector

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

## Installation
1. Using Unity 2020.2 or later, open the package manager from `Window` -> `Package Manager` and select "Add package from git URL..."
![image](https://user-images.githubusercontent.com/29758400/110989310-8ea36180-8326-11eb-8318-f67ee200a23d.png)
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:
`https://github.com/Unity-Technologies/ROS-TCP-Connector.git?path=/com.unity.robotics.ros-tcp-connector#v0.4.0`
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:
`https://github.com/Unity-Technologies/ROS-TCP-Connector.git?path=/com.unity.robotics.ros-tcp-connector#v0.5.0`
3. Click `Add`.


Expand Down
21 changes: 16 additions & 5 deletions Third Party Notices.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
Component name: siemens/ros-sharp<br/>
Copyright 2017-2020 Siemens AG<br/>
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/>
Component name: ROS# (siemens/ros-sharp)

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

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.
Copyright 2017-2020 Siemens AG

```
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
http://www.apache.org/licenses/LICENSE-2.0
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.
```
24 changes: 24 additions & 0 deletions com.unity.robotics.ros-tcp-connector/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,30 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a

### Fixed

## [0.5.0-preview] - 2021-07-15

### Upgrade Notes

Update third party notices also

### Known Issues

### Added

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

Add badges to main README

### Changed

### Deprecated

### Removed

### Fixed

Fixed byte conversion method in the serialization process

## [0.4.0-preview] - 2021-05-27

Note: the logs only reflect the changes from 0.3.0-preview
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static string[] GetActionClassPaths(string inFilePath, string outPath)
string rosPackageName = MessageAutoGen.GetRosPackageName(inFilePath);
string outFolder = MessageAutoGen.GetMessageOutFolder(outPath, rosPackageName);
string extension = Path.GetExtension(inFilePath);
string className = MsgAutoGenUtilities.MessageClassPrefix + MsgAutoGenUtilities.CapitalizeFirstLetter(Path.GetFileNameWithoutExtension(inFilePath));
string className = MsgAutoGenUtilities.CapitalizeFirstLetter(Path.GetFileNameWithoutExtension(inFilePath)) + MsgAutoGenUtilities.ActionClassSuffix;

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

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

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

Expand Down Expand Up @@ -152,6 +152,7 @@ public class ActionWrapper

private const string ONE_TAB = " ";
private const string TWO_TABS = " ";
private const string THREE_TABS = " ";

private readonly string inPath;
private readonly string inFileName;
Expand Down Expand Up @@ -199,12 +200,12 @@ private string GenerateParameterizedConstructor(string className, string msgType

if (msgType.Equals("Goal"))
{
paramsIn += "MHeader header, MGoalID goal_id, ";
paramsIn += "HeaderMsg header, GoalIDMsg goal_id, ";
paramsOut += "header, goal_id";
}
else if (msgType.Equals("Result") || msgType.Equals("Feedback"))
{
paramsIn += "MHeader header, MGoalStatus status, ";
paramsIn += "HeaderMsg header, GoalStatusMsg status, ";
paramsOut += "header, status";
}

Expand All @@ -228,47 +229,39 @@ private string GenerateParameterizedConstructor(string className, string msgType
return constructor;
}

private string GenerateSerializationStatements(string msgType)
private string GenerateDeserializerConstructor(string className, bool callBase = true)
{
string function = "";
function += MsgAutoGenUtilities.TWO_TABS + "public override List<byte[]> SerializationStatements()\n";
function += MsgAutoGenUtilities.TWO_TABS + "{\n";
function += MsgAutoGenUtilities.TWO_TABS + MsgAutoGenUtilities.ONE_TAB + "var listOfSerializations = new List<byte[]>();\n";

string[] inheritedParams = new string[0];

// Inherited params
if (msgType.Equals("Goal"))
{
inheritedParams = new[] { "header", "goal_id" };

}
else if (msgType.Equals("Result") || msgType.Equals("Feedback"))
{
inheritedParams = new[] { "header", "status" };
}

foreach (string paramName in inheritedParams)
{
function += TWO_TABS + ONE_TAB + "listOfSerializations.AddRange(this." + paramName + ".SerializationStatements());\n";
}
string constructor = "";
string assignments = "";

foreach (string identifier in symbolTable.Keys)
{
function += TWO_TABS + ONE_TAB + "listOfSerializations.AddRange(this." + identifier + ".SerializationStatements());\n";
string type = symbolTable[identifier];

if (MsgAutoGenUtilities.nonMessageTypes.Contains(type))
{
assignments += THREE_TABS + $"deserializer.Read(out this.{identifier});\n";
}
else
{
assignments += THREE_TABS + $"this.{identifier} = {type}.Deserialize(deserializer);\n";
}
}

function += "\n" + MsgAutoGenUtilities.TWO_TABS + MsgAutoGenUtilities.ONE_TAB + "return listOfSerializations;\n";
function += MsgAutoGenUtilities.TWO_TABS + "}\n\n";
constructor += TWO_TABS + $"public static {className} Deserialize(MessageDeserializer deserializer) => new {className}(deserializer);\n\n";
constructor += TWO_TABS + $"{className}(MessageDeserializer deserializer){(callBase ? " : base(deserializer)" : "")}\n";
constructor += TWO_TABS + "{\n";
constructor += assignments;
constructor += TWO_TABS + "}\n";

return function;
return constructor;
}

private string GenerateDeserializationStatements(string msgType)
private string GenerateSerializationStatements(string msgType)
{
string function = "";
function += MsgAutoGenUtilities.TWO_TABS + "public override int Deserialize(byte[] data, int offset)\n";
function += MsgAutoGenUtilities.TWO_TABS + "{\n";
function += TWO_TABS + "public override void SerializeTo(MessageSerializer serializer)\n";
function += TWO_TABS + "{\n";

string[] inheritedParams = new string[0];

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

foreach (string paramName in inheritedParams)
{
function += TWO_TABS + ONE_TAB + "offset = this." + paramName + ".Deserialize(data, offset);\n";
function += THREE_TABS + "serializer.Write(this." + paramName + ");\n";
}

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

function += "\n" + MsgAutoGenUtilities.TWO_TABS + MsgAutoGenUtilities.ONE_TAB + "return offset;\n";
function += MsgAutoGenUtilities.TWO_TABS + "}\n\n";
function += TWO_TABS + "}\n\n";

return function;
}

public void WrapActionSections(string type)
{
string wrapperName = MsgAutoGenUtilities.MessageClassPrefix + inFileName + "Action" + type;
string msgName = MsgAutoGenUtilities.MessageClassPrefix + inFileName + type;
string wrapperName = inFileName + "Action" + type + MsgAutoGenUtilities.ActionClassSuffix;
string msgName = inFileName + type + MsgAutoGenUtilities.ActionClassSuffix;

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

Expand Down Expand Up @@ -333,7 +325,8 @@ public void WrapActionSections(string type)

// Write ROS package name
writer.Write(
TWO_TABS + "public const string RosMessageName = \"" + rosPackageName + "/" + inFileName + "Action" + type + "\";\n"
TWO_TABS + "public const string k_RosMessageName = \"" + rosPackageName + "/" + inFileName + "Action" + type + "\";\n" +
TWO_TABS + "public override string RosMessageName => k_RosMessageName;\n\n"
);

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

writer.Write(GenerateDeserializerConstructor(wrapperName));

writer.Write(GenerateSerializationStatements(type));
writer.Write(GenerateDeserializationStatements(type));

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

public void WrapAction()
{
string msgNamePrefix = MsgAutoGenUtilities.MessageClassPrefix + inFileName;
string msgNamePrefix = inFileName + MsgAutoGenUtilities.ActionClassSuffix;
string className = msgNamePrefix + "Action";
string type = "wrapper";

Expand Down Expand Up @@ -399,7 +393,8 @@ public void WrapAction()

// Write ROS package name
writer.Write(
TWO_TABS + "public const string RosMessageName = \"" + rosPackageName + "/" + inFileName + "Action" + "\";\n"
TWO_TABS + "public const string k_RosMessageName = \"" + rosPackageName + "/" + inFileName + "Action" + "\";\n" +
TWO_TABS + "public override string RosMessageName => k_RosMessageName;\n\n"
);

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

// Write default value constructor
writer.Write("\n" + GenerateDefaultValueConstructor(className) + "\n");
writer.Write("\n");
writer.Write(GenerateDefaultValueConstructor(className) + "\n");
writer.Write(GenerateDeserializerConstructor(className, false) + "\n");

writer.Write(GenerateSerializationStatements(type));
writer.Write(GenerateDeserializationStatements(type));

// Close class
writer.Write(ONE_TAB + "}\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static string GetMessageClassPath(string inFilePath, string outPath)
string rosPackageName = MessageAutoGen.GetRosPackageName(inFilePath);
string outFolder = MessageAutoGen.GetMessageOutFolder(outPath, rosPackageName);
string extension = Path.GetExtension(inFilePath);
string className = MsgAutoGenUtilities.MessageClassPrefix + MsgAutoGenUtilities.CapitalizeFirstLetter(Path.GetFileNameWithoutExtension(inFilePath));
string className = MsgAutoGenUtilities.CapitalizeFirstLetter(Path.GetFileNameWithoutExtension(inFilePath)) + MsgAutoGenUtilities.MessageClassSuffix;
return Path.Combine(outFolder, "msg", className + ".cs");
}

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

string inFileName = Path.GetFileNameWithoutExtension(inPath);

if (!(rosPackageName.Equals("std_msgs") && (inFileName.Equals("Time") || inFileName.Equals("Duration"))))
if (MsgAutoGenUtilities.HasHandwrittenMessage(rosPackageName, inFileName))
{
// don't generate! we have a handwritten message for this one
if (verbose)
{
Console.WriteLine(inFileName + " will not be generated");
}
return new List<string>();
}
else
{
if (verbose)
{
Expand All @@ -100,18 +109,10 @@ public static List<string> GenerateSingleMessage(string inPath, string outPath,
throw new MessageParserException("Unexpected number of sections. Simple message should have 1 section.");
}

MessageParser parser = new MessageParser(listOfTokens[0], outPath, rosPackageName, "msg", MsgAutoGenUtilities.builtInTypesMapping, MsgAutoGenUtilities.builtInTypesDefaultInitialValues, MsgAutoGenUtilities.numericTypeDeserializationFunctions, MsgAutoGenUtilities.numericTypeByteSize);
MessageParser parser = new MessageParser(listOfTokens[0], outPath, rosPackageName, "msg", MsgAutoGenUtilities.builtInTypesMapping, MsgAutoGenUtilities.builtInTypesDefaultInitialValues);
parser.Parse();
return parser.GetWarnings();
}
else
{
if (verbose)
{
Console.WriteLine(inFileName + " will not be generated");
}
return new List<string>();
}
}

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

0 comments on commit f7f669f

Please sign in to comment.