SL32_INTEngine.spin HELP!
mhamen3
Posts: 69
Hi guys,
I'm pretty new to the forums, very new to SPIN. I'm trying to use the SL32_INTEngine.spin object but I don't seem to be using it right. What I'm trying to do is run two servos through a 140 degree (servo travel) sinusoidal sweep, 90 degrees out of phase of each other. It's probably my code, which I'll post below, but I also don't totally understand the operations of the object.
Does it only work from 0 to 90deg? Do I have to mirror or reverse it myself?
If it does work through 360deg will it also work past that? e.g. can I put 390deg in and get the same results as 30deg?
Anyway, here is the code. I'm at work so I can't just post the file but it's short anyway.
I'm pretty new to the forums, very new to SPIN. I'm trying to use the SL32_INTEngine.spin object but I don't seem to be using it right. What I'm trying to do is run two servos through a 140 degree (servo travel) sinusoidal sweep, 90 degrees out of phase of each other. It's probably my code, which I'll post below, but I also don't totally understand the operations of the object.
Does it only work from 0 to 90deg? Do I have to mirror or reverse it myself?
If it does work through 360deg will it also work past that? e.g. can I put 390deg in and get the same results as 30deg?
Anyway, here is the code. I'm at work so I can't just post the file but it's short anyway.
CON _CLKMODE=XTAL1 + PLL16X _CLKFREQ=5_000_000 ServoMin=700 'Used for servo control, won't allow PWM signal to go below 700 ServoCh1 = 1 ServoCh2 = 2 OBJ SERVO : "Servo32v7.spin" TRIG : "SL32_INTEngine.spin" VAR long Angle long PosA long PosB PUB main SERVO.start SERVO.ramp SERVO.set(ServoCh1,1500) SERVO.set(ServoCh2,1500) Angle := 1 ' Set initial condition (necessary?) repeat PosA := TRIG.sin(Angle,1)*1400+ServoMin 'Scales sweep of 1400 by sin value and adds it to servo minimum PosB := TRIG.cos(Angle,1)*1400+ServoMin SERVO.set(ServoCh1, PosA) SERVO.set(ServoCh2, PosB) waitcnt(1_400_000 + cnt) 'waits about 1/60th of a sec to allow movement Angle := Angle + 1 ' adds 1 degree for next iteration IF Angle==361 Angle := 1 'ResetIf anyone could help me out with this I would much appreciate it
Comments
Let's go back to Trig. So remember the unit circle? And how all sin and cos calculations were done using the unit circle? Well... since we are using integers and not floats we can't use the unit circle due to having numbers less than one on it. But, if we were to scale the unit circle up then we could then use it.
That's what the second argument of the function call is. Just think about trig a bit when using the library and everything will make sense. All the functions work using triagles and then calculating the COS and SIN argument from them. Just pull the wikipedia page up and you should be good.
Thanks a lot, Kye.