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 / 4001
4000  |  4002
Subject: 
Re: Possible bug? Simple light sensor condition checking.
Newsgroups: 
lugnet.robotics.rcx.legos
Date: 
Mon, 16 Jul 2007 16:50:09 GMT
Viewed: 
16504 times
  
I use BrickOS (LegOS) but I'm not expert in the inner workings.

The code you have here appears fine to me.  So, it may be a bug in
BrickOS, or a problem elsewhere in your code.

I will say I've ran into some interesting things when using
tasks.  Sometimes, you have to include a wait, to suspend the current
task, and allow others to execute.  The cputs may include something like that.

So, the problem may be a bug in BrickOS, but the solution may be in
how you start & switch your tasks.

Steve

At 11:13 AM 7/16/07, Timothy Su wrote:
I tried my own skill on writing a program for the included lego test pad (RIS
2.0), and I discovered something weird.  The following code does set the
conditions right, but the following code doesn't set the conditions right if I
comment out the 'cputs("");'.  Any idea why?

int offonpad =0;

int check_off_pad(int argc, char *argv[]) {
        while(!shutdown_requested()) {
                if(LIGHT(LIGHTSENS) < 40) {
                        offonpad = 1;
                }
                else {
                        offonpad = 0;
                }
                cputs("");
        }
        return 0;
}

What doesn't work is (it fails to set the varible, if i initialize offonpad as
1, its always one.  If i initialize offonpad as 0, it is always zero.):

int check_off_pad(int argc, char *argv[]) {
        while(!shutdown_requested()) {
                if(LIGHT(LIGHTSENS) < 40) {
                        offonpad = 1;
                }
                else {
                        offonpad = 0;
                }
                //cputs("");
        }
        return 0;
}



Message has 1 Reply:
  Re: Possible bug? Simple light sensor condition checking.
 
(...) It looks to me like the c compiler optimized the assignment to the variable away, since there is no external method call (shutdown_requested() is just a macro). (...) You should make this volatile int offonpad = 0; (...) You should also put an (...) (17 years ago, 16-Jul-07, to lugnet.robotics.rcx.legos)

Message is in Reply To:
  Possible bug? Simple light sensor condition checking.
 
I tried my own skill on writing a program for the included lego test pad (RIS 2.0), and I discovered something weird. The following code does set the conditions right, but the following code doesn't set the conditions right if I comment out the (...) (17 years ago, 16-Jul-07, to lugnet.robotics.rcx.legos)

3 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