Servo Starting Angle
-
Although this is a general question it's causing me problems with the simulation of a JCB digger. File attached.
I'm using servos on the digger arms but as, when the simulation starts, the servo angle is taken as zero any subsequent movement is taken from that start position. So if the arm starts off in the incorrect position after the last simulation the digger arm can crash into other components.
I need to be able to know the starting position of the servo or, more likely, of the digger arm. Any ideas.
Note - the attached file uses a joystick as the control device - see the script to understand.
Postscript (Added later) I should have explained that this is using MSPhysics. It works with the version of Sketchup Make 2017 I am using and is the latest version of MSPhysics - 1.0.3.
-
You might call it general, but it is a very specific subject.
You need to tell us what you are using for the animation.
Is it Sketchy physics that works with the rather old version 2016 that you seem to have or is it Msphysics that works with the newer versions, but not with the latest if I remember correctly. -
For completeness I can report that I have managed to fix this problem myself, albeit in a rather "brute force" way - so if there's a simpler solution I'd be very interested.
Rather than try to measure the property of the servo itself, I obtained the position of the objects it was ultimately linked to using script such as the following for each object -
@@pos_mainarm_cylinder = this.get_position(1)
@@pos_mainarm_ram = this.get_position(1)Then by computing the distance between the two objects I was able to limit the movement of the servo so as to remain within the correct range.
dist = distance(@@pos_mainarm_cylinder, @@pos_mainarm_ram)
joy = joystick(:lefty)
if ( dist > 1.000 && joy < 0 ) || ( dist < 0.380 && joy >0 ) || (dist < 1.000 && dist > 0.380)
@_mainarm = @_mainarm - joy
endThe limits of 1.00 and 0.38 were from the known dimensions of the objects. The local variable @_mainarm was then used to control the servo. The distance function uses Pythagoras's theory to calculate the distance between the middle of each object.
As I say - any simpler ideas? Nonetheless it now works as intended irrespective of the starting position of the servos.
Advertisement