Servo control
-
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?
-
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')
-
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??
-
well is supposed to respond on the second click I'm not sure why it wouldn't try it again
-
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
-
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? -
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
-
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?
-
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.
-
Ok, that explains a lot. Thanks very much. Ill just try those scripts on a hinge...
-
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
Advertisement