ROBOTC.net forums
http://robotc.net/forums/

Program doesn`t start after turning brick off and on
http://robotc.net/forums/viewtopic.php?f=1&t=4470
Page 1 of 1

Author:  FosterChip [ Wed Apr 25, 2012 12:01 pm ]
Post subject:  Program doesn`t start after turning brick off and on

Afetr compile and downloading program to brick it works perfectly. But when I turn brick off and than turn it on I try to start program. All I see is text "%program name% running". And nothing works. Screen doesn`t siplay any messages. But while according to code it should display some values. What is wrong?

Author:  NeXT-Generation [ Wed Apr 25, 2012 12:05 pm ]
Post subject:  Re: Program doesn`t start after turning brick off and on

FosterChip wrote:
Afetr compile and downloading program to brick it works perfectly. But when I turn brick off and than turn it on I try to start program. All I see is text "%program name% running". And nothing works. Screen doesn`t siplay any messages. But while according to code it should display some values. What is wrong?


Can you post your program?

Like this:

Code:
[code]Hi!  Put your program between these tags![/code]

Author:  FosterChip [ Wed Apr 25, 2012 12:16 pm ]
Post subject:  Re: Program doesn`t start after turning brick off and on

Sure,

But it`s hard to post it here. It uses few .c files.
I have just wrote simple program for testing.

Code:
 
task main()
{
  int iteration = 0;
 
  while (true)
  {
    /* Motors */
    motor[motorA] = 30;
    motor[motorB] = 30;
   
    /* Display */
    eraseDisplay();
    nxtDisplayTextLine(0, "it:%d", iteration);
    wait1Msec(100);
   
    /* Iteration */
    iteration++;
  }
}


This program works great after turning off and on. So, I understand, that this problem depends on program.

Author:  FosterChip [ Wed Apr 25, 2012 12:38 pm ]
Post subject:  Re: Program doesn`t start after turning brick off and on

I really don`t get why it doesn`t work after reboot.
My program contains multitasking.

It`s a little bit hard for me to explain. This program was written in NXC first. But then I switched to RobotC.

So, main task makes orders to another tasks. Such as Sensors, Display, Movement and Control task.
There is an array of orders to give.
Each task works in while loop waiting for a new order.

Sensors read values from each sensor (int this version I have 2 light sensors for line follower) and store them into global variables leftSensorValue and rightSensorValue.

Movement task executes the order (order is to follow the line using the PID regulation).
For PID regulation I have a special function in another one .c file.

Display task erases screen each 100 ms and prints desired information.

Code is,

Main Task
Code:
#pragma config(Sensor, S1,     lightSensorLeft,         sensorLightActive)
#pragma config(Sensor, S2,     lightSensorRight,        sensorLightActive)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//
#include "Order.c"
#include "Variables.c"
#include "PidLineFollow.c"
#include "Display.c"
#include "Sensor.c"
#include "Movement.c"
#include "Control.c"
//*!!Special tasks!!*//

void ReadOrder(int order_num);

task main()
{
  InitializeOrderLineMain();

  StartTask(sens, kDefaultTaskPriority);
  StartTask(move, kDefaultTaskPriority);
  StartTask(disp, kDefaultTaskPriority);

  while (true)
  {
    if (masterGiveOrder)
    {
      ReadOrder(masterCurrentOrder);
      if (OrderLineMainNext[masterCurrentOrder] == false)
        masterGiveOrder = false;
    }
  }
}

void ReadOrder(int order_num)
{
  int order = OrderLineMain[order_num];
  if (order == 0x06)
  {
    ord_pid_line_follow = true;
  }
}


Orders File
Code:
int OrderLineMain[100];
bool OrderLineMainNext[100];
bool ord_pid_line_follow = false;

void InitializeOrderLineMain()
{
  OrderLineMain[0] = 0x05; // Wait
  OrderLineMainNext[0] = true;
  OrderLineMain[1] = 0x06; // pid line follow
  OrderLineMainNext[1] = false;
}


Global Variables
Code:
/*Motors*/
int powerLeftMotor,
    powerRightMotor;

/*Sensors*/
int leftSensorValue = 0,
    rightSensorValue = 0;

/*Master*/
bool masterGiveOrder = true;
int masterCurrentOrder = 1;


Sensors
Code:
task sens()
{
  while (true)
  {
     leftSensorValue  = SensorValue[lightSensorLeft];
     rightSensorValue = SensorValue[lightSensorRight];
  }
}


Movement
Code:
task move()
{
   while(true)
   {

     if (ord_pid_line_follow)
     {
       PidLineFollow(100);
     }
   }
}


PidLineFollow (this is exemple code). Anyway, even with empty fucntion problem persists.
Code:
void PidLineFollow(int speed)
{
   motor[motorA] = speed;
   motor[motorB] = speed;
}

Author:  FosterChip [ Wed Apr 25, 2012 1:18 pm ]
Post subject:  Re: Program doesn`t start after turning brick off and on

