To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.legosOpen lugnet.robotics.rcx.legos in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / legOS / 2213
2212  |  2214
Subject: 
Re: threads - bug in the firmware?
Newsgroups: 
lugnet.robotics.rcx.legos
Date: 
Wed, 16 Jan 2002 19:51:27 GMT
Viewed: 
1713 times
  
Hi again
I have now totally stripped down my code to a minimum and I am still having
problems with
the code hanging up. I can see nowhere where there can be a fault. I am a
long way from being an
expert, but is it possible there is a bug in the firmware? Would someone
else please try compiling
and running the code.  Gonna try another route, mutexs here I come ;-
)
Thanks
mike

*****************


//
**************************************************
// Program: rover_pid_control_1 -
stripped down
// Description: simple rover with left and right motors
// speed matched with
a PID algorithm
// Notes:
// Inputs: PRGM key
// Versions: 0.1 get it up and running
//
Programmer: Mike McFarlane
// Date: 5-1-02
// legOS version: 0.2.5
// development OS:
win98 with cygwin
// **************************************************


//
**************************************************
// Includes
//
**************************************************
#include <conio.h> // console
i/o
#include <unistd.h> // UNIX std for timers and task management
#include <dkey.h> //
to allow user input, doh

// **************************************************
//
Define
// **************************************************


//
**************************************************
// Declarations
//
**************************************************


// global process
id's
pid_t pid1;
pid_t pid2;
pid_t pid3;

// global misc
wakeup_t dummy1 =
0;
wakeup_t dummy2 = 0;


//
**************************************************
// Function prototypes
//
**************************************************
int bumper_task (int argc, char
*argv[]);
int left_task (int argc, char *argv[]);
int right_task (int argc, char
*argv[]);

wakeup_t bumper_hit (wakeup_t data);
wakeup_t key_hit (wakeup_t
data);

void key (int data1, int data2);



//
**************************************************
// Functions
//
**************************************************

//
**************************************************
// Function: main
//
Description:
// Notes:
// Returns: none
//
**************************************************

int main(int argc, char
*argv[])
{

// start tasks
pid1 = execi (&bumper_task, 0, NULL, PRIO_NORMAL,
DEFAULT_STACK_SIZE);
pid2 = execi (&left_task, 0, NULL, PRIO_NORMAL+1,
DEFAULT_STACK_SIZE);
pid3 = execi (&right_task, 0, NULL, PRIO_NORMAL+2,
DEFAULT_STACK_SIZE);

return 0;

} // end of main()



wakeup_t bumper_hit
(wakeup_t data)
{
return dkey_pressed (KEY_PRGM);
} // end of bumper_hit
()



int bumper_task (int argc, char *argv[])
{

while (1)
{
// wait for
bumper (now PRGM key) to be hit
wait_event (&bumper_hit, dummy2);
msleep
(250);
cputs ("ouch");
// hit an object so kill all other threads and stop
kill
(pid2);
kill (pid3);

cputs ("dead");
msleep (1000); //temp delay to simulate
some action

//********** GETS THIS FAR******************

// restart threads and
motors
pid2 = execi (&left_task, 0, NULL, PRIO_NORMAL+1,
DEFAULT_STACK_SIZE);
//key (1, pid2);
pid3 = execi (&right_task, 0, NULL,
PRIO_NORMAL+2, DEFAULT_STACK_SIZE);
//key (2, pid3);
cputs
("finish");
}

return 0;
} // end of bumper_task ()

int left_task (int argc, char
*argv[])
{

int k = 0;

for (k = 50; k < 255; k++)
{
// some action in here
normally
msleep (200);
}

return 0;
} // end of left_task ()

int right_task
(int argc, char *argv[])
{
int k = 0;

for (k = 50; k < 255; k++)
{
// some action in
here normally
lcd_int (k);
msleep (200);
}

return 0;
} // end of right_task
()

// ************* TEMP DEBUG CODE *************
void key (int data1, int
data2)
{
cputs ("key");

wait_event (&key_hit, dummy1);

lcd_int
(data1);
msleep (1000);
cputw (data2);
msleep (1000);

return;
} // end of
key()

wakeup_t key_hit (wakeup_t data)
{
return dkey_pressed (KEY_VIEW);
}



Message has 2 Replies:
  Re: threads - bug in the firmware?
 
(...) As pointed by Albert Huang, you cannot call kill() with an "invalid" pid. Actually, the comment above kill() in tm.c says: //! kill a process /*! \param pid must be valid process ID, or undefined behaviour will result! The function updates (...) (22 years ago, 16-Jan-02, to lugnet.robotics.rcx.legos)
  Re: threads - bug in the firmware?
 
Hi Mike, your problem is not because of an error in legOS. But what you do is that you start your subroutines and then you leave main()! Leaving main means that all your allocated memory is freed. The following will do the job: ---...--- cut here (...) (22 years ago, 17-Jan-02, to lugnet.robotics.rcx.legos)

Message is in Reply To:
  Re: threads
 
Hi again, I'm now totally stuck with this problem. I've spent all day at it, stepping through the code line by line with key presses. I've marked the point that the code appears to hang in left_control_task (). Someone please help, please. Thanks (...) (22 years ago, 15-Jan-02, to lugnet.robotics.rcx.legos)

18 Messages in This Thread:





Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact

This Message and its Replies on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR