Manipulator control.

The manipulator control can be used to mimic behaviour of analogue joystick using regular mouse. By dragging manipulator away from control's centre, it fires PositionChanged event notifying about its X/Y coordinates (or about R/Theta coordinates in Polar coordinates system).

For example, in robotics applications the control can be used to drive robots. If user drags manipulator further from centre (increasing distance between centre and manipulator), then higher power (speed) should be set for robot's motors. But dragging it in different directions away from centre should result in changing robot's direction: straight forward, backward, turning right or left, etc.

Another possible application of the control is to control position of some device, etc. For example, the control could be used with pan-tilt camera - by dragging control away from centre, the camera may rotate in one of the directions.

Inheritance: System.Windows.Forms.Control
Ejemplo n.º 1
0
        // Driving with "software joystick"
        private void manipulatorControl_PositionChanged( object sender, ManipulatorControl.PositionEventArgs eventArgs )
        {
            float leftMotorPower = 0f, rightMotorPower = 0f;

            // calculate robot's direction and speed
            if ( ( eventArgs.X != 0 ) || ( eventArgs.Y != 0 ) )
            {
                // radius (distance from center)
                double r = eventArgs.R;
                // theta
                double t = eventArgs.Theta;

                if ( t > 180 )
                    t -= 180;

                // index of maximum power
                int maxPowerIndex = (int) ( t / 180 * maxPowers.Length );

                // check direction to move
                if ( eventArgs.Y > 0 )
                {
                    // forward direction
                    leftMotorPower  = (float) ( r * maxPowers[maxPowers.Length - maxPowerIndex - 1] );
                    rightMotorPower = (float) ( r * maxPowers[maxPowerIndex] );
                }
                else
                {
                    // backward direction
                    leftMotorPower  = (float) ( -r * maxPowers[maxPowerIndex] );
                    rightMotorPower = (float) ( -r * maxPowers[maxPowers.Length - maxPowerIndex - 1] );
                }
            }

            DriveMotors( leftMotorPower, rightMotorPower );
        }