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

Arrays and sensors.
http://www.robotc.net/forums/viewtopic.php?f=1&t=8453
Page 1 of 1

Author:  qwerty54321 [ Wed Apr 09, 2014 11:48 am ]
Post subject:  Arrays and sensors.

I'm trying to make my robot stay inside an arena while saving sensor values in an array every second. I have managed to achieve both of these tasks but cant get the code working together.

The following code works using the "wait10Msec(100);" line of code but as expected this causes the rest of the code to pause and my robot will stray out of the arena.

int lightvalues[60];

for(int i = 0; i < 60; i++)
{
lightvalues[i] = SensorValue[lightSensor];
wait10Msec(100);
}

I realize I must have to use timers but when I try to use them instead of the array saving a value every second every element in the array changes. I've spent hours trying to get my head round this but cant figure it out.

Any pointers would be much appreciated! Thanks. :)

Author:  BurningLights [ Wed Apr 09, 2014 1:56 pm ]
Post subject:  Re: Arrays and sensors.

It would be helpful if you posted your entire code, especially the stuff that keeps the robot in the arena. It's kind of hard to tell you how to integrate the two pieces together without seeing that. Although, one way you could do it is to create a separate task for storing the light sensor values in an array, assuming you don't use the values in the array in any other part of your code.

Author:  MHTS [ Thu Apr 10, 2014 1:52 am ]
Post subject:  Re: Arrays and sensors.

I suppose you can do something like this.
Code:
task main()
{
    int lightvalues[60];
    int index = 0;

    ClearTimer(T1);
    while (index < 60)
    {
        if (timer1[T1] > 1000)
        {
            lightvalues[index] = SensorValue[lightSensor];
            index++;
            ClearTimer{T1);
        }
        //
        // Do something else
        //
        wait1Msec(10);
    }
}

Author:  Coder A [ Sat Apr 12, 2014 5:43 pm ]
Post subject:  Re: Arrays and sensors.

Have you any experience with tasks? Tasking is a programming concept that enables multiple pieces of code to run with the appearance of simultaneity. Check out the ROBOTC wiki page on them.

-A

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