sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    MSPhysics tests and questions

    Scheduled Pinned Locked Moved Plugins
    104 Posts 21 Posters 44.7k Views 21 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • F Offline
      faust07
      last edited by

      Hi Anton, short question: how can I make up for the differences between controller and scripted input? With the same pre-set parameters why arise the differences in the results?
      Model slightly reduced to test it.


      Pengu-Test_03.gif


      Pengu-Test_03.skp

      1 Reply Last reply Reply Quote 0
      • F Offline
        faust07
        last edited by

        Here is an approximation of the setting of a servo joint (oscillator) with controller or script.
        The oscillation about 180° in both directions corresponds to the number pi in the script. Seems somehow to be logical ...


        Servo-Test_04.jpg


        Servo-Test_04.skp

        1 Reply Last reply Reply Quote 0
        • A Offline
          Anton_S
          last edited by

          Hello faust,

          Nice coding there. So, when you assign value via script, i.e some_servo.controller=, the value is assumed as some angle in radians. Whenever, you assign it via controller, the angle is assumed as the angle in preset angle units, which are by default in degrees.

          Now, instead of iterating through all servos to assign their controller, a more reliable way would be to use a variable. Control the variable through script and change servo angle via controller. Here is what I mean:

          onStart { @p3_head_osc = 30 set_var('wing', 0) } onUpdate { set_var('wing', oscillator(@p3_head_osc) * 30) }

          Paste this in the controller of a desired servo:
          get_var('wing')

          Other than that, I'm amazed by your improvement in scripting. Keep it up!

          Anton

          1 Reply Last reply Reply Quote 0
          • F Offline
            faust07
            last edited by

            Thanks Anton! The simple way is the best - I will try it. Here a little pengu fun with my old script solution and "Curvy Piston".


            Pengu-Test_11.gif

            1 Reply Last reply Reply Quote 0
            • robintR Offline
              robint
              last edited by

              Hi All

              Not wishing to hijack this OP, but I cant see where to post otherwise
              so here goes. Attached is a simple falling block assy to test the validity of accel due to gravity, ie block should fall 9.81m in 1 sec, all thing set right.

              What would be nice is to have a script that stopped the sim once the bloack collided with the baseplate. In theory I should be able to read the time taken, no of frames etc on the bottom lhs of the screen, but just now I approximate this by tapping pause on eyeballing the block - not very accurate at all

              Iv'e seen there is an "on touch" script with slamming doors but Im still a ruby newbie

              Is there a way to stop the sim on block reaching the baseplate?

              FYI If I can get this to work for my students, then the next step is to simulate the viscosity experiment using a falling sphere in fluid, but I dont know if SU can simulate viscous fluid yet?

              Great stuff on this page, I am truly humbled

              Robin


              falling block.skp

              As one door closes another one slams in your face

              1 Reply Last reply Reply Quote 0
              • F Offline
                faust07
                last edited by

                Hi Robint
                Put this script into your baseplate (copy the 3 lines, select the plate, open MSP UI, select "Script", paste the lines into the Script window, run MSP):

                onTouch { |toucher, position, normal|
                MSPhysics::Simulation.reset
                }

                and the simulation stops "onTouch".

                1 Reply Last reply Reply Quote 0
                • robintR Offline
                  robint
                  last edited by

                  @faust07 said:

                  Hi Robint
                  Put this script into your baseplate (copy the 3 lines, select the plate, open MSP UI, select "Script", paste the lines into the Script window, run MSP):

                  onTouch { |toucher, position, normal|
                  MSPhysics::Simulation.reset
                  }

                  and the simulation stops "onTouch".

                  Hi Faust, thanx for the tip, but not quite there yeet

                  the simulation resets and I lose all the time/frame data at the bottom of screen - which is what I need for this to be useful.

                  I tried .pause and .stop but they dont exist

                  Is there something else I could try?

                  As one door closes another one slams in your face

                  1 Reply Last reply Reply Quote 0
                  • robintR Offline
                    robint
                    last edited by

                    Hi Faust

                    Through the Ruby Code editor, I found a start_timer and stop_timer function

                    Would this help?

                    Say put start at the top to activate when staring sim,

                    then stop_timer after the reset action line

                    then display timer?

                    sorry my newbie attempts at script (do you hav any recommendations on the best way to learn script for MSP - there's so much flack out there its hard to know where to start)

                    Cheers

                    Robin

                    As one door closes another one slams in your face

                    1 Reply Last reply Reply Quote 0
                    • F Offline
                      faust07
                      last edited by

                      Hi Robin,
                      have tested to find a solution to pause simulation per script, but have nothing found until now.
                      I'm a script newbie too. For my purposes I look into scripts of models from the experts at 3D-Warehouse (AntonS & PituPhysics) or ask them in Anton's main MSP post.

                      1 Reply Last reply Reply Quote 0
                      • robintR Offline
                        robint
                        last edited by

                        Well we are both struggling, blind leading the blind

                        FYI this timer thing is fundamental to simulating physical systems (mass speed acceleration)

                        The on touch is a good start, just need to time the sequence and display result on reset

                        opens up a whole new way of simulating mechanical systems

                        as fundamental say as a thermometer is to tell you the temperature - if you see my point

                        so I must perservere. If I get a result I will post it you

                        Cheers

                        Robin

                        As one door closes another one slams in your face

                        1 Reply Last reply Reply Quote 0
                        • robintR Offline
                          robint
                          last edited by

                          A bing moment has occured ☀

                          when I # out the reset line, I just had a ontouch line only and it outputs to screen what might be some sort of final velocity m/s on impact (according to the script info)

                          pls see model

                          Now I cant yet correlate that to the calc velocity which should be 14m/s on impact from 10m
                          it comes out at 58 and varies with the UI sim setting of Newton update rate (currently 10)

                          also from dropping from 5m gives 33 (should be 9.9m/s and is 1/sqr2 - .707) whereas 33/58 is ca.57

                          maybe some dynamic friction in play?

                          Is this a worthwhile line of enquiry?

                          Cheers

                          Robin

                          ps the ball is in anton's examples funny little thing - and something for gamers pool table maybe?


                          falling block.skp

                          As one door closes another one slams in your face

                          1 Reply Last reply Reply Quote 0
                          • A Offline
                            Anton_S
                            last edited by

                            Yes, the final velocity should be 14 m/s, and it is 14 m/s.

                            Your script in the model you posted, just outputs the frame:

                            onTouch { |toucher, position, normal, force, speed|
                              simulation.log_line("onTouch #{frame}")
                            }
                            

                            That explains why you get unrelated results.

                            To output the final velocity, you should change the code to output the speed:

                            onTouch { |toucher, position, normal, force, speed|
                              simulation.log_line("onTouch #{speed}")
                            }
                            

                            And besides, setting the linear damping of the falling box to zero will make the final velocity even more right because this will eliminate the dissipative force.

                            1 Reply Last reply Reply Quote 0
                            • robintR Offline
                              robint
                              last edited by

                              Thank you so much Anton, I was just about to post an apology for a stoopid boy Pike moment (no smilie for Duh 😳 )

                              but I read the second line and it outputs frame to screen, what a numpty

                              You gave me some other scrip that outputs velocity, strange to note that the cube reaches a terminal velocity ca 2m/s ca halfway down - intriguing. Is there something in there that simulates viscosity?

                              onUpdate {

                              Get current velocity

                              cv = this.get_velocity

                              Output it in the note

                              note = sprintf("Velocity: (%.3f, %.3f, %.3f)", cv.x, cv.y, cv.z)
                              simulation.display_note(note)
                              }

                              Cheers

                              Robin

                              As one door closes another one slams in your face

                              1 Reply Last reply Reply Quote 0
                              • A Offline
                                Anton_S
                                last edited by

                                Yes, the viscosity is simulated by the linear damping. To remove the linear damping, select the desired group, open MSPhysics UI, activate the Properties tab, and set Linear Damping to 0.00. This should alter the height of terminal velocity.

                                If you meant something else, like water or buoyancy, you can add a buoyancy plane by navigating to (Menu)Extensions->MSPhysics->Create Buoyancy Plane. Although the liquid is not simulated. It's just the buoyancy force that is applied.

                                1 Reply Last reply Reply Quote 0
                                • robintR Offline
                                  robint
                                  last edited by

                                  Hi Anton

                                  Just when I thought you cracked it with speed, something strange happens

                                  When dropping the block from 10m = ok = 14m/s as per calc (see model)

                                  Move the block down to 5m => nonesense answer like 0.07... (should be 9.9m/s)

                                  Yet move block to other elevations like 8.5m or 2.5m , seems to work ok (but I haven't checked the result against calcs (12.9, 7)

                                  So I am completely stumped 😒

                                  BTW sometimes the block appears to penetrate the baseplate and slowly return to zero, could this be the reason?

                                  Thats ruined my day

                                  Cheers

                                  Robin


                                  falling block2.skp

                                  As one door closes another one slams in your face

                                  1 Reply Last reply Reply Quote 0
                                  • robintR Offline
                                    robint
                                    last edited by

                                    Maybe uncovered a nasty bug? Anton

                                    Here's a suggestion from your speed indicator

                                    onUpdate {

                                    Get current velocity

                                    cv = this.get_velocity

                                    Output it in the note

                                    note = sprintf("Velocity: (%.3f)", cv.z)
                                    simulation.display_note(note)
                                    }

                                    When it runs, on collision it displays 0.00 as expected, the block has stopped but we lost the terminal velocity

                                    Could we say put an IF loop in the output velocity to note, only iff velocity <say .5m/s, then it should go to zero when the block stops (assuming no bounce)

                                    Just a thought, maybe a simpler approach? from a ruby newby

                                    Cheers

                                    Robin

                                    As one door closes another one slams in your face

                                    1 Reply Last reply Reply Quote 0
                                    • robintR Offline
                                      robint
                                      last edited by

                                      Sorry, Im getting tired

                                      I meant it should retain the highest last value in note when the block stops

                                      Apologies

                                      Robin

                                      As one door closes another one slams in your face

                                      1 Reply Last reply Reply Quote 0
                                      • A Offline
                                        Anton_S
                                        last edited by

                                        It's all cool 😄

                                        Here is the code for viewing maximum velocity.

                                        onStart {
                                          @max_vz = 0
                                        }
                                        
                                        onUpdate {
                                          v = this.get_velocity
                                          if v.z.abs > @max_vz
                                            @max_vz = v.z.abs
                                            simulation.display_note(sprintf("Max Speed %.3f m/s", @max_vz))
                                          end
                                        }
                                        

                                        And yes, the speed indicator in onTouch may not always work right, which is the problem of the physics engine that my wrapper is using.

                                        1 Reply Last reply Reply Quote 0
                                        • robintR Offline
                                          robint
                                          last edited by

                                          Hi Anton

                                          Installed your script, works a treat and pretty accurate 😎

                                          However I have meddled and got stuck, I cant find a way to print another result on a new line, tried everything, puts, print (can't find sprintf in docs either)

                                          As you see I want to print elapsed time as well and it works but overwrite the Max Speed result on the same line

                                          I feel really dumb getting stuck on this trivial matter, pls help 😢

                                          BTW would I be right in saying that MSP script is a subset of official Ruby 2.0 and some elements like puts and print (they dont do anything on screen or riase an error)are left out?

                                          Cheers

                                          Robin


                                          falling block3.skp

                                          As one door closes another one slams in your face

                                          1 Reply Last reply Reply Quote 0
                                          • A Offline
                                            Anton_S
                                            last edited by

                                            Here:

                                            onStart {
                                              @max_vz = 0
                                            }
                                            
                                            onUpdate {
                                              v = this.get_velocity
                                              if v.z.abs > @max_vz
                                                @max_vz = v.z.abs
                                                simulation.display_note(sprintf("Max Speed %.3f m/s\nElapsed Time; %.2f s", @max_vz, world.time))
                                              end
                                            }
                                            
                                            1 Reply Last reply Reply Quote 0
                                            • 1
                                            • 2
                                            • 3
                                            • 4
                                            • 5
                                            • 6
                                            • 3 / 6
                                            • First post
                                              Last post
                                            Buy SketchPlus
                                            Buy SUbD
                                            Buy WrapR
                                            Buy eBook
                                            Buy Modelur
                                            Buy Vertex Tools
                                            Buy SketchCuisine
                                            Buy FormFonts

                                            Advertisement