Page 1 of 1

C# coding for 1061 AdvancedServo Controller

Posted: Tue Mar 08, 2016 10:38 am
by Audaray
Hello everyone :)

I wonder if you can help.
I am creating a pan and tilt system. I have 2 Hitec 322HD servos attached to a 1061_0 Servo Controller, in a pan and tilt mount with a webcam on top. I am using a Tobii EyeX to control them using UI buttons in Unity; if you look at the 'look right' button, the servo setup with camera on top should pan right, etc. What I can't get to work, however, is only one servo will activate - I can't seem to open 2 simultaneously. Here is a snippet of my code :

Code: Select all

public class AngleController : MonoBehaviour {

   double pos;
   public float increment;

   AdvancedServo panServo = new AdvancedServo();
   AdvancedServo tiltServo = new AdvancedServo();

   public    GazeAwareComponent LookRight; //Declared eyex components
   public  GazeAwareComponent LookLeft;

   public    GazeAwareComponent LookUp;
   public  GazeAwareComponent LookDown;

   void Start () {

      panServo.Attach += new AttachEventHandler (panServo_Attach); //

      tiltServo.Attach += new AttachEventHandler (tiltServo_Attach); //

   .... //I removed the event handler section here to shorten my post. There are positionchange, attach, detach and error handlers.

      pos = 30.00; (); ();

      panServo.waitForAttachment (1000);
      tiltServo.waitForAttachment (1500);

      panServo.servos [0].Engaged = true;
      tiltServo.servos [4].Engaged = true;

      if (panServo.Attached && tiltServo.Attached) {
         panServo.servos [0].Position = pos;
         tiltServo.servos [4].Position = pos;
         Debug.Log ("Started");

If I change the order of; and; , then tilt servo will activate, and pan servo will not. The opposite is true when panServo comes first. I don't know how to solve this issue - if anyone could help me with where I've gone wrong, I'd be very grateful!



Re: C# coding for 1061 AdvancedServo Controller

Posted: Tue Mar 08, 2016 1:15 pm
by mparadis
Since both motors are connected to one controller, you only need one AdvancedServo object. Open just one, and then set the position of servos[0] and servos[4] of that same object.