sketchucation logo sketchucation
    • Login
    1. Home
    2. Bas9999
    3. Posts
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info
    B
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 3
    • Posts 20
    • Groups 1

    Posts

    Recent Best Controversial
    • RE: MSPhysics 1.0.3 (16 October 2017)

      Well i have found earlier versions around on the internet and i am confused with the version numbering because it already passed v1.0.0 @ 2014-09-01..... πŸ˜‰

      MSPhysics - v0.1.0 (2014-04-26)
      MSPhysics - v0.2.0 (2014-06-26)
      MSPhysics - v0.2.0 (2015-04-06) ???
      MSPhysics - v1.0.0 (2014-09-01)

      posted in Plugins
      B
      Bas9999
    • RE: Write to serial port with Ruby [SOLVED!]

      Hi Anton_S

      *EDIT SOLVED!!! SEE BELOW

      Could you assist on this one?

      When for example i use a diffrent baudrate (on purpose) i still get this error:
      sp su15 serial recieve error baudrate.png

      The original code was:

      ontick{
        MSketchyPhysics3.closeControlPanel if frame == 1
        string_size = 1024
        $serialdata = eval(@serial.read(string_size))
      }
      

      I changed it to this, but that doesn't work:

      ontick{
        MSketchyPhysics3.closeControlPanel if frame == 1
        string_size = 1024
      
        begin
          $serialdata = eval(@serial.read(string_size))
        rescue RubySerial;;Exception => e
          @serial.close if @serial
          MSketchyPhysics3;;SketchyPhysicsClient.physicsReset
          UI.messagebox("ERROR!")
        end
      }
      

      How to catch this error?

      *EDIT SOLVED!!!
      I just changed the line to:

      $serialdata = @serial.read(string_size)
      

      so it's only:

      ontick{
        MSketchyPhysics3.closeControlPanel if frame == 1
        $serialdata = eval(@serial.read(1024))
      }
      
      posted in SketchyPhysics
      B
      Bas9999
    • RE: Stop simulation immediatly / End script!

      Hi Anton_S

      Thank you, so this is the piece of code i have now... wich includes a messagebox to ask the COM port and exit if CANCEL is pressed.

      The code is lumped together with some examples found here and there, so if there are any tweaks let me know!

      sp su15 serial recieve example.png

      # DomoticX Virtual 3D Device Port SU15 interface.
      
      # Wat moet er gebeuren bij het starten van de simulatie?
      onstart{
        options = ["Serial Port;", "Baudrate;"]
        default = ["COM8", "9600"]
        list = ["", "4800|9600|14400|19200|28800|38400|57600|115200"]
        serialsettings = UI.inputbox(options, default, list, "Serial port settings;")
      
        if serialsettings != FALSE
          $comport = serialsettings[0]
          $baudrate = serialsettings[1].to_i
      
          begin
            @serial = Serial.new($comport, $baudrate)
          rescue RubySerial;;Exception => e
            @serial.close if @serial
            MSketchyPhysics3;;SketchyPhysicsClient.physicsReset
            UI.messagebox("Serial port not found!")
          end
        else
          MSketchyPhysics3;;SketchyPhysicsClient.physicsReset
        end
      }
      
      # Wat moet er gebeuren tijdens de simulatie?
      ontick{
        MSketchyPhysics3.closeControlPanel if frame == 1
      
        string_size = 1024
        $serialdata = eval(@serial.read(string_size))
      
        logLine("COM poort; " + $comport.to_s)
        logLine("BAUD rate; " + $baudrate.to_s)
        logLine("Seriele data; " + $serialdata.to_s)
        logLine("")
        logLine("")
        logLine("")
        logLine("")
        logLine("")
      }
      
      # Wat moet er gebeuren als de de simulatie stopt?
      onend{
        # Sluit de seriele poort als deze open staat.
        @serial.close if @serial
      }
      

      Ps. The simulation works fine... but sometimes when i STOP and START the simulation again i get this error, when i start it for the second time it works perfectly again, any ideas to prevent this?

      sp su15 serial recieve error.png

      posted in SketchyPhysics
      B
      Bas9999
    • RE: SketchyPhysics 3.5.6 (26 January 2015)

      Ahem...

      Should "SketchyPhysics 3.5.6 (January 26, 2014)"
      not be "SketchyPhysics 3.5.6 (January 26, 2015)"?

      πŸ˜’

      posted in SketchyPhysics
      B
      Bas9999
    • Stop simulation immediatly / End script!

      I wanted to implement a better error handler for the script here: http://sketchucation.com/forums/viewtopic.php?f=61%26amp;t=61033

      What i did was to bring up the error on purpose, to let SketchyPhysics open a COM port that does not exist with

      @serial = Serial.new('COM7', 9600)
      

      Gives:
      sketchyphysics COM port - file not found error.png

      Hey look... it sees the COM port as a file...NEAT!, so i looked up some code, where you can check if a file exists:

      File.exist?('file.ext')
      

      Gives Boolean True or False as return

      So, a COM port can also be checked if it exists with:

      File.exist?('COM7')
      

      So i put this line together:

      @serial = Serial.new('COM7', 9600) if File.exist?('COM7')
      

      Now...when runing the simulation and the COM port is not found the simulation just starts and gives the error:
      sketchyphysics COM port - file not found error 02.png

      Ok, so we need to STOP the script immediatly, so i looked up how to stop a script from another example, i came up with this line:

      MSketchyPhysics3;;SketchyPhysicsClient.physicsReset
      

      Now putting it all together and include a nice messagebox, this is the part i have now:

      onstart{
        if File.exist?('COM7')
          @serial = Serial.new('COM7', 9600)
        else
          UI.messagebox('Serial Port not found!')
          MSketchyPhysics3;;SketchyPhysicsClient.physicsReset
        end
      }
      

      But what happens now is, that we get the message the COM port is not found that is ok, but right after that, another error pops up, SketchyPychics still executes the function: ONEND!!

      onend{
        @serial.close
      }
      

      sketchyphysics COM port - file not found error 03.png

      So my question is: How to abort the script/simulation immediatly?

      *EDIT

      I could do this:

      onend{
        @serial.close if File.exist?('COM7')
      }
      

      but's not charming to implement the check everytime...

      posted in SketchyPhysics
      B
      Bas9999
    • RE: Disable control panel popup

      @anton_s said:

      Although it still has to be in onUpdate or onTick event.
      So your one liner would look like this:
      onUpdate { MSketchyPhysics3.closeControlPanel if frame == 1 }

      πŸ‘ 🀣

      posted in SketchyPhysics
      B
      Bas9999
    • RE: Write to serial port with Ruby [SOLVED!]

      Hi All,

      This is an example how to SEND data to the Arduino with SU 14/15, SketchyPhysics and Ruby Serial

      First the Arduino programming, here is the code to lit the integrated LED on digital 13, when there is a serial "1" recieved, the LED goes out when there is a "0" recieved.

      Arduino code:

      String readString;
      
      void setup() {
        pinMode(13, OUTPUT);
        Serial.begin(9600);
      }
       
      void loop() {
        while (Serial.available()) {
          delay(3);
          if (Serial.available() >0) {
            char c = Serial.read();
            readString += c;
          } 
        }
       
        if (readString.length() >0) {
          if (readString == "1") { digitalWrite(13, HIGH); }
          if (readString == "0") { digitalWrite(13, LOW); }
          readString = "";
        } 
      }
      

      Now...once programmed, create a sketchyphysics solid and paste this code in it:

      onstart{
        @serial = Serial.new('COM8', 9600)
      }
      
      onclick{
        @m = Sketchup.active_model.materials.add "My material"
        group.material = @m
        @m.color="Yellow"
      
        logLine("LED ON!")
        @serial.write('1')
      }
      
      onunclick{
        @m = Sketchup.active_model.materials.add "My material"
        group.material = @m
        @m.color="White"
      
        logLine("LED OFF!")
        @serial.write('0')
      }
      
      ontick{
        MSketchyPhysics3.closeControlPanel if frame == 1
      }
      
      onend{
        @serial.close
      }
      

      How does this work?
      When you run the script and click on the solid, the color will change to yellow and over the serial port a "1" will be send, de Arduino will recieve this "1" and will put on the LED light, when you release the mouse button, the model changes color back to white and a "0" will be sent, the Arduino recieves this and will put the LED light out!

      Have fun!

      Ps. Is there any code to read out a textbox or something (userinput possible?), where the user can specify the COMPORT and BAUDRATE?

      SU_14_15_Ruby Serial Sketchup Sketchyphysics screen.jpg

      I think i will start to create the 204/2015 walktrough soon!, this will be the banner for the
      projects:
      SketchyPhysics serial banner.jpg


      SU_14_15 - Ruby Serial SEND Example with Sketchup Sketchyphysics.skp

      posted in SketchyPhysics
      B
      Bas9999
    • RE: Write to serial port with Ruby [SOLVED!]

      @mptak said:

      I see you tested it with SU2015...this confuses me. Were you using the 64 bit version of sketchup? Which Sketchy Physics download did you use? Thanks.

      No, i used the 32-bit version of SU2015, sketchyphysics does not work on 64-bit (yet)

      posted in SketchyPhysics
      B
      Bas9999
    • RE: Write to serial port with Ruby [SOLVED!]

      Hello Anton_S

      I've tested it with Sketchup 2015... 😍 , it works like a charm!

      This is the code to read data for the serial port so far...

      onstart{
        @serial = Serial.new('COM8', 9600)
      }
       
      ontick{
        MSketchyPhysics3.closeControlPanel if frame == 1
        $serialdata = eval(@serial.read(1024))
        logLine("Serial data; " + $serialdata.to_s)
        logLine("")
        logLine("")
        logLine("")
        logLine("")
        logLine("")
        logLine("")
      }
      
      onend{
        @serial.close
      }
      

      Thank you!, i see if i can make a script that SENDS data to the Arduino / Raspberry...

      posted in SketchyPhysics
      B
      Bas9999
    • RE: Disable control panel popup

      Or just 1 line πŸ˜‰

      MSketchyPhysics3.closeControlPanel if frame == 1
      
      posted in SketchyPhysics
      B
      Bas9999
    • RE: Write to serial port with Ruby [SOLVED!]

      Hi Anton_S & driven,

      Wow, i really hope you can make this work!, so that we can use the new SU version to communicate with a serial port, we can make lots of cool things with Arduino & Raspberry.

      If i need to test something, let me know!

      Thanks in forward!

      posted in SketchyPhysics
      B
      Bas9999
    • RE: Read out hinge/servo value [SOLVED!]

      Thank you Anton_S!

      @All,
      Watch the YouTube movie where i used these scripts in action:

      SCRIPTS & TUTORIALS @ DomoticX.com
      Look for: "Virtual 3D Device Port"

      Virtual-3D-Device-port-SU08-logo.jpg

      The tutorial pages are written in our main language: DUTCH
      Use google translate to translate the pages for you!

      (note: copy & paste scripts from the original untranslated site)

      posted in SketchyPhysics
      B
      Bas9999
    • RE: Read out hinge/servo value [SOLVED!]

      Hi Anton_S,

      Thank you!

      Ps. the first script for the "hinge", is that also a copy & paste script for every component?, if not... could you adjust it that way?

      Thanks in forward!

      posted in SketchyPhysics
      B
      Bas9999
    • RE: Read out hinge/servo value [SOLVED!]

      Hello anton_S,

      Again, thank you for the example code!, i see it's a lot for a NON Sketchup/Ruby expert like me πŸ˜„

      I needed this for a virtual "RGB LED controller" that controls a LED trough the Arduino, so i made some adds & adjustements to your code.

      Ps. why does the value start at 0.06 and ends with 1.07?, i did a correction of -0.6 but then i still come out on 1.01 πŸ˜’

      My additions to store the 3 RGB values per slider:

      RED:

      onupdate {
          ratio = ratio - 0.06
          ratio = 1.00 if ratio > 1.00
          $sliderr = sprintf("%.2f", ratio)
      }
      

      GREEN:

      onupdate {
          ratio = ratio - 0.06
          ratio = 1.00 if ratio > 1.00
          $sliderg = sprintf("%.2f", ratio)
      }
      
      

      BLUE:

      onupdate {
          ratio = ratio - 0.06
          ratio = 1.00 if ratio > 1.00
          $sliderb = sprintf("%.2f", ratio)
      }
      

      On the "baseplate" this code in the "scripted" section to display the values on the left side:

      onUpdate {
      logLine("Waarde rood; " + $sliderr.to_s)
      logLine("Waarde groen; " + $sliderg.to_s)
      logLine("Waarde blauw; " + $sliderb.to_s)
      logLine("")
      logLine("")
      logLine("")
      logLine("")
      logLine("")
      }
      

      Here is a screen of the project:
      SketchUp SketchPhysics - RGB control 02.png


      SketchUp SketchPhysics - RGB control.skp

      posted in SketchyPhysics
      B
      Bas9999
    • RE: Read out hinge/servo value [SOLVED!]

      Hello Anton_S,

      Can the same be done with a slider?, could you provide an example?

      Thanks!


      slider_su8.skp

      posted in SketchyPhysics
      B
      Bas9999
    • Write to serial port with Ruby [SOLVED!]

      Hi all,

      I've made some projects to control 3D objects with an Arduino with connected hardware, like potentiometers and gyroscopes (making mini games πŸ˜‰ ), just trough the serial interface.

      Therefore i am using:

      • SketchUp 8
      • Sketchup 8 plugin - SketchyPhysics v3.5.6
      • Sketchup 8 plugin - Supy v1.6 for Python v2.5
      • Python 2.5
      • Python 2.5 library – PySerial v2.5

      But... does SuPy v1.6 work in SU2014 / SU2015?
      I know there are Ruby changes with the 2.x version that break scripts, but this was from SU2014 to SU 2015 right?

      In SketchUp 8 you just could do:

      onstart{
        Py.exec("import serial")
        Py.exec("ser = serial.Serial('COM8', 9600)")
      }
       
      ontick{
        Py.exec("serialdata = ser.readline()")
        $serialdata = Py.eval("serialdata")
      }
       
      onend{
        Py.exec("ser.close()")
      }
      

      And in the controller box you could put:

      $serialdata.to_f
      

      So...i was wondering if there is any Ruby GEM needed to make serial things happen?, and wat would be a sample code?

      Please let me know!

      posted in SketchyPhysics
      B
      Bas9999
    • RE: Read out hinge/servo value [SOLVED!]

      Hmmmm, seems the ROUND function is not doing well in SU8 πŸ˜’

      Sketchup8_round_error.png

      After some research i made this code for SU8, using SPRINTF:

      anglefloat = @angle.radians.round.to_f
      puts sprintf "%.2f", (((0.5 / 90) * anglefloat) + 0.5) if anglefloat > 0
      puts sprintf "%.2f", (((-0.5 / 90) * anglefloat) - 0.5).abs if anglefloat < 0
      

      That seems to do the trick...


      lever_angle2_SU8.skp

      posted in SketchyPhysics
      B
      Bas9999
    • RE: Read out hinge/servo value [SOLVED!]

      Ok, i got it working to make a value from 0.00 to 1.00 from the degree number in the sketch above.

      Since i am new to ruby i had todo some reseach but made it, if you have any improvements...let me know!

      in section "onUpdate" add this at the end:

      anglefloat = @angle.radians.round.to_f
      puts (((0.5 / 90) * anglefloat) + 0.5).round(2) if anglefloat > 0
      puts (((-0.5 / 90) * anglefloat) - 0.5).abs.round(2) if anglefloat < 0
      

      Open the RUBY CONSOLE there you can see the values:

      0.54
      0.53
      0.53
      0.53
      0.52
      0.51
      0.51
      0.49
      0.49
      0.48
      0.48
      0.47
      0.46
      0.46
      0.45
      0.44
      0.43
      0.43
      0.42
      0.41
      0.41
      0.4
      0.39
      

      lever_angle2.skp

      posted in SketchyPhysics
      B
      Bas9999
    • RE: Read out hinge/servo value [SOLVED!]

      Hi Anton_S,

      Thank you for the example, i am going to study it a bit!

      First i have to make the degrees to a value 0.00 (MIN) and 1.00 (MAX) (optional, but handy)

      My goal is to put an Arduino behind the sketch, so that virtual pulled elements are also moving in the 'real' world, like a servo, i will put my project on the forum when it's finished πŸ˜‰

      Best Regards,
      Bas

      posted in SketchyPhysics
      B
      Bas9999
    • Read out hinge/servo value [SOLVED!]

      Hi All,

      I've been struggling for days now how to make this work... is there any change about reading the value 0.0 / 1.0 from a hinge/servo?

      Say you have a hinge with a 'lever' attatched to it, with

      MIN: -90
      MAX: 90

      Now when i pull the 'lever' (that is attatched to the hinge) with the mouse, i want to readout the hinge value 0.0 (-90 degrees) --- 1.0 (90 degrees)

      From my understanding and experimenting, everything i put in the 'controller' box of the hinge makes it stop working to manually control it...

      All i can do is fiddle with position().x or position().y in the 'lever' scripting...and some mathmathics...but but that should not be needed i guess...

      Could you help me out?

      posted in SketchyPhysics
      B
      Bas9999
    • 1 / 1