View unanswered posts | View active topics It is currently Fri Oct 24, 2014 3:03 am






Reply to topic  [ 11 posts ] 
RobotC only running first line of code once compiled? 
Author Message
Rookie

Joined: Mon Nov 25, 2013 3:46 am
Posts: 5
Post RobotC only running first line of code once compiled?
Recently I've been having a problem with RobotC that once i compile a program to our robot or onto virtual worlds it only runs the first line of code until the program is stopped even though i have a wait1Msec following it. Oddly though our remote control program seems to work fine.

Here is a link to the code that im having troubles with. http://pastebin.com/yf5sr3Fb

I'd greatly appreciate any help because right now my team and I are completely clueless as to what could be the problem.


Mon Nov 25, 2013 3:56 am
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: RobotC only running first line of code once compiled?
Don't know what your code is trying to do but you do not have any loop in your program. This means your program will run about 17 seconds and will be terminated once it reaches the last statement. Since you did not explain what your code is intending to do, I can't offer any advise on how to fix it.


Mon Nov 25, 2013 5:13 am
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: RobotC only running first line of code once compiled?
BTW, if your code is intended to be used as the FTC autonomous program, you may want to start with the autonomous template provided in RobotC "File->Open Sample Programs". Here is the template from RobotC:
Code:
#pragma config(Hubs,  S1, HTMotor,  HTServo,  none,     none)
#pragma config(Motor,  mtr_S1_C1_1,     ,              tmotorNone, openLoop)
#pragma config(Motor,  mtr_S1_C1_2,     ,              tmotorNone, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

/////////////////////////////////////////////////////////////////////////////////////////////////////
//
//                           Autonomous Mode Code Template
//
// This file contains a template for simplified creation of an autonomous program for an Tetrix robot
// competition.
//
// You need to customize two functions with code unique to your specific robot.
//
/////////////////////////////////////////////////////////////////////////////////////////////////////

#include "JoystickDriver.c"  //Include file to "handle" the Bluetooth messages.


/////////////////////////////////////////////////////////////////////////////////////////////////////
//
//                                    initializeRobot
//
// Prior to the start of autonomous mode, you may want to perform some initialization on your robot.
// Things that might be performed during initialization include:
//   1. Move motors and servos to a preset position.
//   2. Some sensor types take a short while to reach stable values during which time it is best that
//      robot is not moving. For example, gyro sensor needs a few seconds to obtain the background
//      "bias" value.
//
// In many cases, you may not have to add any code to this function and it will remain "empty".
//
/////////////////////////////////////////////////////////////////////////////////////////////////////

void initializeRobot()
{
  // Place code here to sinitialize servos to starting positions.
  // Sensors are automatically configured and setup by ROBOTC. They may need a brief time to stabilize.

  return;
}


/////////////////////////////////////////////////////////////////////////////////////////////////////
//
//                                         Main Task
//
// The following is the main code for the autonomous robot operation. Customize as appropriate for
// your specific robot.
//
// The types of things you might do during the autonomous phase (for the 2008-9 FTC competition)
// are:
//
//   1. Have the robot follow a line on the game field until it reaches one of the puck storage
//      areas.
//   2. Load pucks into the robot from the storage bin.
//   3. Stop the robot and wait for autonomous phase to end.
//
// This simple template does nothing except play a periodic tone every few seconds.
//
// At the end of the autonomous period, the FMS will autonmatically abort (stop) execution of the program.
//
/////////////////////////////////////////////////////////////////////////////////////////////////////

task main()
{
  initializeRobot();

  waitForStart(); // Wait for the beginning of autonomous phase.

  ///////////////////////////////////////////////////////////
  ///////////////////////////////////////////////////////////
  ////                                                   ////
  ////    Add your robot specific autonomous code here.  ////
  ////                                                   ////
  ///////////////////////////////////////////////////////////
  ///////////////////////////////////////////////////////////

  while (true)
  {}
}


Mon Nov 25, 2013 5:31 am
Profile
Rookie

Joined: Mon Nov 25, 2013 3:46 am
Posts: 5
Post Re: RobotC only running first line of code once compiled?
Yeah this is just a simple autonomous program and like you said it is supposed to run for only around 17 seconds but for some reason it only runs the first few lines. So in this code it just runs motorD and motorE until i stop it in RobotC or on the NXT.


Mon Nov 25, 2013 11:47 am
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: RobotC only running first line of code once compiled?
So here is your code. I have inserted some debug statements in there so you may use them to tell if it truly was just executing a few lines.
Code:
#pragma config(Hubs,  S1, HTMotor,  HTMotor,  none,     none)
#pragma config(Sensor, S1,     ,               sensorI2CMuxController)
#pragma config(Motor,  mtr_S1_C1_1,     motorD,        tmotorTetrix, openLoop, reversed)
#pragma config(Motor,  mtr_S1_C1_2,     motorE,        tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S1_C2_1,     motorF,        tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S1_C2_2,     motorG,        tmotorTetrix, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#include "JoystickDriver.c"
#pragma debuggerWindows("joystickSimple");

