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

    Servo control

    Scheduled Pinned Locked Moved SketchyPhysics
    11 Posts 3 Posters 1.4k Views 3 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.
    • ashscottA Offline
      ashscott
      last edited by

      Hi guys, I've had a look round the forum but I struggle to understand anything on this subject, although I'm sure its simple.

      What I'm trying to do is get a servo to rotate 120degrees then stop. Then rotate another 120 degrees when I hit the key again. I've got it rotating 120 but it returns on release of the key. What sort of script do I put in the control box to do what I'm talking about?

      Just some stuff I do with Sketchup.

      1 Reply Last reply Reply Quote 0
      • P Offline
        phy
        last edited by

        try this

        if key('space')==1; setVar('servo',getVar('servo')+1);end
        

        put it on the servo's controller or else in ontick with the servo's controller getVar('servo')

        Tableau de comparaison de Staxyn s'agit d'un mГ©dicament uniquement sur ordonnance.

        1 Reply Last reply Reply Quote 0
        • ashscottA Offline
          ashscott
          last edited by

          wow, cool thanks for that. What do I need to add to that to get it to repeat the action; It does the 120 degree motion but no response on the second click....is it possible to get an additional response on the second click??

          Just some stuff I do with Sketchup.

          1 Reply Last reply Reply Quote 0
          • P Offline
            phy
            last edited by

            well is supposed to respond on the second click I'm not sure why it wouldn't try it again

            Tableau de comparaison de Staxyn s'agit d'un mГ©dicament uniquement sur ordonnance.

            1 Reply Last reply Reply Quote 0
            • W Offline
              Wacov
              last edited by

              You want to toggle it? I have just the thing 😄

              if frame==1;setVar("repeat",0);setVar("toggle",0);end;if key("space")==0;setVar("repeat",1);getVar("toggle");elsif getVar("repeat")==0;getVar("toggle");elsif getVar("toggle")==0;setVar("repeat",0);getSetVar("toggle",1);else;setVar("repeat",0);getSetVar("toggle",0);end;
              

              Change key("space") to whatever, and it's ready-to-go. And don't worry, I didn't write it just for you, it's an old one of mine 😄

              http://sketchup.google.com/3dwarehouse/cldetails?mid=3096a836877fb9af6cd8ad826e9017b8&prevstart=0

              1 Reply Last reply Reply Quote 0
              • ashscottA Offline
                ashscott
                last edited by

                I know basically nothing about code so am assuming I just cut and paste these chunks of code separately into the control box of the servo?
                When I do this, your code phy increases the speed of the servo which spins continuously, and your code wacov turns the servo for one increment but on the second click it returns to the original position...what am I doing wrong guys?

                Just some stuff I do with Sketchup.

                1 Reply Last reply Reply Quote 0
                • W Offline
                  Wacov
                  last edited by

                  Lol, sorry, I read your post wrong 😳

                  Okay, with a slight change to the toggle script, you have the desired result (well, kinda):

                  if frame==1;setVar("repeat",0);setVar("toggle",0);end;if key("space")==0;setVar("repeat",1);getVar("toggle");elsif getVar("repeat")==0;getVar("toggle");else; setVar("toggle",getVar("toggle")+1);end
                  

                  http://sketchup.google.com/3dwarehouse/cldetails?mid=3096a836877fb9af6cd8ad826e9017b8&prevstart=0

                  1 Reply Last reply Reply Quote 0
                  • ashscottA Offline
                    ashscott
                    last edited by

                    I'm sorry that I have such an elementary understanding, but this new code seems to spin the servo faster and faster like phy's one. Does the '+1 add an increment of speed? I can't seem to figure it out. How would I change the first script you sent me Wacov to repeat itself each time the key is pushed?

                    Just some stuff I do with Sketchup.

                    1 Reply Last reply Reply Quote 0
                    • W Offline
                      Wacov
                      last edited by

                      The whole spinning thing is an unfortunate problem with servos, and happens whenever they exceed 360 degrees. My second script adds 1 to the servo's controller when space is pressed, but once the servo goes over 360, it'll always spin out.

                      http://sketchup.google.com/3dwarehouse/cldetails?mid=3096a836877fb9af6cd8ad826e9017b8&prevstart=0

                      1 Reply Last reply Reply Quote 0
                      • ashscottA Offline
                        ashscott
                        last edited by

                        Ok, that explains a lot. Thanks very much. Ill just try those scripts on a hinge...

                        Just some stuff I do with Sketchup.

                        1 Reply Last reply Reply Quote 0
                        • ashscottA Offline
                          ashscott
                          last edited by

                          These scripts both seem to toggle back and forth for me....Have I done something wrong? Also, what would I add to the last script to allow a second key to control the opposite direction of rotation; ie a +/- key

                          Just some stuff I do with Sketchup.

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

                          Advertisement