View unanswered posts | View active topics It is currently Fri Oct 24, 2014 11:24 am






Reply to topic  [ 4 posts ] 
Multitasking 
Author Message
Rookie

Joined: Tue Jul 03, 2012 5:16 am
Posts: 43
Post Multitasking
I have a line following program that works quite well using PID with the lego colour sensors. However, I need to also change the colour sensor mode into light sensor like the code below. I need to run the line following program the same time I am running the code below, how do I achieve this?

Code:
SetSensorType(S1, sensorCOLORFULL); // Colour sensor
    SetSensorType(S3, sensorCOLORFULL); // Colour sensor
    wait1Msec(190);
    for(int count = 0; count<100; count++){       
       colour = normaliseReading(S1);      
       normalColour = SensorValue(S1);
       colour2 = normaliseReading(S3);
       normalColour2 = SensorValue(S3);
     } 
    
    SetSensorType(S1, sensorCOLORRED); // Colour sensor      
    SetSensorType(S3, sensorCOLORRED); // Colour sensor   
    wait1Msec(190);
    light = normaliseLight(S1);
    light2 = normaliseLight(S3);


Sat Aug 04, 2012 7:59 pm
Profile
Senior Roboticist
User avatar

Joined: Wed Sep 28, 2011 10:13 pm
Posts: 630
Location: If I told you, I'd have to kill you.
Post Re: Multitasking
Can you post all the code you have so far? Also, why do the color sensors need to switch between light and color mode?

_________________
A.K.A. inxt-generation
Self-proclaimed genius, and future world dominator.
My Brickshelf Folder
"Don't they teach recreational mathematics anymore?" - The Tenth Doctor
Bow down to Nikola Tesla, King of the Geek Gods.


Sat Aug 04, 2012 10:24 pm
Profile WWW
Rookie

Joined: Tue Jul 03, 2012 5:16 am
Posts: 43
Post Re: Multitasking
Don't worry, it works now. However, the switching between modes is a bit slow. I have created a task called readSensor.
Do you know how to make the modes switch extremely fast, possible 20 times a second? I need to switch the modes because the colour sensor needs to find a silver strip and that cannot be achieved when in FULL mode. I have entered into a Robocup Premier rescue comp.

task readSensor(){
while(true){

SetSensorType(S1, sensorCOLORFULL); // Colour sensor
SetSensorType(S3, sensorCOLORFULL); // Colour sensor
wait1Msec(160);
for(int count = 0; count<200; count++){
colour = normaliseReading(S1);
normalColour = SensorValue(S1);
colour2 = normaliseReading(S3);
normalColour2 = SensorValue(S3);
wait1Msec(1);
}

SetSensorType(S1, sensorCOLORRED); // Colour sensor
SetSensorType(S3, sensorCOLORRED); // Colour sensor
wait1Msec(160);
light = normaliseLight(S1);
light2 = normaliseLight(S3);
}
}

If you want the structure of the program, here it is anyway.

#include "ThatWay2.h"
#include "rescue2.h"

// Define robot dimenstions
const int silverPoint = 95;



task main(){
int battery = nAvgBatteryLevel; // Battery level of robot at start of program.

// Declaration of Global Variabls (Header files)
const int width = 20;
const int diameter = 56;

Tp = 65;
kp = 6;
ki = 0.001;
kd = 120;
int a = 0, b = 0;

// Declaration of variables only used in this program



offset[0] = normaliseReading(S1); // Calibrate offset values
offset[1] = normaliseReading(S3);

nMotorPIDSpeedCtrl(motorB)=mtrSpeedReg; // Start motor PID control
nMotorPIDSpeedCtrl(motorC)=mtrSpeedReg;

stopAllMotors();
resetmotors();

StartTask(readSensor,9);

while(readSensor){
if(SensorValue(S4)>23){
lineFollow(1,normalColour, normalColour2, colour, colour2); //line follow as usual.
}
else{
waterTower(); //WaterTower
}

if(light>silverPoint){ //If one of the sensor senses silver
rescue(); // rescue
}

}
}


Sun Aug 05, 2012 2:01 am
Profile
Senior Roboticist
User avatar

Joined: Wed Sep 28, 2011 10:13 pm
Posts: 630
Location: If I told you, I'd have to kill you.
Post Re: Multitasking
I say again: why do you need it in both modes? What is "full" mode being used for? Why can't you just use it in light sensor mode?

_________________
A.K.A. inxt-generation
Self-proclaimed genius, and future world dominator.
My Brickshelf Folder
"Don't they teach recreational mathematics anymore?" - The Tenth Doctor
Bow down to Nikola Tesla, King of the Geek Gods.


Sun Aug 05, 2012 11:39 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


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.