|
Page 1 of 1
|
[ 4 posts ] |
|
| Author |
Message |
|
brianchen11
Rookie
Joined: Tue Jul 03, 2012 5:16 am Posts: 43
|
 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?
|
| Sat Aug 04, 2012 7:59 pm |
|
 |
|
NeXT-Generation
Senior Roboticist
Joined: Wed Sep 28, 2011 10:13 pm Posts: 509 Location: Totally not spying on Hassenplug to see what he has for the Brickworld Chicago 2013 sumo contest.
|
 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 |
|
 |
|
brianchen11
Rookie
Joined: Tue Jul 03, 2012 5:16 am Posts: 43
|
 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 |
|
 |
|
NeXT-Generation
Senior Roboticist
Joined: Wed Sep 28, 2011 10:13 pm Posts: 509 Location: Totally not spying on Hassenplug to see what he has for the Brickworld Chicago 2013 sumo contest.
|
 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 |
|
|
|
Page 1 of 1
|
[ 4 posts ] |
|
Who is online |
Users browsing this forum: No registered users and 5 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
|
|