Gyro - RobotC

Is there a way to program using RobotC so that the Gyro Sensor can help the robot remain on a straight line or is another sensor more suited to this need?

Gyro is pretty good, except for a small drift it typically exhibits.

In simplest form, you set the heading and then keep adjusting the left/right motor speed proportionally to difference between requested heading and the gyro reading.
(for keeping straight line, no complex PID logic is necessary).

Hey nenik, can you help me please. so i want to connect joysticks to the robot and when I go to compile code it gives me “ErrorDuplicate definition for task ‘main’.” on the two brackets above infinite loop to open and close claw.
here is my full code.:frowning:

#pragma config(Motor, mtr_Matrix_S1_1, FLMotor, tmotorTetrix, PIDControl, reversed, encoder)
#pragma config(Motor, mtr_Matrix_S1_2, FRMotor, tmotorTetrix, PIDControl, encoder)

//!!Code automatically generated by ‘ROBOTC’ configuration wizard !!//

#pragma debuggerWindows(“joystickSimple”);
#include “JoystickDriver.c”

task main()
{
while(true) //Loop Forever

//Get the Latest joystick values
getJoystickSettings(joystick);

//Driving Control
//left y
if(abs(joystick.joy1_y1) > 3)

motor[FRMotor] = joystick.joy1_y1;
motor[FLMotor] = joystick.joy1_y1;
{
motor[FLMotor] = 0;
motor[FRMotor] = 0;
//right x
if(abs(joystick.joy1_x2) > 3) //

motor[FRMotor] = -joystick.joy1_x2;
motor[FLMotor] = joystick.joy1_x2;
}
motor[FLMotor] = 0;
motor[FRMotor] = 0;
}

//Infinite Loop
while(true)

//If button 6 (right bumper) is pressed
if(joy1Btn(06) == 1)
{
//Raise the arm
motor[PORT7] = 100;
}

//Else, if button 8 (right trigger) is pressed
else if(joy1Btn(08) == 1)
{
//Lower the arm
motor[PORT7] = -100;
}
//Else (no button pressed)
else if(joy1Btn(08) == 0)
{
//Turn the arm motor off
motor[PORT7] = 0;
}
{
//Infinite Loop
while(true)

//If button 5 (left bumper) is pressed
if(joy1Btn(05) == 1)
{
//Open the claw
motor[PORT6] = 100;
}
//Else, if button 7 (left trigger) is pressed
else if(joy1Btn(07) == 1)
{
//Close the claw
motor[PORT6] = -100;
}
//Else (no button pressed)
else if(joy1Btn(07) == 0)
{
//Turn the arm motor off
motor[PORT6] = 0;
}
}

This looks more like VEX than VexIQ. Anyway, the formatting is either broken badly, of you miss a whole lot of curly braces. And have a sequence of two infinite loops - when is the second one supposed to run if the first one is infinite?

The right syntax for infinite loop would be
task main() {
// setup goes here
// …

// then the control loop
while (true) {
// all the joystick evaluation and motor control commands go here
// …
}
}

here is my full code.:frowning:

Don’t forget that you have code inside here: #include “JoystickDriver.c”. The contents of that file are essentially copied and pasted into your main file when it is compiled. If JoystickDriver.c also has a main() task then you will get the “Duplicate” error message. What is in JoystickDriver.c?

so does this part of my code go in task main()

#pragma config(Motor, mtr_Matrix_S1_1, FLMotor, tmotorTetrix, PIDControl, reversed, encoder)
#pragma config(Motor, mtr_Matrix_S1_2, FRMotor, tmotorTetrix, PIDControl, encoder)

//!!Code automatically generated by ‘ROBOTC’ configuration wizard !!//

#pragma debuggerWindows(“joystickSimple”);
#include “JoystickDriver.c”

so with the code above my robot will not turn everything but turn. How do I fix this

We are new to VEX IQ & Graphical RobotC. We want to try to use the Gyro Sensor & Color Sensor to program the robot to follow a black line down to the ring tray. We believe we now how to program it, but we’re having a problem getting the gyro sensor to recognize all of the motors involved in the movement of the robot. One set of tires works, but the other set doesn’t work when the gyro sensor is plugged in. So we know it has something to do with the gyro sensor.