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(); }
public SimpleServoEngine(BrickServo servoBrick, byte servoId) { ServoBrick = servoBrick; ServoId = servoId; IsEnabled = false; InitializePropertyDefaults(); SetSpeed(0); }
public RadialDistanceSensor(RadialDistanceMap targetMap, BrickServo servoBrick, byte servoId, IDistanceSensor distanceBricklet) { Measurements = targetMap; ServoId = servoId; ServoBrick = servoBrick; DistanceSensor = distanceBricklet; SetupMeasurement(); SetupServo(); }
private void InitializeDevices() { Connection = new IPConnection(); Connection.Connect("localhost", 4223); ServoBrick = new BrickServo("ap6zRki6edN", Connection); SetupServoBrick(); DistanceBricklet = new BrickletDistanceIR("8XU", Connection); var distanceCollection = new ClosestDistanceSensorCollection(); distanceCollection.AddSensor(new ImmediateDistanceIRSensor(DistanceBricklet)); Distances = distanceCollection; var drivingStrategy = new SimpleDistanceDrivingStrategy(Engine, Distances); drivingStrategy.MinimumDrivingDistance = 30.Centimeters(); drivingStrategy.ReversalDistance = 11.Centimeters(); drivingStrategy.RefreshInterval = 10; this.DrivingStrategy = drivingStrategy; }
// 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"); } }
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(); }
public TFRoboticArmWith6DOF() { // Connection to brickd ipcon = new IPConnection(); servo = new BrickServo(UID, ipcon); ipcon.Connect(HOST, PORT); servo.SetOutputVoltage(5000); // 5V MotorConfiguration mcServoTypeA = new MotorConfiguration(); mcServoTypeA.SetValue("Degree_Min", "-6700"); mcServoTypeA.SetValue("Degree_Max", "6700"); mcServoTypeA.SetValue("PulseWidth_Min", "800"); mcServoTypeA.SetValue("PulseWidth_Max", "2700"); mcServoTypeA.SetValue("Period", "19500"); mcServoTypeA.SetValue("Acceleration", "65535"); mcServoTypeA.SetValue("Velocity", "65535"); mcServoTypeA.SetValue("Position", "0"); MotorConfiguration mcServoTypeB = new MotorConfiguration(); mcServoTypeB.SetValue("Degree_Min", "-6700"); mcServoTypeB.SetValue("Degree_Max", "6700"); mcServoTypeB.SetValue("PulseWidth_Min", "800"); mcServoTypeB.SetValue("PulseWidth_Max", "2100"); mcServoTypeB.SetValue("Period", "19500"); mcServoTypeB.SetValue("Acceleration", "65535"); mcServoTypeB.SetValue("Velocity", "65535"); mcServoTypeB.SetValue("Position", "0"); SetMotorConfiguration(JOINT1_SERVO, mcServoTypeA); SetMotorConfiguration(JOINT2_SERVO, mcServoTypeA); SetMotorConfiguration(JOINT3_SERVO, mcServoTypeB); SetMotorConfiguration(JOINT4_SERVO, mcServoTypeB); SetMotorConfiguration(JOINT5_SERVO, mcServoTypeB); SetMotorConfiguration(JOINT6_SERVO, mcServoTypeB); }
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(); }
private void ServoApproached(BrickServo sender, byte servoId, short position) { if (servoId != ServoId) return; PerformMeasurement(); }