-
Notifications
You must be signed in to change notification settings - Fork 114
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
Fix scene simulation time #272
Conversation
Its been some time, but as I recall, there was no provision of providing the time vector to javascript. It took only (start_time, end_time and time_delta) and calculated time vector based on these. We will require some changes in code to accomodate both. |
The start time is displayed correctly after the first time the simulation is run. If looped, the start time is correct if non zero. It is only in the beginning, before the simulation has been run the first time, where the time is (possibly) incorrectly displayed as 0. |
@tarzzz The time value is hardcoded to zero here: pydy/pydy/viz/static/index.html Line 91 in eaf45c6
Is there a way to set the initial time immediately after loading the model? |
Also, when I modify .js files in the static directory, changes are not reflected when I start a server (or at least it doesn't show the changes when I 'inspect element' in my browser). Is there a way to force this to refresh? |
We will need to set the initial time, dynamically on load. Another way is to go to pydy-resources directory which is created for that simulation. You can edit code inside the js/ directory, test it there and if it works, change the same code in static directory, and push to github. |
I've deleted the whole pydy resources directory and re-executed all the I'll try modifying the generated js directory later.
|
Maybe we need to create a jupyter extension so that the js files for the viz are served from the user's notebook extension directory in their home directory. That could possibly avoid the copying of the files to the working directory. |
c9e998d
to
1ac3f42
Compare
This now works for me. |
self._scene_info["timeDelta"] = total_time / (num_time_steps - 1) | ||
self._scene_info["startTime"] = self.times[0] | ||
else: | ||
self._scene_info["timeDelta"] = 1.0 / self.frames_per_second |
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.
@oliverlee You should include the "startTime" dict key here also (can be set to zero). Else the scene_desc json files will become in-consistent for two cases, and js code will break. Then it should be okay to be merged in.
Thanks for the fix :)
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.
fixed
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.
This is ready to be merged.
On Oct 17, 2015 16:01, "Tarun Gaba" [email protected] wrote:
In pydy/viz/scene.py
#272 (comment):@@ -408,9 +408,17 @@ def _generate_json(self, directory=None, prefix=None):
self._generate_scene_dict()self._scene_info["simulationData"] = self._simulation_json_file
# NOTE : Python 3 division is imported at the top of the file so
# this will be a float.
self._scene_info["timeDelta"] = 1 / self.frames_per_second
if self.times is not None:
# Assume that times is evenly spaced and monotonic.
# TODO: Interpolate if times are not evenly spaced.
total_time = self.times[-1] - self.times[0]
self._scene_info["timeDelta"] = total_time / (num_time_steps - 1)
self._scene_info["startTime"] = self.times[0]
else:
self._scene_info["timeDelta"] = 1.0 / self.frames_per_second
@oliverlee https://github.com/oliverlee You should include the
"startTime" dict key here also (can be set to zero). Else the scene_desc
json files will become in-consistent for two cases, and js code will break.
Then it should be okay to be merged in.—
Reply to this email directly or view it on GitHub
https://github.com/pydy/pydy/pull/272/files#r42309534.
1ac3f42
to
ffa15ef
Compare
Update with master please. |
ffa15ef
to
cc3caca
Compare
I just tried this branch with the mass_spring_damper notebook and changes the sys.times var to go from 5.0 to 10.0 seconds with 100 steps in time, but the slider bar gives me 0.0 to 3.3 seconds with 100 steps. The value to the left reflects the seconds and the value in the black box that follows the slider when dragged seems to reflect the frame number. So it doesn't seem to work for me. |
daa1e39
to
1f548f6
Compare
We should come up with a standardized test for checking js related fixes. Fixing one thing might lead to something else breaking, and it is difficult to track unless someone manually runs the simulation and tests it. |
1f548f6
to
7a2efe7
Compare
Ok, this now works for me. +1. You need to update with master it seems. |
Use simulation times when computing 'timeDelta'. Add 'startTime' and 'speedup' fields for future use in javascript scene.
Set scene time value to first value in scene.times array. This commit resolves issue pydy#253.
7a2efe7
to
62dbeaf
Compare
The time shows up as 0 when the model is loaded (not the first value in the times array). Maybe one of you knows how to fix it since I don't know JS.
We should probably implement some sort of speedup slider to change fps in the future.