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 / 2711
2710  |  2712
Subject: 
Re: HOWTO Demo.c
Newsgroups: 
lugnet.robotics.rcx.legos
Date: 
Thu, 11 Jul 2002 12:59:25 GMT
Viewed: 
5215 times
  
Brilliant! Brilliant!

It works!

Many Thanks to Micheal Obenland and also to Steve Hassenplug

Best Regards

Shehryar

"Michael Obenland" <obenland@t-online.de> wrote in message
news:Gz1xAM.Inn@lugnet.com...
> To solve your problems with demo.c, you sent me your source. There are • some
> problems with it, but I think they are intresting enough to say something
> about them.
> 
> The big problem you get with your program is caused by your main function:
> 
> -------------------------------------------------------------------------- • --------------
> int main(int argc, char *argv[])
> {
> pid1=execi(&task_swapper,0,NULL,1,DEFAULT_STACK_SIZE);
> return 0;
> }
> -------------------------------------------------------------------------- • ------------
> 
> This causes all your problems. The reason is, that you exec the task • swapper
> process, but then YOU EXIT YOUR PROGRAM!
> There was a bug in the reaper, some legOS versions ago. The reaper is the
> procedure that should clean the memory used by a program after the end of
> the program. The reaper didn't do that and that caused a memory leak every
> time you had run your user program. Nowadays, the reaper behaves as
> expected and frees all user memory. So in your program, the tasks started
> by the task_swapper will try to use memory formerly allocated by your main
> routine beeing now void. This could work, sometimes, but normaly your
> program wil crash badly (what your program does).
> 
> You can do two things now. First, put all the task_swapper functionality • in
> main and sweep out the task_swapper. If you want to keep the program • logic,
> you may introduce a new to-be-watched variable:
> 
> -------------------------------------------------------------------------- • -----------
> ...
> int ready;
> 
> /*
> button press functions
> */
> 
> wakeup_t button_press_wakeup(wakeup_t data) {
> return PRESSED(dbutton(),data);
> }
> 
> wakeup_t button_release_wakeup(wakeup_t data) {
> return RELEASED(dbutton(),data);
> }
> 
> wakeup_t done_it( wakeup_t data )
> {
>    return( ready == 1 );
> }
> 
> int main(int argc, char *argv[])
> {
>    ready = 0;
>    pid1 = execi(&task_swapper,0,NULL,1,DEFAULT_STACK_SIZE);
>    wait_event( done_it, 0 );
> return 0;
> }
> 
> -------------------------------------------------------------------------- • ---------
> 
> now you must insert
> 
>    ready = 1;
> 
> as the last statement in your task_swapper function. Main() will wait for
> ready to become 1 (via the done_it wakeup function) and exits then.
> 
> This will make your program work, mostly. There is a subtle bug in your
> touch_sensor function. Your write the following:
> 
> -------------------------------------------------------------------------- • ---------
> 
> void touch_sensor()
> {
> cputs("touch"); /*indicate which function we are in*/
> msleep(500);
> motor_a_speed(100);
> motor_c_speed(100);
> while(1)
> {
> motor_a_dir(fwd);
> motor_c_dir(fwd);
> cputs(TOUCH_1); /*output sensor value*/
> if(TOUCH_1!=0) /*if sensor has been touched*/
> {
> motor_a_dir(rev);
> motor_c_dir(rev);
> sleep(1);
> }
> }
> }
> 
> -------------------------------------------------------------------------- • ----------
> 
> you cputs a non-string variable. You better do an lcd_int( TOUCH_1) or • drop
> this statement completly. But then, you can't stop touch_sensor by • pressing
> the view button most of the time. If you change the cputs( TOUCH_1) to
> msleep(100) or yield(), your program will run as you expected.
> 
> Hope it helps, regards,
> 
> Michael
> 



Message is in Reply To:
  Re: HOWTO Demo.c
 
To solve your problems with demo.c, you sent me your source. There are some problems with it, but I think they are intresting enough to say something about them. The big problem you get with your program is caused by your main function: ---...--- (...) (24 years ago, 10-Jul-02, to lugnet.robotics.rcx.legos)

3 Messages in This Thread:

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

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