• Login
sketchucation logo sketchucation
  • Login
🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

Pause a simulation...open and close a file...continue?

Scheduled Pinned Locked Moved SketchyPhysics
10 Posts 3 Posters 1.2k Views
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.
  • M Offline
    mptak
    last edited by 19 Feb 2011, 12:29

    I am trying to revive this topic as a way of passing changing variables into a sketchy physics simulation. Let's say there is some external program that will check the color of the shirt I am wearing right now (when the right now changes every 15 seconds) and then update a flat ascii file with the name of the color. Is there a way to poll that file every 15 seconds and then have SP3.2 use that color value (or velocity...or position)?

    1 Reply Last reply Reply Quote 0
    • T Offline
      TIG Moderator
      last edited by 19 Feb 2011, 13:00

      @mptak said:

      I am trying to revive this topic as a way of passing changing variables into a sketchy physics simulation. Let's say there is some external program that will check the color of the shirt I am wearing right now (when the right now changes every 15 seconds) and then update a flat ascii file with the name of the color. Is there a way to poll that file every 15 seconds and then have SP3.2 use that color value (or velocity...or position)?

      Lets say you have a variable @color="Red" that you use elsewhere in your code - now set this to get updated every 15 seconds:-
      tid=UI.start_timer(15, true){set_color()}
      when you no longer want it to be updating you can use:-
      UI.stop_timer(tid)
      The method itself could be something like this:-

      <span class="syntaxdefault">def set_color</span><span class="syntaxkeyword">()<br /></span><span class="syntaxdefault">  </span><span class="syntaxkeyword">@</span><span class="syntaxdefault">color</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">IO</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">read</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"C;\\Temp\\mycolor.txt"</span><span class="syntaxkeyword">).</span><span class="syntaxdefault">chomp<br />  </span><span class="syntaxcomment">### for example - assumes one line of text and chomp removes any \n<br /></span><span class="syntaxdefault">end</span>
      

      EDIT@ corrected a typo...

      TIG

      1 Reply Last reply Reply Quote 0
      • M Offline
        Mr.K.1
        last edited by 19 Feb 2011, 17:40

        @color=IO.read("C;\\Temp\\mycolor.txt")[0].chomp
        

        This will actually give an error, because [0] part will return the first character as an ascii number and chompcan't work with numbers.

        So if you just remove that it will work perfectly well.

        @color=IO.read("C;\\Temp\\mycolor.txt").chomp
        
        1 Reply Last reply Reply Quote 0
        • T Offline
          TIG Moderator
          last edited by 19 Feb 2011, 17:54

          @unknownuser said:

          @color=IO.read("C;\\Temp\\mycolor.txt")[0].chomp
          

          This will actually give an error, because [0] part will return the first character as an ascii number and chompcan't work with numbers.

          So if you just remove that it will work perfectly well.

          @color=IO.read("C;\\Temp\\mycolor.txt").chomp
          

          My typo - I meant to type IO.readlines which returns all lines in the file 😳
          The IO.read is probably better anyway...
          I have corrected the original... 😒

          TIG

          1 Reply Last reply Reply Quote 0
          • M Offline
            mptak
            last edited by 20 Feb 2011, 01:53

            Very cool stuff. Thank you. However I am still having issues with making it work within
            Sketchy Physics. I would guess that the same IO.read should work on an intermittent basis in the ontick but I am having no luck.

            1 Reply Last reply Reply Quote 0
            • M Offline
              Mr.K.1
              last edited by 20 Feb 2011, 14:33

              I made a quick example model for you, only requires a test file on your C disk. C://test.txt
              And then write in any 3 numbers, like so: 13, 17, 165 (only an example, they can be anything)

              Those will convert into a color value as RGB(only ranges from 0 to 255), and velocity vector, and a torque vector, and a teleport position(added them all so you have the full range of uses)

              Code it fairly crude but it works.
              onstart{ @timer = UI.start_timer(2, true){ @color=Object::IO.read("C://test.txt").chomp.split(',') output=[@color[0].to_i, @color[1].to_i, @color[2].to_i] group.material=output #sets color as RGB setVelocity(output) #sets body velocity setTorque(output) #sets body torque teleport(output) #sets teleport point } } onend{ UI.stop_timer(@timer) }


              filedata_to_SP.skp

              1 Reply Last reply Reply Quote 0
              • M Offline
                mptak
                last edited by 20 Feb 2011, 15:12

                You may be Mr. K....but you are Mr. OK by me. Hope I can pay it forward in the future. The power of this to generate multiple input into a model is mindboggling. A K of thanks.

                1 Reply Last reply Reply Quote 0
                • M Offline
                  Mr.K.1
                  last edited by 20 Feb 2011, 17:13

                  Could you share what you are using this for?

                  I tried to come op with some good uses but nothing really comes to mind.

                  1 Reply Last reply Reply Quote 0
                  • M Offline
                    mptak
                    last edited by 20 Feb 2011, 17:20

                    I'm not really sure but I think it is for multiperson input into a simple model...for which my wife says we have Second Life. For me, who has been highly involved in K-12 and Technical College Education...I see it as a way of sucking a group of people into a multi-person environment which has controls (Ruby) that they can fathom. It relies I would say on their all having access to the same part of the cloud but I presume that leaping to the lat long generated by their phones is not too far....(google docs I presume).

                    If you want something more solid I guess it would be taking output from PLC or other emulator programs before actually making the hard connect to the machine. I will post a badly programmed model the first chance I get. For now I have 15 students and they each will get a box that they can make giggle and change color when it it their turn to tell me what happens when they transform a shape by e^(ipi).

                    Any other uses ideas...particularly with how to poll off the web...would be greatly appreciated.

                    1 Reply Last reply Reply Quote 0
                    • M Offline
                      Mr.K.1
                      last edited by 20 Feb 2011, 18:45

                      I see...

                      Well for internet data transfer you can do it several ways, easiest being opening up the web-dialog and reading data from that, the interactivity is a bit limited but it has all sorts of uses .
                      I used it for automated plug-in updating, so when I upload a new script the plugin on users end can update itself without file transfer.

                      Another way is direct UDP/TCP connection, if you add another file to SU then Ruby can connect to other people directly.
                      I used this for a small multiplayer game experiment, and it works quite well, tho setting up p2p connections it not without it's faults.
                      But a friend is doing an upgraded version with a user database where people log-in, chat, multiplayer game lobbies/lists/scores, that may take a while tho.

                      There was also quite some talk of interactive modeling, but the biggest problem is Ruby still hasn't got the full access to SU, so the synchronizing would probably haveto rebuild the full geometry on the other end(not an ideal solution with bigger models).

                      1 Reply Last reply Reply Quote 0
                      • 1 / 1
                      1 / 1
                      • First post
                        1/10
                        Last post
                      Buy SketchPlus
                      Buy SUbD
                      Buy WrapR
                      Buy eBook
                      Buy Modelur
                      Buy Vertex Tools
                      Buy SketchCuisine
                      Buy FormFonts

                      Advertisement