View unanswered posts | View active topics It is currently Sat Nov 01, 2014 4:26 am






Reply to topic  [ 4 posts ] 
Arrays and sensors. 
Author Message
Rookie

Joined: Tue Apr 08, 2014 6:15 pm
Posts: 1
Post 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. :)


Wed Apr 09, 2014 11:48 am
Profile
Expert
User avatar

Joined: Sat Aug 31, 2013 9:15 am
Posts: 160
Post 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.

_________________
FTC Team 6100 Chariots of Fire - Programmer (2012-2013)
FTC Team 7468 Blue Chariots of Fire - Programmer (2013-2014)
FTC Team 7468 Blue Chariots of Fire - Mentor (2014-2015)
Check out our team website at http://cof7468.weebly.com/.


Wed Apr 09, 2014 1:56 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post 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);
    }
}


Thu Apr 10, 2014 1:52 am
Profile
Moderator
Moderator

Joined: Thu Jan 03, 2013 5:10 pm
Posts: 198
Location: The plateau north of the Ohio River Valley, also known as Cave Country.
Post 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

_________________
I'm not a robot! I'm british! ~ quote from an asparagus
I am not a robot! I am a unicorn! ~ quote from a robot


Sat Apr 12, 2014 5:43 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.