Skip to content
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

Made clock published independently from time scale #248

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 32 additions & 13 deletions Assets/AWSIM/Scripts/ROS/ClockPublisher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,50 @@ public class ClockPublisher : MonoBehaviour

IPublisher<rosgraph_msgs.msg.Clock> clockPublisher;
rosgraph_msgs.msg.Clock clockMsg;
float timer = 0;
float timeScale = 1.0f;

void PublishClock()
{
SimulatorROS2Node.UpdateROSClockTime(clockMsg.Clock_);
clockPublisher.Publish(clockMsg);
}

void Start()
{
InvokeRepeating("PublishClock", 1.0f, 1.0f/publishHz);
}
#region [Life Cycle]

// Start is called before the first frame update
void Awake()
{
var qos = qosSettings.GetQoSProfile();
clockPublisher = SimulatorROS2Node.CreatePublisher<rosgraph_msgs.msg.Clock>(topic, qos);
clockMsg = new rosgraph_msgs.msg.Clock();
}


void OnDestroy()
{
SimulatorROS2Node.RemovePublisher<rosgraph_msgs.msg.Clock>(clockPublisher);
}

#endregion

void Start()
{
timeScale = Time.timeScale;
InvokeRepeating("PublishClock", 1.0f, timeScale/publishHz);
}

void Update()
{
if (Mathf.Abs(Time.timeScale - timeScale) > 0.01f)
{
timeScale = Time.timeScale;
OnTimeScaleChanged();
}
}

void OnTimeScaleChanged()
{
CancelInvoke();
InvokeRepeating("PublishClock", 0.0f, timeScale/publishHz);
}

void PublishClock()
{
SimulatorROS2Node.UpdateROSClockTime(clockMsg.Clock_);
clockPublisher.Publish(clockMsg);
}
}
}
}
Loading