Robot C code with vex cortex

My students and I are trying to get a code for using a press button switch to run dragsters for 2-3 seconds. After we push the button, the motors will not turn on. we opened the sample code and modified it, but it will not work. Also, we watched videos and wrote our own code.

one robot the motors turned on, but the robot would not stop until you pushed the button again. I do not know what we are doing wrong. I have been using the vex v 5 coding and modkit. I forgot how to use robot c or I am leaving out a simple command with a punctuation or bracket to start and turn it off. Are limit switches easier than the button? I need serious help. Are there examples of the PLTW dragster or test bed code? I can’t find it.

are you using cortex with robotc or v5 with vex code?

the title suggest you’re using cortex with robotc, but this:

suggests otherwise.

vexcode v5 does not work with cortex, and robotc does not work with the v5 system. Which system are you using?

5 Likes

As always posting the code makes getting you an answer go faster.

6 Likes

I would guess you are actually using V5 based on how you describe things, but we can’t really help until you

  1. confirm this
    And
  2. show us your code
2 Likes

I am using Robot C and the button is not communicating when we push down to the rest of our dragster.

It is very difficult to debug code you can’t see, you will be able to get help much quicker if you post your code here.

3 Likes

and is your robot using the cortex system?
like foster said, posting your code is the only way we’ll be able to help you debug it.

2 Likes

#pragma config(Sensor, dgtl1, , sensorTouch)
#pragma config(Sensor, dgtl5, bumpSwitch, sensorDigitalIn)
#pragma config(Motor, port1, , tmotorVex393_HBridge, openLoop)
#pragma config(Motor, port2, rightMotor, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port9, leftMotor, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port10, , tmotorVex393_HBridge, openLoop)
//!!Code automatically generated by ‘ROBOTC’ configuration wizard !!//

task main()
{
while(1==1)// this is a loop
{
if(SensorValue(bumpSwitch)==1)// if the bump switch is pressed do the following code
{
{
}
startTask(rightMotor,127);

{

		wait1Msec(4.0);

}

	}
}

}

Task Description:

Pseudocode:

*/

task main()
{ //Program begins, insert code within curly braces
untilBump(bumpSwitch);

startMotor(rightMotor, 127);
wait(3.0);
stopMotor(rightMotor);
wait1Msec(.05);

}
This is another we ran

I’ve formatted your code for readability:

#pragma config(Sensor, dgtl1, , sensorTouch)
#pragma config(Sensor, dgtl5, bumpSwitch, sensorDigitalIn)
#pragma config(Motor, port1, , tmotorVex393_HBridge, openLoop)
#pragma config(Motor, port2, rightMotor, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port9, leftMotor, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port10, , tmotorVex393_HBridge, openLoop)
//!!Code automatically generated by ‘ROBOTC’ configuration wizard !!//

task main()
{
	while(1==1)// this is a loop
	{
		if(SensorValue(bumpSwitch)==1)// if the bump switch is pressed do the following code
		{
			{
			}
			startTask(rightMotor,127);

			{
					wait1Msec(4.0);
			}

		}
	}
}
5 Likes

Assuming you’re using VEX RobotC:

if(SensorValue(bumpSwitch)==1)// if the bump switch is pressed do the following code
{
			{
			}

You have an extra set of brackets (I indented them out for clarity), remove those.

startTask(rightMotor,127);

startTask runs a task not a motor. Use something like motor[rightMotor] = 127 instead to move the motor.

{
    wait1Msec(4.0);
}

You don’t need the surrounding brackets. wait1Msec takes a time in milliseconds, 4ms is too small for you to notice anything. 1000ms = 1 second, so if you meant to wait 4 seconds, use wait1Msec(4000); instead.


RobotC tutorials: https://www.youtube.com/channel/UCfYLoXdoqYwL8IH5vM37GUQ

(reading the docs also help)

C Tutorial: https://www.learn-c.org/

6 Likes

I put the above code in, and there is a yellow arrow on line 21 says invalid task state detected(92)
program slot 0, Task ID: [0}

@Battlesquid gave you suggestions, not full working code. Nevertheless, as stated before, please paste your full code here in code tags if you want help. It is nearly impossible to troubleshoot something we can’t see.

2 Likes