nxtlib/src/Protocol.cs
/// <summary> 
/// [Native] Sync two motors as driving motors, specifying whether to brake or coast and the turn ratio.
/// </summary>
/// <param name="port">The ports of the selected motors.  Exactly two motors must be selected.</param>
/// <param name="power">The power at which to move the motors, between -100 and 100.</param>
/// <param name="stop">Whether to brake or coast during operation.  Braking uses far more power.</param>
/// <param name="turnratio">The turn ratio of the two motors, between -100 and 100.  A ratio of zero will make both motors move straight.
///   A negative ratio will move the left motor more and a positive ratio would move the right motor more.</param>
[Native] Sync two motors as driving motors, specifying whether to brake or coast and the turn ratio.
[ Native ] Sync two motors as driving motors specifying whether to brake or coast and the turn ratio .
public void MoveMotors(MotorPortSyncable port, int power, MotorStop stop, int turnratio)
        {
            int[] pow = new int[] { power, power };
            double ratio = (double)turnratio;
            double powr = (double)power;
            if (turnratio != 0)
            {
                bool masterleft = true;
                if (power < 0)
                {
                    if (turnratio < 0)
                    {
                        masterleft = true;
                    }
                    else
                    {
                        masterleft = false;
                    }
                }
                else
                {
                    if (turnratio <= 0)
                    {
                        masterleft = false;
                    }
                    else
                    {
                        masterleft = true;
                    }
                }
                double equ = ((-2 * Math.Abs(ratio)) + 100) / 100 * powr;
                if (masterleft == true)
                {
                    pow = new int[] { power, Convert.ToInt32(Math.Floor(equ)) };
                }
                else
                {
                    pow = new int[] { Convert.ToInt32(Math.Floor(equ)), power };
                }
            }
            MotorMode mode = MotorMode.MotorOn;
            if (stop == MotorStop.Coast)
            {
                mode = MotorMode.On_Regulated;
                if ((power < 75) && (power > -75))
                {
                    mode = MotorMode.MotorOn;
                }
            }
            if (stop == MotorStop.Brake)
            {
                mode = MotorMode.On_Brake_Regulated;
                if ((power < 75) && (power > -75))
                {
                    mode = MotorMode.On_Brake;
                }
            }
            Motor[] motors = new Motor[] { };
            if (port == MotorPortSyncable.AB) { motors = new Motor[] { Motor.A, Motor.B }; }
            if (port == MotorPortSyncable.AC) { motors = new Motor[] { Motor.A, Motor.C }; }
            if (port == MotorPortSyncable.BC) { motors = new Motor[] { Motor.B, Motor.C }; }
            if (port == MotorPortSyncable.BA) { motors = new Motor[] { Motor.B, Motor.A }; }
            if (port == MotorPortSyncable.CA) { motors = new Motor[] { Motor.C, Motor.A }; }
            if (port == MotorPortSyncable.CB) { motors = new Motor[] { Motor.C, Motor.B }; }
            SetOutputState(motors[0], (sbyte)pow[0], mode,
                MotorReg.Speed, (sbyte)turnratio, MotorState.Running, (uint)0);
            SetOutputState(motors[1], (sbyte)pow[1], mode,
                MotorReg.Speed, (sbyte)turnratio, MotorState.Running, (uint)0);
            return;
        }
public void MoveMotors ( MotorPortSyncable port , int power , MotorStop stop , int turnratio ) { int [ ] pow = new int [ ] { power , power } ; double ratio = ( double ) turnratio ; double powr = ( double ) power ; if ( turnratio != 0 ) { bool masterleft = true ; if ( power < 0 ) { if ( turnratio < 0 ) { masterleft = true ; } else { masterleft = false ; } } else { if ( turnratio <= 0 ) { masterleft = false ; } else { masterleft = true ; } } double equ = ( ( - 2 * Math . Abs ( ratio ) ) + 100 ) / 100 * powr ; if ( masterleft == true ) { pow = new int [ ] { power , Convert . ToInt32 ( Math . Floor ( equ ) ) } ; } else { pow = new int [ ] { Convert . ToInt32 ( Math . Floor ( equ ) ) , power } ; } } MotorMode mode = MotorMode . MotorOn ; if ( stop == MotorStop . Coast ) { mode = MotorMode . On_Regulated ; if ( ( power < 75 ) && ( power > - 75 ) ) { mode = MotorMode . MotorOn ; } } if ( stop == MotorStop . Brake ) { mode = MotorMode . On_Brake_Regulated ; if ( ( power < 75 ) && ( power > - 75 ) ) { mode = MotorMode . On_Brake ; } } Motor [ ] motors = new Motor [ ] { } ; if ( port == MotorPortSyncable . AB ) { motors = new Motor [ ] { Motor . A , Motor . B } ; } if ( port == MotorPortSyncable . AC ) { motors = new Motor [ ] { Motor . A , Motor . C } ; } if ( port == MotorPortSyncable . BC ) { motors = new Motor [ ] { Motor . B , Motor . C } ; } if ( port == MotorPortSyncable . BA ) { motors = new Motor [ ] { Motor . B , Motor . A } ; } if ( port == MotorPortSyncable . CA ) { motors = new Motor [ ] { Motor . C , Motor . A } ; } if ( port == MotorPortSyncable . CB ) { motors = new Motor [ ] { Motor . C , Motor . B } ; } SetOutputState ( motors [ 0 ] , ( sbyte ) pow [ 0 ] , mode , MotorReg . Speed , ( sbyte ) turnratio , MotorState . Running , ( uint ) 0 ) ; SetOutputState ( motors [ 1 ] , ( sbyte ) pow [ 1 ] , mode , MotorReg . Speed , ( sbyte ) turnratio , MotorState . Running , ( uint ) 0 ) ; return ; }
[Native] Sync two motors as driving motors, specifying whether to brake or coast and the turn ratio.
[ Native ] Sync two motors as driving motors specifying whether to brake or coast and the turn ratio .
//Arc and Point rotation //Both arc and point rotation may be used for joystick control //pow = new int[] { Convert.ToInt32(Math.Floor(((50 - diff) / 100) * powr)), //Convert.ToInt32(Math.Floor(((50 + diff) / 100) * powr)) }; //pow = new int[] { Convert.ToInt32(Math.Floor(((50 - diff) / 100) * powr)), //Convert.ToInt32(Math.Floor(((50 + diff) / 100) * powr)) }; //slave motor power = master power * turn ratio //find which motor is the master
port
MotorPortSyncable
The ports of the selected motors.  Exactly two motors must be selected.
The ports of the selected motors . Exactly two motors must be selected .
power
int
The power at which to move the motors, between -100 and 100.
The power at which to move the motors between - 100 and 100 .
stop
MotorStop
Whether to brake or coast during operation.  Braking uses far more power.
Whether to brake or coast during operation . Braking uses far more power .
turnratio
int
The turn ratio of the two motors, between -100 and 100.  A ratio of zero will make both motors move straight.
A negative ratio will move the left motor more and a positive ratio would move the right motor more.
The turn ratio of the two motors between - 100 and 100 . A ratio of zero will make both motors move straight . A negative ratio will move the left motor more and a positive ratio would move the right motor more .