task main()
{
    eraseDisplay();

    motor[motorD] = 70;
    motor[motorE] = 70;
    wait1Msec(100);
    nxtDisplayTextLine(1, "stage 1 done");

    motor[motorF]= 90;
    wait1Msec(8500);
    nxtDisplayTextLine(2, "stage 2 done");

    motor[motorB] = -30;
    motor[motorC] = -30;
    wait1Msec(1000);
    nxtDisplayTextLine(3, "stage 3 done");

    motor[motorF] = -60;
    wait1Msec(7500);
    nxtDisplayTextLine(4, "stage 4 done");

    while (true)
    {
        // loop forever to keep the LCD alive.
        wait1Msec(100);
    }
    nxtDisplayTextLine(5, "never come here!");
}

If you run the above code, what do you see on the LCD display?


Mon Nov 25, 2013 2:13 pm
Profile
Rookie

Joined: Mon Nov 25, 2013 3:46 am
Posts: 5
Post Re: RobotC only running first line of code once compiled?
Okay so the screen displays this

(Quickly changing back and forth between) Wait for Start / Auton running
Stage 2 Done
EXT Batt: On
NXT: 8.6V
FMS Msgs: 1234 (increasing)
Teleop Filename:

And thats it.


Mon Nov 25, 2013 3:24 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: RobotC only running first line of code once compiled?
Then try this instead:
Code:
task main()
{
    StopTask(displayDiagnostics);
    eraseDisplay();

    motor[motorD] = 70;
    motor[motorE] = 70;
    wait1Msec(100);
    nxtDisplayTextLine(1, "stage 1 done");

    motor[motorF]= 90;
    wait1Msec(8500);
    nxtDisplayTextLine(2, "stage 2 done");

    motor[motorB] = -30;
    motor[motorC] = -30;
    wait1Msec(1000);
    nxtDisplayTextLine(3, "stage 3 done");

    motor[motorF] = -60;
    wait1Msec(7500);
    nxtDisplayTextLine(4, "stage 4 done");

    while (true)
    {
        // loop forever to keep the LCD alive.
        wait1Msec(100);
    }
    nxtDisplayTextLine(5, "never come here!");
}


Mon Nov 25, 2013 3:40 pm
Profile
Rookie

Joined: Mon Nov 25, 2013 3:46 am
Posts: 5
Post Re: RobotC only running first line of code once compiled?
Awesome that time it read out
Stage 1 done
Stage 2 done
Stage 3 done
Stage 4 done


So what was causing it to stop at stage 2? and thank you so much for the help.


Mon Nov 25, 2013 4:30 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: RobotC only running first line of code once compiled?
Chuchu wrote:
So what was causing it to stop at stage 2? and thank you so much for the help.

I have no idea. Are you sure it stopped at stage 2 before? Well, if it works, you are fine now.


Mon Nov 25, 2013 5:10 pm
Profile
Rookie

Joined: Mon Nov 25, 2013 3:46 am
Posts: 5
Post Re: RobotC only running first line of code once compiled?
Well im not sure it's been stopping at stage 2 but it will continuously run the first stage until it's stopped while also running Motor F.
It should stop running Motor D and E but it keeps going until i cancel it in the debugger window or on the NXT


Mon Nov 25, 2013 6:06 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: RobotC only running first line of code once compiled?
Chuchu wrote:
Well im not sure it's been stopping at stage 2 but it will continuously run the first stage until it's stopped while also running Motor F.
It should stop running Motor D and E but it keeps going until i cancel it in the debugger window or on the NXT

If you want to stop motors D and E, you need to explicitly instruct it to do so.
Code:
task main()
{
    StopTask(displayDiagnostics);
    eraseDisplay();

    motor[motorD] = 70;
    motor[motorE] = 70;
    wait1Msec(100);
    motor[motorD] = 0;
    motor[motorE] = 0;
    nxtDisplayTextLine(1, "stage 1 done");

    motor[motorF]= 90;
    wait1Msec(8500);
    motor[motorF] = 0;
    nxtDisplayTextLine(2, "stage 2 done");

    motor[motorB] = -30;
    motor[motorC] = -30;
    wait1Msec(1000);
    motor[motorB] = 0;
    motor[motorC] = 0;
    nxtDisplayTextLine(3, "stage 3 done");

    motor[motorF] = -60;
    wait1Msec(7500);
    motor[motorF] = 0;
    nxtDisplayTextLine(4, "stage 4 done");

    while (true)
    {
        // loop forever to keep the LCD alive.
        wait1Msec(100);
    }
    nxtDisplayTextLine(5, "never come here!");
}


Mon Nov 25, 2013 6:28 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 11 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.