-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 33f1338
Showing
7 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
bin/ | ||
obj/ | ||
/packages/ | ||
riderModule.iml | ||
/_ReSharper.Caches/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ROSNET6", "ROSNET6\ROSNET6.csproj", "{471266C0-8225-43B0-928D-D91FEF2947ED}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{471266C0-8225-43B0-928D-D91FEF2947ED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{471266C0-8225-43B0-928D-D91FEF2947ED}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{471266C0-8225-43B0-928D-D91FEF2947ED}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{471266C0-8225-43B0-928D-D91FEF2947ED}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace ROSNET6; | ||
|
||
public interface IObservableROSWorker<in TArg, out T> | ||
{ | ||
IObservable<T> GetObservable(); | ||
Task InitWorker(TArg arg); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using ROSNET6; | ||
using Serilog; | ||
using Uml.Robotics.Ros; | ||
|
||
Log.Logger = new LoggerConfiguration() | ||
.MinimumLevel.Debug() | ||
.WriteTo.Console() | ||
.CreateLogger(); | ||
|
||
|
||
var host = Host.CreateDefaultBuilder(args).UseSerilog() | ||
.ConfigureServices(services => { services.AddSingleton<ROSWorker>(); }) | ||
.Build(); | ||
|
||
ROS.Init(Array.Empty<string>(), "ROSNET6"); | ||
var spinner = new AsyncSpinner(); | ||
spinner.Start(); | ||
|
||
var rosWorker = host.Services.GetService<ROSWorker>(); | ||
|
||
IObservable<Messages.std_msgs.String> observable = rosWorker.GetObservable(); | ||
IDisposable disposable = observable.Subscribe(msg => | ||
{ | ||
Log.Information("Received message. \n" + $"MessageType: {msg.MessageType} \n" + $"Data: {msg.data} \n"); | ||
}); | ||
|
||
NodeHandle node = new NodeHandle(); | ||
await rosWorker.InitWorker(node); | ||
|
||
await host.RunAsync(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"profiles": { | ||
"ROSNET6": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"environmentVariables": { | ||
"DOTNET_ENVIRONMENT": "Development", | ||
"ROS_MASTER_URI": "http://localhost: 11311" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Worker"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<UserSecretsId>dotnet-ROSNET6-E5150359-B512-4BC0-BE21-938FBE44DDC6</UserSecretsId> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1"/> | ||
<PackageReference Include="Serilog" Version="2.11.0"/> | ||
<PackageReference Include="Serilog.Extensions.Hosting" Version="5.0.1"/> | ||
<PackageReference Include="Serilog.Extensions.Logging" Version="3.1.0"/> | ||
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.1"/> | ||
<PackageReference Include="System.Reactive" Version="5.0.0"/> | ||
<PackageReference Include="System.Reactive.Core" Version="5.0.0"/> | ||
<PackageReference Include="System.Reactive.Linq" Version="5.0.0"/> | ||
<PackageReference Include="Uml.Robotics.Ros" Version="1.1.2"/> | ||
<PackageReference Include="YAMLParser" Version="1.0.0"/> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System.Reactive.Concurrency; | ||
using System.Reactive.Linq; | ||
using System.Reactive.Subjects; | ||
using Uml.Robotics.Ros; | ||
using String = Messages.std_msgs.String; | ||
|
||
namespace ROSNET6; | ||
|
||
public class ROSWorker : IObservableROSWorker<NodeHandle, String> | ||
{ | ||
private readonly ILogger<ROSWorker> _logger; | ||
private readonly Subject<String> _subject = new(); | ||
private Subscriber? _subscriber; | ||
|
||
public ROSWorker(ILogger<ROSWorker> logger) | ||
{ | ||
_logger = logger; | ||
_logger.LogInformation("ROSWorker: constructed."); | ||
} | ||
|
||
public IObservable<String> GetObservable() => _subject.ObserveOn(Scheduler.NewThread).AsObservable(); | ||
|
||
public async Task InitWorker(NodeHandle nodeHandle) | ||
{ | ||
try | ||
{ | ||
await nodeHandle.SubscribeAsync<String>( | ||
"/chatter", | ||
1, | ||
cb => _subject.OnNext(cb)); | ||
_logger.LogInformation("ROSWorker: Subscriber initialized."); | ||
|
||
ROS.WaitForShutdown(); | ||
} | ||
catch (Exception e) | ||
{ | ||
_logger.LogError("ROSWorker: Subscribe failed.\\n {Message}", e.Message); | ||
throw; | ||
} | ||
} | ||
} |