Esempio n. 1
0
    private static string UID = "9yEBJVAgcoj"; // Change to your UID

    #endregion Fields

    #region Methods

    static void Main()
    {
        IPConnection ipcon = new IPConnection(HOST, PORT); // Create connection to brickd
        stepper = new BrickStepper(UID); // Create device object
        ipcon.AddDevice(stepper); // Add device to IP connection
        // Don't use device before it is added to a connection

        // Register "position reached callback" to ReachedCB
        // ReachedCB will be called every time a position set with
        // SetSteps or SetTargetPosition is reached
        stepper.RegisterCallback(new BrickStepper.PositionReached(ReachedCB));

        stepper.Enable();
        stepper.SetSteps(1); // Drive one step forward to get things going

        System.Console.WriteLine("Press ctrl+c to exit");
        ipcon.JoinThread();
    }
    private static string UID = "XXYYZZ"; // Change XXYYZZ to the UID of your Stepper Brick

    #endregion Fields

    #region Methods

    static void Main()
    {
        IPConnection ipcon = new IPConnection(); // Create IP connection
        BrickStepper stepper = new BrickStepper(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
        stepper.PositionReached += PositionReachedCB;

        stepper.Enable(); // Enable motor power
        stepper.SetSteps(1); // Drive one step forward to get things going

        Console.WriteLine("Press enter to exit");
        Console.ReadLine();
        stepper.Disable();
        ipcon.Disconnect();
    }
    private static string UID = "XXYYZZ"; // Change XXYYZZ to the UID of your Stepper Brick

    #endregion Fields

    #region Methods

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

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

        stepper.SetMotorCurrent(800); // 800mA
        stepper.SetStepMode(8); // 1/8 step mode
        stepper.SetMaxVelocity(2000); // Velocity 2000 steps/s

        // Slow acceleration (500 steps/s^2),
        // Fast deacceleration (5000 steps/s^2)
        stepper.SetSpeedRamping(500, 5000);

        stepper.Enable(); // Enable motor power
        stepper.SetSteps(60000); // Drive 60000 steps forward

        Console.WriteLine("Press enter to exit");
        Console.ReadLine();
        stepper.Disable();
        ipcon.Disconnect();
    }
    // Use position reached callback to program random movement
    static void PositionReachedCB(BrickStepper sender, int position)
    {
        int steps;
        if(random.Next(0, 2) == 0)
        {
            steps = random.Next(1000, 5001); // steps (forward)
            Console.WriteLine("Driving forward: " + steps + " steps");
        }
        else
        {
            steps = random.Next(-5000, -999); // steps (backward)
            Console.WriteLine("Driving backward: " + steps + " steps");
        }

        int vel = random.Next(200, 2001); // steps/s
        int acc = random.Next(100, 1001); // steps/s^2
        int dec = random.Next(100, 1001); // steps/s^2
        Console.WriteLine("Configuration (vel, acc, dec): (" +
                          vel + ", " + acc + ", " + dec + ")");

        sender.SetSpeedRamping(acc, dec);
        sender.SetMaxVelocity(vel);
        sender.SetSteps(steps);
    }