コード例 #1
0
    private static string UID = "XXYYZZ"; // Change XXYYZZ to the UID of your Servo Brick

    #endregion Fields

    #region Methods

    static void Main()
    {
        IPConnection ipcon = new IPConnection(); // Create IP connection
        BrickServo servo = new BrickServo(UID, ipcon); // Create device object

        ipcon.Connect(HOST, PORT); // Connect to brickd
        // Don't use device before ipcon is connected

        // Register position reached callback to function PositionReachedCB
        servo.PositionReached += PositionReachedCB;

        // Enable position reached callback
        servo.EnablePositionReachedCallback();

        // Set velocity to 100°/s. This has to be smaller or equal to the
        // maximum velocity of the servo you are using, otherwise the position
        // reached callback will be called too early
        servo.SetVelocity(0, 10000);
        servo.SetPosition(0, 9000);
        servo.Enable(0);

        Console.WriteLine("Press enter to exit");
        Console.ReadLine();
        servo.Disable(0);
        ipcon.Disconnect();
    }
コード例 #2
0
 private void SetMotorConfiguration(byte motorID, MotorConfiguration mc)
 {
     if (GetMotorIDs().Contains(motorID))
     {
         servo.SetDegree(motorID, mc.GetShortValue("Degree_Min"), mc.GetShortValue("Degree_Max"));
         servo.SetPulseWidth(motorID, mc.GetIntValue("PulseWidth_Min"), mc.GetIntValue("PulseWidth_Max"));
         servo.SetPeriod(motorID, mc.GetIntValue("Period"));
         servo.SetAcceleration(motorID, mc.GetIntValue("Acceleration"));
         servo.SetVelocity(motorID, mc.GetIntValue("Velocity"));
         servo.SetPosition(motorID, mc.GetShortValue("Position"));
         servo.Enable(motorID);
     }
     else
     {
         throw new Exception("Unkown motorID in SetMotorConfiguration: " + motorID);
     }
 }
コード例 #3
0
 // Callback function for distance callback (parameter has unit mm)
 static void ReachedCB(BrickServo sender, byte servoNum, short position)
 {
     if(position == 9000)
     {
         System.Console.WriteLine("Position: 90°, going to -90°");
         sender.SetPosition(servoNum, -9000);
     }
     else if(position == -9000)
     {
         System.Console.WriteLine("Position: -90°, going to 90°");
         sender.SetPosition(servoNum, 9000);
     }
     else
     {
         // Can only happen if another program sets position
         System.Console.WriteLine("Error");
     }
 }
コード例 #4
0
    private static string UID = "XXYYZZ"; // Change XXYYZZ to the UID of your Servo Brick

    #endregion Fields

    #region Methods

    static void Main()
    {
        IPConnection ipcon = new IPConnection(); // Create IP connection
        BrickServo servo = new BrickServo(UID, ipcon); // Create device object

        ipcon.Connect(HOST, PORT); // Connect to brickd
        // Don't use device before ipcon is connected

        // Configure two servos with voltage 5.5V
        // Servo 1: Connected to port 0, period of 19.5ms, pulse width of 1 to 2ms
        //          and operating angle -100 to 100°
        //
        // Servo 2: Connected to port 5, period of 20ms, pulse width of 0.95
        //          to 1.95ms and operating angle -90 to 90°
        servo.SetOutputVoltage(5500);

        servo.SetDegree(0, -10000, 10000);
        servo.SetPulseWidth(0, 1000, 2000);
        servo.SetPeriod(0, 19500);
        servo.SetAcceleration(0, 1000); // Slow acceleration
        servo.SetVelocity(0, 65535); // Full speed

        servo.SetDegree(5, -9000, 9000);
        servo.SetPulseWidth(5, 950, 1950);
        servo.SetPeriod(5, 20000);
        servo.SetAcceleration(5, 65535); // Full acceleration
        servo.SetVelocity(5, 65535); // Full speed

        servo.SetPosition(0, 10000); // Set to most right position
        servo.Enable(0);

        servo.SetPosition(5, -9000); // Set to most left position
        servo.Enable(5);

        Console.WriteLine("Press enter to exit");
        Console.ReadLine();
        servo.Disable(0);
        servo.Disable(5);
        ipcon.Disconnect();
    }
コード例 #5
0
    private static string UID = "a4LCMm3K2bS"; // Change to your UID

    #endregion Fields

    #region Methods

    static void Main()
    {
        IPConnection ipcon = new IPConnection(); // Create IP connection
        BrickServo servo = new BrickServo(UID, ipcon); // Create device object

        ipcon.Connect(HOST, PORT); // Connect to brickd
        // Don't use device before ipcon is connected

        // Register "position reached callback" to ReachedCB
        // ReachedCB will be called every time a position set with
        // SetPosition is reached
        servo.PositionReached += ReachedCB;

        // Set velocity to 100°/s. This has to be smaller or equal to
        // maximum velocity of the servo, otherwise ReachedCB will be
        // called too early
        servo.SetVelocity(0, 10000);
        servo.SetPosition(0, 9000);
        servo.Enable(0);

        System.Console.WriteLine("Press key to exit");
        System.Console.ReadKey();
        ipcon.Disconnect();
    }