Well, if immediately turn brick on after turning it off the program still starts and works. But after 10sec waiting it won`t start

Author:  miki [ Thu Apr 26, 2012 6:07 am ]
Post subject:  Re: Program doesn`t start after turning brick off and on

This is more a question than a tip:
Does the fact to download a program reset something in the brick ? (something that is not reset by a simple program launch).

Miki.

Author:  NeXT-Generation [ Fri Apr 27, 2012 3:19 pm ]
Post subject:  Re: Program doesn`t start after turning brick off and on

Have you tried it on a different NXT? Since your program is in multiple files, could you pleas upload a .zip (or similar) containing them all? I've never heard of a problem like this before.

Author:  FosterChip [ Sat Apr 28, 2012 3:09 am ]
Post subject:  Re: Program doesn`t start after turning brick off and on

I`ll try to run this on a different NXT and will tell you the results soon.

Author:  miki [ Mon Apr 30, 2012 11:44 am ]
Post subject:  Re: Program doesn`t start after turning brick off and on

Hi FosterChip

Did you try to switch on the option 'zero variables before program starts (n/a VEX)' ?
This option is located in 'View' menu, 'RobotC preferences' dialog box then 'Compiler' tab, according that the option 'Super User' is set in 'Window'/'Menu Level'.

Miki

Author:  FosterChip [ Fri May 04, 2012 4:53 am ]
Post subject:  Re: Program doesn`t start after turning brick off and on

Hi everyone!

Well, I`ve found the source of problem.
As you noticed, in task main() I call StartTask function with followint arguments:
StartTask(sensors, kDefaultTaskPriority);

So, writing kDefaultTaskPriority was a mistake. Since I deleted this parameter from StartTask function, program works properly after rebooting brick.

It`s interesting that in Multitasking sample program there are return statements at the end of each task. I`ve thought that this is the reason of improper work, but I was wrong.

Thanks for the help!

Author:  miki [ Fri May 04, 2012 7:55 am ]
Post subject:  Re: Program doesn`t start after turning brick off and on

Hi FosterChip,

I'm glad you found a workaround to this problem :-), even if I don't understand how it solves the issue :eek: .
The documentation says
Quote:
StartTask(TaskID, nPriority);
StartTaskWithPriority(TaskID, nPriority);
A functional call to start or restart the execution of a specific task. The "nPriority" command is optional, and can be used to assign a priority to a task at the time the task is told to start executing. If the "nPriority" command is not specified, the task will start with a default priority of "7".
A reading at first glance suggests that StartTask(TaskID, kDefaultTaskPriority) is the same than StartTask(TaskID);.
Another reading of this documentation chapter suggests that if you want to change the priority of a task, you should use StartTaskWithPriority(TaskID, nPriority); rather than StartTask(TaskID, nPriority); But in RobotC v3.08 and fw9.12, this function StartTaskWithPriority(TaskID, nPriority); doesn'exist :-(
So the documentation is obsolete (because StartTaskWithPriority() doesn't exist) and probably false (because it seems that StartTask(TaskID, kDefaultTaskPriority) doesn't behave like StartTask(TaskID))

Would you submit a ticket about that on http://www.robotc.net/support/ with a link on this topic (posting.php?mode=reply&f=1&t=4470)?
Thanks for sharing information.

Best regards
Miki

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/