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

Fix scene simulation time #272

Merged
merged 4 commits into from
Oct 19, 2015
Merged

Conversation

oliverlee
Copy link
Contributor

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.

@tarzzz
Copy link
Contributor

tarzzz commented Oct 15, 2015

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.

@oliverlee
Copy link
Contributor Author

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.

@oliverlee
Copy link
Contributor Author

@tarzzz The time value is hardcoded to zero here:

<span style="margin-right:1em;" id="time"> 0.000 s</span>

Is there a way to set the initial time immediately after loading the model?

@oliverlee
Copy link
Contributor Author

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?

@tarzzz
Copy link
Contributor

tarzzz commented Oct 16, 2015

We will need to set the initial time, dynamically on load.
Regarding the js files, after you change the code in static directory, you need to re-execute the python code for simulation.

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.

@tarzzz tarzzz self-assigned this Oct 16, 2015
@oliverlee
Copy link
Contributor Author

I've deleted the whole pydy resources directory and re-executed all the
python code but there's no change. This is the script I use:
https://github.com/oliverlee/bicycle/blob/master/python/scripts/create_viz.py

I'll try modifying the generated js directory later.
On Oct 16, 2015 19:44, "Tarun Gaba" [email protected] wrote:

We will need to set the initial time, dynamically on load.
Regarding the js files, after you change the code in static directory, you
need to re-execute the python code for simulation.

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.


Reply to this email directly or view it on GitHub
#272 (comment).

@moorepants
Copy link
Member

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.

@oliverlee
Copy link
Contributor Author

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
Copy link
Contributor

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 :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copy link
Contributor Author

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.

@moorepants
Copy link
Member

Update with master please.

@moorepants
Copy link
Member

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.

@tarzzz
Copy link
Contributor

tarzzz commented Oct 18, 2015

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.

@moorepants
Copy link
Member

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.
oliverlee added a commit that referenced this pull request Oct 19, 2015
@oliverlee oliverlee merged commit b5edaf4 into pydy:master Oct 19, 2015
@oliverlee oliverlee deleted the fix-scene-simulation-time branch October 21, 2015 22:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants