-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/timesource options #266
Merged
Merged
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
4a5886f
Added TimeSource for Simulation Time
szylis 2269625
Improved System ITimeSource
szylis 0fe4f7b
Added feature of setting time source from config.json
szylis 4388b64
Improved DotNet TimeSources
szylis c9579a1
Added thread-safe TimeAsDouble value
szylis 7fc0d3b
Updated UnityTimeSource
szylis 669121c
Set default TimeSource for simulation
szylis 128bbda
Added ROS2TimeSource into time source provider
szylis b3e5553
Enable unity time to be selected from json config
szylis 53d251d
Refactor - change name of dotnet system time source
szylis c40a3d6
Refactor
szylis 9519b0b
Added obsolete attribute to redundant time sources
szylis bfa79b6
Remove FindObjectOfType
szylis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
48 changes: 48 additions & 0 deletions
48
Assets/AWSIM/Scripts/Clock/Scripts/DotNetSimulationTimeSource.cs
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,48 @@ | ||
using System; | ||
using System.Threading; | ||
using ROS2; | ||
|
||
namespace AWSIM | ||
{ | ||
/// <summary> | ||
/// A thread-safe timesource class that provides simulation time based on the dot net system utc time. | ||
/// This time source takes into account the value of the simulation timescale and | ||
/// starts at zero value when the simulation is started. | ||
/// </summary> | ||
public class DotNetSimulationTimeSource : ITimeSource | ||
{ | ||
private DateTime prevDateTime; | ||
private double time; | ||
private bool hasStarted = false; | ||
|
||
private readonly object lockObject = new object(); | ||
|
||
public DotNetSimulationTimeSource() | ||
{ | ||
hasStarted = false; | ||
} | ||
|
||
public void GetTime(out int seconds, out uint nanoseconds) | ||
{ | ||
lock (lockObject) | ||
{ | ||
DateTime currDateTime = DateTime.UtcNow; | ||
|
||
if(!hasStarted) | ||
{ | ||
hasStarted = true; | ||
time = 0.0; | ||
|
||
prevDateTime = currDateTime; | ||
} | ||
|
||
TimeSpan timeSpan = currDateTime - prevDateTime; | ||
prevDateTime = currDateTime; | ||
|
||
time += timeSpan.TotalMilliseconds * 0.001f * TimeScaleProvider.TimeScale; | ||
TimeUtils.TimeFromTotalSeconds(time, out seconds, out nanoseconds); | ||
} | ||
} | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
Assets/AWSIM/Scripts/Clock/Scripts/DotNetSimulationTimeSource.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
41 changes: 41 additions & 0 deletions
41
Assets/AWSIM/Scripts/Clock/Scripts/TimeAsDoubleProvider.cs
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 UnityEngine; | ||
|
||
namespace AWSIM | ||
{ | ||
/// <summary> | ||
/// A thread-safe static class to provide the value of the Unity time as double. | ||
/// </summary> | ||
public static class TimeAsDoubleProvider | ||
{ | ||
private static readonly object lockObject = new object(); | ||
|
||
private static double timeAsDouble = 0.0; | ||
public static double TimeAsDouble | ||
{ | ||
get | ||
{ | ||
lock(lockObject) | ||
{ | ||
return timeAsDouble; | ||
} | ||
} | ||
} | ||
|
||
|
||
#region [Public Methods] | ||
|
||
/// <summary> | ||
/// Synchronise the value of the timeAsDouble variable with the Time.timeAsDouble from the Unity thread. | ||
/// </summary> | ||
public static void DoUpdate() | ||
{ | ||
lock(lockObject) | ||
{ | ||
timeAsDouble = Time.timeAsDouble; | ||
} | ||
} | ||
|
||
#endregion | ||
} | ||
} | ||
|
11 changes: 11 additions & 0 deletions
11
Assets/AWSIM/Scripts/Clock/Scripts/TimeAsDoubleProvider.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using FindObjectOfType, could you please add a [SerializeField] TimeSourceSelector to AutowareSimulation.cs?
I would like to avoid type find at runtime as much as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. I've just made the change. Thanks