Хелпикс

Главная

Контакты

Случайная статья





5.2.Сборка модели. 5.3.Програмное обеспечение



5. 2. Сборка модели

Сборка основной части конструкции (см.: 1, 2, 3, 4, 5, 6, 9, 10, 11, 12, 14, 15, 16)

Обеспечиваем конструкцию движущей частью(см.: 7, 8, 13)

 

1.

2.

 

3.

4.                                                                 5.

6.

7.

8.

9.

10.

11.

12.

13.

14.

15.

16.

 

5. 3. Програмное обеспечение

Управление движением робота реализовано с использованием двухмерного джойстика: переключатели включают соответствующие движения робота.  

Если при движении робота перед ним возникнет препятствие, то в зависимости от программы и поставленной задачи робот может останавливаться, используя датчик расстояния.

Управление джойстиком:

#pragma config(Motor, motor2,      leftMotor, tmotorVexIQ, PIDControl, reversed, encoder)

#pragma config(Motor, motor4,      rightMotor, tmotorVexIQ, PIDControl, encoder)

#pragma config(Motor, motor10,     armMotor, tmotorVexIQ, PIDControl, reversed, encoder)

#pragma config(Motor, motor11,        clawMotor, tmotorVexIQ, PIDControl, reversed, encoder)

//*!! Code automatically generated by 'ROBOTC' configuration wizard         !! *//

 

task main()

{

       int threshold=10;

       static int leftSpeed=0;

       static int rightSpeed=0;

 

       while(true)

       {

              int A = getJoystickValue(ChA);

                   int D = getJoystickValue(ChD);

                   displayCenteredBigTextLine(0, " ChA = %d", A);

                   displayCenteredBigTextLine(3, " ChB = %d", D);

 

                   leftSpeed = A/2;

                   rightSpeed = D/2;

 

                   if(leftSpeed> threshold||leftSpeed< -threshold)

                   {

                          setMotorSpeed(leftMotor, leftSpeed);

                   }

                   else

                   {

                              setMotorSpeed(leftMotor, 0);

                   }

 

                   if(rightSpeed> threshold||rightSpeed< -threshold)

                   {

                              setMotorSpeed(rightMotor, rightSpeed);

                   }

                   else

                   {

                              setMotorSpeed(rightMotor, 0);

                   }

 

                   if(getJoystickValue(BtnLUp)==1)

                   {

                              setMotorSpeed(armMotor, -127);

                   }

                   else if(getJoystickValue(BtnLDown)==1)

                   {

                              setMotorSpeed(armMotor, 127);

                   }

                   else

                   {

                              setMotorSpeed(armMotor, 0);

                   }

 

                   if(getJoystickValue(BtnRUp)==1)

                   {

                              setMotorSpeed(clawMotor, -127);

                   }

                   else if(getJoystickValue(BtnRDown)==1)

                   {

                              setMotorSpeed(clawMotor, 127);

                   }

                   else

                   {

                              setMotorSpeed(clawMotor, 0);

                   }

       }

}

******************************

#pragma config(Sensor, port3, colorSensor, sensorVexIQ_ColorHue)

//*!! Code automatically generated by 'ROBOTC' configuration wizard         !! *//

 

task main()

{

       while(true)

       {

                   int Green = getColorGreenChannel(port3);

                   int Red = getColorRedChannel(port3);

                   int Blue = getColorBlueChannel(port3);

                   float avg = (Green+Red+Blue)/3;

 

//                 displayCenteredBigTextLine(0, " Green = %d", Green);

//                 displayCenteredBigTextLine(2, " Red = %d", Red);

//                 displayCenteredBigTextLine(4, " Blue = %d", Blue);

 

                   if(Blue< avg & & Red> avg & & Green< avg)

                   {

                              displayCenteredBigTextLine(0, " Red" );

 

                   }

                   else

       {

                   displayCenteredBigTextLine(0, " Blue" );

 

       }

 

       }

}

 

*****************************************

 

task main()

{

int i=0;

while (1)

       {

       i=vexRT[BtnLUp]+2*vexRT[BtnRUp]+8*vexRT[BtnRDown]

       switch(i)

       {

                    case 0:

                    move(0, 0, 2);

                    break;

                    case 1:

                    move (0, 127, 2

 

 

}



  

© helpiks.su При использовании или копировании материалов прямая ссылка на сайт обязательна.