CNCLgithub / GalileoEvents

Galileo + Events
MIT License
2 stars 0 forks source link

creating incongruent stimuli #17

Closed belledon closed 4 years ago

belledon commented 4 years ago

@jeffzma2000 ,

For the next stage of the experiment we need to generate stimuli where the second ball, B, has a change in mass between collisions AB and BC.

There are several ways to go about this (open to suggestions) but I think the simplest method is as follows:

  1. lets assume that the mass ratio for AB is 1:1. simulate the first collisions and capture the instantaneous linear and angular velocity of A and B right after the moment of collision (t = c+1).
  2. In the second stage where B has a different mass, set the initial position of A and B and their velocities to match the previous simulation (as if they start at t = c+1).
  3. Run the second simulation forward
belledon commented 4 years ago

here is some reference code to get things started (not debugged yet)

You can now specify initial velocities when you add objects to a ramp scene (note this is a new, 3ball class, from galileo_ramp import Ball3World, Ball3Sim)

https://github.com/CNCLgithub/galileo-ramp/blob/423bed0ee703249d3206af00d594124798b30fc7/galileo_ramp/ball_world.py#L18-L25

In the new sim class Ball3Sim this gets passed to pybullet and updates initial velocities

https://github.com/CNCLgithub/galileo-ramp/blob/423bed0ee703249d3206af00d594124798b30fc7/galileo_ramp/ball_sim.py#L7-L20

belledon commented 4 years ago

with the above code (that you will probably have to debug a little) can you please make an aptly named script that for now generates 1 trial with two parts, where A:B:C is 1:1:1 but after AB collision, the ratio becomes 1:2:1

The way I would go about this is instead of just saving the scene.json in https://github.com/CNCLgithub/galileo-ramp/blob/26231526e56e353930ff4c4d5ff8ede131860c23/scripts/stimuli/create_3ball_scene.py#L73-L75, I would have the trial be a directory that contains several files:

trial # /
    first_scene.json # A:B:C = 1:1:1
    first_trace.npy # simulation of first_scene
    second_scene.json # A:B:C = 1:2:1
    second_trace.npy # simulation of second scene 
    full_trace.npy # just a concatenation of the two traces to have a seamless trace

take a look at https://github.com/CNCLgithub/rigid_body_world/blob/master/examples/marbles.py to see how to use scene data to create a simulation.

The output of simulation is a few matrices where the rows represent time. the first matrix pla is a Tx3XNx3 array where N is the number of objects. The second axis is either positions (0), linear velocity (1) and angular velocity (2). The second array, rot is a TxNx4 describe the rotation of each object as a quaternion (wxyz). lastly cols describes a collision map that you can use to find the time stamp of collision

The dataset class that is used under the hood for allot of the code does something very similar https://github.com/CNCLgithub/galileo-ramp/blob/26231526e56e353930ff4c4d5ff8ede131860c23/galileo_ramp/exp1_dataset.py#L92-L109

You should be able to

  1. create the first scene
  2. simulate the first scene
  3. extract the time stamp of the first collisions t = c the same way the dataset code does
  4. get the state of the objects at t = c + 1 and pass it into 3BallWorld
  5. use 3BallSim to simulate the second stage
  6. concatenate the two stages and say it as a numpy file. np.save