Programming ISSUE

  1. 4 months ago

    PCHSRoboticsC

    May 14 Somerset,Kentucky 98089C

    We are doing a CIM Factory for class and it owrks by pressing buttons and then going to what you selected to make something.
    its not working and we don't know why. HELP.

    #pragma config(Sensor, dgtl5, leftEncoder, sensorQuadEncoder)
    #pragma config(Sensor, dgtl7, rightEncoder, sensorQuadEncoder)
    #pragma config(Motor, port2, VexTwist, tmotorVex269_MC29, openLoop)
    #pragma config(Motor, port3, VexTower, tmotorVex269_MC29, openLoop)
    #pragma config(Motor, port5, VexClaw, tmotorVex269_MC29, openLoop)
    #pragma config(Motor, port6, leftMotor, tmotorVex269_MC29, openLoop)
    #pragma config(Motor, port7, rightMotor, tmotorVex269_MC29, openLoop)
    #pragma config(Motor, port8, Slider, tmotorVex393_MC29, openLoop)
    //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

    /*---------------------------------------------------------------------------*/
    /* */
    /* Description: Competition template for VEX EDR */
    /* */
    /*---------------------------------------------------------------------------*/

    // This code is for the VEX cortex platform
    #pragma platform(VEX2)

    // Select Download method as "competition"
    #pragma competitionControl(Competition)

    //Main competition background code...do not modify!
    #include "Vex_Competition_Includes.c"

    /*---------------------------------------------------------------------------*/
    /* Pre-Autonomous Functions */
    /* */
    /* You may want to perform some actions before the competition starts. */
    /* Do them in the following function. You must return from this function */
    /* or the autonomous and usercontrol tasks will not be started. This */
    /* function is only called once after the cortex has been powered on and */
    /* not every time that the robot is disabled. */
    /*---------------------------------------------------------------------------*/
    void pre_auton ()
    {
    }
    void driveFront(int front)
    {
    int masterPower1 = 125; //do not set this at 127 because the slave power will not be able to go over
    int slavePower1 = 125;
    int error1 = 0;
    int kp1 = 5;

    //Reset the encoders.
    SensorValue[leftEncoder] = 0;
    SensorValue[rightEncoder] = 0;

    while((SensorValue[leftEncoder]) < front)// move forward to stars
    {
    //Set the motor powers to their respective variables.
    motor[leftMotor] = masterPower1;
    motor[rightMotor] = slavePower1;

    error1 = SensorValue[leftEncoder] - SensorValue[rightEncoder];
    slavePower1 += error1 / kp1;
    wait1Msec(100);
    }
    motor[leftMotor] = -20;
    motor[rightMotor] = -20;
    wait1Msec(250);
    motor[leftMotor] = 0;
    motor[rightMotor] = 0;
    }

    void driveBack(int back)
    {

    int masterPower = -125;
    int slavePower = -125;

    int error = 0;

    int kp = 15;

    //Reset the encodback
    SensorValue[leftEncoder] = 0;
    SensorValue[rightEncoder] = 0;
    wait1Msec(500);
    //Repeat ten times a second.
    while((SensorValue[leftEncoder]*-1) < back)
    {
    //Set the motor powers to their respective variables.
    motor[leftMotor] = masterPower;
    motor[rightMotor] = slavePower;

    error = SensorValue[leftEncoder] - SensorValue[rightEncoder];

    slavePower += error / kp;

    wait1Msec(100);
    }
    motor[leftMotor] = 20;
    motor[rightMotor] = 20;
    wait1Msec(250);
    motor[leftMotor] = 0;
    motor[rightMotor] = 0;
    wait1Msec(100); //pause one second
    }

    /*---------------------------------------------------------------------------*/
    /* */
    /* Autonomous Task */
    /* */
    /* This task is used to control your robot during the autonomous phase of */
    /* a VEX Competition. */
    /* */
    /* You must modify the code to add your own robot specific commands here. */
    /*---------------------------------------------------------------------------*/

    task autonomous()
    {

    // Remove this function call once you have "real" code.
    AutonomousCodePlaceholderForTesting();
    }

    /*---------------------------------------------------------------------------*/
    /* */
    /* User Control Task */
    /* */
    /* This task is used to control your robot during the user control phase of */
    /* a VEX Competition. */
    /* */
    /* You must modify the code to add your own robot specific commands here. */
    /*---------------------------------------------------------------------------*/

    task usercontrol()
    {
    //customer picking

    if (vexRT[Btn5U] == 1)
    {
    while (vexRT[Btn5U] == 1)
    {
    driveFront(500);
    }

    }
    if (vexRT[Btn6U] == 1)
    {
    while (vexRT[Btn6U] == 1)
    {
    driveFront(750);
    }

    }

    if (vexRT[Btn7U] == 1)
    {
    while (vexRT[Btn7U] == 1)
    {
    driveFront(1000);
    }

    }
    if (vexRT[Btn8U] == 1)
    {
    while (vexRT[Btn8U] == 1)
    {
    driveFront(1250);
    }

    }
    }

  2. Wiredcat Robotics

    May 14 Neuqua Valley High School | Na... 2360Z

    First things first, does your class actually have a VEX Net Competition switch? As far as I know, you've put your code in the competition template (which works only if you're using the VEX Net competition switch).
    "Not working" could mean a variety of things. Is it not moving far enough? Or is it just not moving all together?

    But for a start, // This code is for the VEX cortex platform #pragma platform(VEX2) // Select Download method as "competition" #pragma competitionControl(Competition) //Main competition background code...do not modify! #include "Vex_Competition_Includes.c" shouldn't be necessary.
    Just start a new file and copy-paste your motor/sensor setups into it and your user-defined functions as well. put what was in task usercontrol into the task main of the new program. Otherwise it seems that your code is properly done and should work.
    Hopefully this helps!

  3. jrp62

    May 14 V5 Beta Tester Michigan 33 & 3333
    Edited 4 months ago by jrp62

    You need a while loop inside the user control task. The code is only running once then stopping, rather than constantly polling for button presses.

    Don't feel bad, everyone has made this mistake at least once.

  4. [deleted]

    May 16
    Deleted 4 months ago by DRow
  5. nenik

    May 16 V5 Beta Tester

    @DRow spam detected

 

or Sign Up to reply!