C# coding for 1061 AdvancedServo Controller

Supporting Visual Studio on Windows
Fresh meat
Posts: 1
Joined: Tue Mar 08, 2016 10:23 am

C# coding for 1061 AdvancedServo Controller

Postby Audaray » Tue Mar 08, 2016 10:38 am

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.open ();
      tiltServo.open ();

      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 panServo.open(); and tiltServo.open(); , 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!



User avatar
Site Admin
Posts: 626
Joined: Fri Oct 28, 2011 12:17 pm

Re: C# coding for 1061 AdvancedServo Controller

Postby mparadis » Tue Mar 08, 2016 1:15 pm

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.

Return to “C#.NET”

Who is online

Users browsing this forum: wuhuilin11 and 1 guest