noelex / rclnet Goto Github PK
View Code? Open in Web Editor NEWModern ROS 2 client library for .NET.
License: MIT License
Modern ROS 2 client library for .NET.
License: MIT License
I ran ros2cs on my C:\dev\SmplROS2dNET2\ros2cs.spec without any package exclusions. After it processed 32 packages and 287 message definitions, VS2022 gave me 430+ errors of type "CS0227 Unsafe code may only appear if compiling with /unsafe". I took the quick action's advice to allow the project to use unsafe code, but now I still have 5 errors of "CS0234 The type or namespace name 'BasicIdl' does not exist in the namespace 'Rosidl.Messages.Rosbag2StorageMcapTestdata' (are you missing an assembly reference?)". All 5 errors are in C:\dev\SmplROS2dNET2\Rosbag2StorageMcapTestdata\Messages\ComplexMsgDependsOnIdl.cs, which I assume it generated from C:\dev\ros2_humble(\ros2-windows)\share\rosbag2_storage_mcap_testdata\msg\ComplexMsgDependsOnIdl.idl. IntelliSense confirms that Rosbag2StorageMcapTestdata in fact does not have BasicIdl as a member, even with my project including the Rcl.NET (1.3.2) package. I may be able to remove C:\dev\SmplROS2dNET2\Rosbag2StorageMcapTestdataC:\dev\SmplROS2dNET2\Rosbag2StorageMcapTestdata from my project, but this should probably be addressed nonetheless. Thanks...
I am creating an API to publish to "/goal_pose" but I don't understand why sometimes it fails to publish and nothing happens while the task is being completed correctly.
public static bool SetGoalPose(float x1, float y1, float orientation)
{
ILogger logger = LoggerHelper.Logger;
bool result = false;
try
{
//ros2node only generates rclContext
using (Ros2Node ros2Node = new Ros2Node(NODE_NAME))
{
PoseStamped poseStamped = new PoseStamped(new Header(new ROS2Messages.Builtin.Time(DateTime.UtcNow.Second, (uint)DateTime.UtcNow.Nanosecond)));
poseStamped.Pose.Position.X = x1;
poseStamped.Pose.Position.Y = y1;
poseStamped.Pose.Orientation = CalculateQuaternionRos(orientation);
poseStamped.Header.FrameId = "map";
if (ros2Node == null)
{
return false;
}
ValueTask valueTask = ros2Node.PublishAsync<PoseStamped>(poseStamped);
bool complete = valueTask.AsTask().Wait(WAIT_TIMEOUT);
if (!complete)
{
throw new Exception($"API TIME OUT: [{WAIT_TIMEOUT}]");
}
if (valueTask.IsCompletedSuccessfully)
{
logger.LogInformation("SetGoalPose => Service call finished with [IsCompletedSuccessfully]");
return true;
}
else if (valueTask.IsCompleted)
{
logger.LogInformation("SetGoalPose => Service call finished with [IsCompleted]");
result = true;
}
else if (valueTask.IsFaulted)
{
logger.LogInformation("SetGoalPose => Service call finished with [IsFaulted]");
result = false;
}
else if (valueTask.IsCanceled)
{
logger.LogInformation("SetGoalPose => Service call finished with [IsCanceled]");
result = false;
}
else
{
logger.LogInformation("SetGoalPose => Service call finished with unknow state");
result = false;
}
}
} catch (Exception e)
{
logger.LogError("SetGoalPose => Exception setting goal pose [{0}]",e.Message);
throw new Exception($"SetGoalPose[{NODE_NAME}] => See the logs. Exception [{e.Message}]", e);
}
return result;
}
//method from Ros2Node
public async ValueTask PublishAsync<T>(T aMessage)
{
try
{
_theLogger.LogInformation("PublishAsync[{0}] => Starting publisher [{1}]", _theName, _theTopicName);
await _thePublisher.PublishAsync(aMessage);
_theLogger.LogInformation("Publish[{0}] => Publisher's inner task finished", _theName);
}
catch (Exception e)
{
throw new Exception($"Publish[{_theName}] => See the logs. Exception [{e.Message}]", e);
}
finally
{
}
}
The logs always show "Service call finished with [IsCompletedSuccessfully]" but sometimes it doesn't publish anything because I'm looking with ros2 topic echo echo /goal_pose and it doesn't show what it supposedly just published.
Does anyone know what could be going on here?
Update: (https://answers.ros.org/question/65774/publisher-not-publishing-on-topic/) I am reading that when working in c++ sometimes a publisher fails because it is not yet connected to the corresponding subscriber. Is it possible that my error is similar to that? Is it possible to wait for that connection?
I'm trying to follow the instructions, but when I get to the part about running the ros2cs utility on the ros2cs.spec file in my Visual Studio project, I see in both the admin command prompt, admin PowerShell:
Searching in directory: C:\dev\ROS2cs\install
Searching in directory: C:\dev\ros2_humble
Unable to parse field defined as 'FieldDeclaration { Type = bool, Identifier = bool_values_default, Value = [false, true, false], IsArray = True, ArrayLength = 3, InlineComment = , IsUpperBounded = False }': Unexpected boolean value ' true'.
I also ran it from both kinds of command prompts available from Visual Studio 2022, which failed the same way after the "install" line. I can't find much about this online, closest is something about JavaScript. Which bit of code is this and what could be happening? Thanks...
Hi there,
First this is a great library and thanks for the hard work here.
I am able to create a new .NET 7 application and create context, node and publisher to publish async while my app is running. My issue is that I am not able to see the node listed in the command line ros2 interface using the command: ros2 node list
For the examples, the topic and data do show up as expected.
Is this intended behavior? I do not think it causes a huge issue more that it is very difficult to debug the system with large amounts of nodes running. Would love to help dig into this if needed and thanks again!
Code:
private async void SpinNode()
{
await using var ctx = new RclContext();
using var node = ctx.CreateNode("turtle_circling");
using var pub = node.CreatePublisher<Twist>("/turtle1/cmd_vel");
var twist = new Twist(
linear: new(x: 3.0f),
angular: new(z: 1.8f)
);
while (!cts.IsCancellationRequested)
{
Debug.WriteLine("Publishing! ros2 publisher");
await pub.PublishAsync(twist);
await Task.Delay(1000, cts.Token);
}
}
I'm trying to get ROS2 working in .NET apps in Windows, and I'm attempting to follow the instructions on installing dependencies so the examples can be run. I understand Windows does not support rosdep, and the dependencies will need to be installed manually. What does that procedure look like? Thanks...
I was setting up a "Fake" Rcl system so that I can at least launch my GUI without having ROS installed. I got almost all the way to the end before I realized that the "Context" property on my "FakeNode" is being called by the Rcl library itself. But since I can't construct a RclContext without having ROS installed I'm right back where I started.
I'm sure there's a good reason why not...but can the type of the Context property be IRclContext instead of RclContext?
Attempting a simple program utilizing Rcl classes. My Program.cs:
using Rcl;
// Must add "somewhere in the source code of the project"
[assembly: System.Runtime.CompilerServices.DisableRuntimeMarshalling]
Console.WriteLine("Hello, World! Today we're going to communicate over ROS2 using .NET. Aren't you excited?!");
var whatToDo = Console.ReadLine();
if (whatToDo != null) {
if (whatToDo.StartsWith("T", StringComparison.CurrentCultureIgnoreCase)) {
// Talker
await using var ctx = new RclContext(args); // EXCEPTION THROWN HERE
using var node = ctx.CreateNode("SmplROS2dNET2");
using var pub = node.CreatePublisher<Rosidl.Messages.Example.String>("/smpl");
Console.WriteLine("Enter anything to publish a one-word message...");
// User echos topic in another command window, enters letter, presses "Enter"...
Console.ReadLine();
pub.Publish(new Rosidl.Messages.Example.String("Published. "));
} else if (whatToDo.StartsWith("L", StringComparison.CurrentCultureIgnoreCase)) {
//TODO: listener
}
}
At the line noted above, an exception happens, showing this information:
System.TypeInitializationException: 'The type initializer for 'Rcl.RclContext' threw an exception.'
Inner Exception: DllNotFoundException: Unable to load DLL 'rcutils' or one of its dependencies: The specified module could not be found. (0x8007007E)
This exception was originally thrown at this call stack:
System.Runtime.InteropServices.NativeLibrary.LoadLibraryByName(string, System.Reflection.Assembly, System.Runtime.InteropServices.DllImportSearchPath?, bool) in NativeLibrary.cs
Rcl.RclContext.RclContext()
I tried adding one of these two dependencies...
...but each time I browse to the DLL and hit "OK", I'm told the reference is invalid or unsupported.
Finally, since rclnet does not support IDLs currently, will I run into more trouble trying to use Rosidl.Messages.Example classes? Thanks...
I can build the C:\dev\rclnet-1.3.1\examples\RclExamples.sln solution in Visual Studio 2022, but setting the starting project to fake_clock and running in Debug mode, the following line in C:\dev\rclnet-1.3.1\src\Rcl.NET\RclContext.cs (#30) gets the following exception:
private SpinLock _handleLock = new(), _callbackLock = new();
System.TypeInitializationException: 'The type initializer for 'Rcl.RclContext' threw an exception.'
DllNotFoundException: Unable to load DLL 'rcutils' or one of its dependencies: The specified module could not be found. (0x8007007E)
This exception was originally thrown at this call stack:
System.Runtime.InteropServices.NativeLibrary.LoadLibraryByName(string, System.Reflection.Assembly, System.Runtime.InteropServices.DllImportSearchPath?, bool) in NativeLibrary.cs
I then try to add solution or project references to one of these DLLs:
...but each time I browse to the DLL and hit "OK", I'm told the reference is invalid or unsupported. How can I fix this? Thanks...
I had my Blazor web app working fine, communicating over ROS2 via a node I initialized in the Program.cs (relevant code below). I then made a trivial change to my Razor file, and the next time I ran it, it would hang at the point where the node is created. I can create the RclContext but can't do anything with it.
using Rcl;
...
var ctx = new RclContext();
var node = ctx.CreateNode("ROS2dotNETwebApp"); // Hangs here
var pub = node.CreatePublisher<Rosidl.Messages.Example.String>("/blazor");
var sub = node.CreateSubscription<Rosidl.Messages.Example.String>("/blazed");
builder.Services.AddSingleton(ctx);
builder.Services.AddSingleton(node);
builder.Services.AddSingleton(pub);
builder.Services.AddSingleton(sub);
var app = builder.Build();
I even created a new Blazor web app and only added these lines (and added to launchSettings.json environmentVariables and installed the RclNet NuGet package), and it still hangs. I see an empty command window and never a home page. When I terminate the command window, Visual Studio flashes a message saying "Unable to connect to web server 'https'". If I run the Release EXE from a command window, it also hangs, and when I hit "Ctrl-C" to terminate, it displays:
[foonathan::memory] Allocator foonathan::memory::heap_allocator (at 0000000000000000) leaked 36912 bytes.
In case it's relevant, I tried solving it by running the following commands in an admin command window:
dotnet dev-certs https --clean
dotnet dev-certs https --trust
What should I now try first? Thanks...
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.