problem with maze solve project
Author |
Message |
fahd
Rookie
Joined: Tue Jun 05, 2012 2:31 pm Posts: 11
|
 problem with maze solve project
i wrote this code but not completely finished to solve the maze which i have blacks line inside it i used color sensor as light sensor because i don't know how i can used color sensor to detect the black line inside the maze please any one can help me and give me some advice to do it this is my basic project  |  |  |  | Code: #pragma config(Sensor, S1, color, sensorCOLORRED) #pragma config(Sensor, S2, touch, sensorTouch) #pragma config(Sensor, S4, sonar, sensorSONAR) #pragma config(Motor, motorA, ma, tmotorNormal, PIDControl, encoder) #pragma config(Motor, motorB, mb, tmotorNormal, PIDControl, encoder) #pragma config(Motor, motorC, mc, tmotorNormal, PIDControl, encoder) //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*// // Calibration values, these may be different for you const int blackValue = 220; const int whiteValue = 580;
// Normalise a raw value, returns a value from 0 to 100 int normaliseReading(int rawValue) { // Anything less than the black value should return 0 if (rawValue <= blackValue) return 0;
// Anything brighter than the white value should return 100 else if (rawValue >= whiteValue) return 100;
// Anything else should be calculated in a scale from 0-100% else return ((long)(rawValue - blackValue) * 100) / (whiteValue - blackValue); } task main() { int rawValue = 0; int normalisedValue = 0; while (true) { // Get the raw value from the sensor. rawValue = SensorRaw[color];
// Calculate the normalised value normalisedValue = normaliseReading(rawValue);
nxtDisplayTextLine(4, "Raw: %3d", rawValue); nxtDisplayTextLine(5, "Norm: %3d", normalisedValue); wait1Msec(100); rawValue = SensorRaw[color]; if (rawValue>=300) { if((SensorValue(sonar)>15)&&((SensorValue(sonar)<18)) { motor[mc]=30; motor[mb]=60; SensorValue(color); SensorValue(sonar); } else if(SensorValue(sonar)<11) { motor[mc]=60; motor[mb]=30; SensorValue(color); SensorValue(sonar); }
} else if (rawValue<300) { motor[mc]=60; motor[mb]=60; SensorValue(color); SensorValue(sonar); if(SensorValue(sonar)>18) { motor[mc]=0; motor[mb]=60; wait1Msec(500); SensorValue(color); SensorValue(sonar); } } } } |  |  |  |  |
|
Tue Jun 05, 2012 2:44 pm |
|
 |
NeXT-Generation
Senior Roboticist
Joined: Wed Sep 28, 2011 10:13 pm Posts: 630 Location: If I told you, I'd have to kill you.
|
 Re: problem with maze solve project
Could you please post the code using the tags? Because it's very hard to read otherwise. Also, could you please explain the problem better? I'm not exactly sure what's wrong.
_________________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.
|
Tue Jun 05, 2012 2:51 pm |
|
 |
fahd
Rookie
Joined: Tue Jun 05, 2012 2:31 pm Posts: 11
|
 Re: problem with maze solve project
ok i will do it
|
Tue Jun 05, 2012 2:58 pm |
|
 |
fahd
Rookie
Joined: Tue Jun 05, 2012 2:31 pm Posts: 11
|
 Re: problem with maze solve project
my problem is with color sensor when i but the robot on clock wise is doing perfect but on counter clockwise it's not doing that's i used sonar u know there is two white color and the line between it  |  |  |  | Code: #pragma config(Sensor, S1, color, sensorCOLORRED) #pragma config(Sensor, S2, touch, sensorTouch) #pragma config(Sensor, S4, sonar, sensorSONAR) #pragma config(Motor, motorA, ma, tmotorNormal, PIDControl, encoder) #pragma config(Motor, motorB, mb, tmotorNormal, PIDControl, encoder) #pragma config(Motor, motorC, mc, tmotorNormal, PIDControl, encoder) //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*// // Calibration values, these may be different for you const int blackValue = 220; const int whiteValue = 580;
// Normalise a raw value, returns a value from 0 to 100 int normaliseReading(int rawValue) { // Anything less than the black value should return 0 if (rawValue <= blackValue) return 0;
// Anything brighter than the white value should return 100 else if (rawValue >= whiteValue) return 100;
// Anything else should be calculated in a scale from 0-100% else return ((long)(rawValue - blackValue) * 100) / (whiteValue - blackValue); } task main() { int rawValue = 0; int normalisedValue = 0; while (true) { // Get the raw value from the sensor. rawValue = SensorRaw[color];
// Calculate the normalised value normalisedValue = normaliseReading(rawValue);
nxtDisplayTextLine(4, "Raw: %3d", rawValue); nxtDisplayTextLine(5, "Norm: %3d", normalisedValue); wait1Msec(100); rawValue = SensorRaw[color]; if (rawValue>=300) { if((SensorValue(sonar)>15)&&((SensorValue(sonar)<18)) { motor[mc]=30; motor[mb]=60; SensorValue(color); SensorValue(sonar); } else if(SensorValue(sonar)<11) { motor[mc]=60; motor[mb]=30; SensorValue(color); SensorValue(sonar); }
} else if (rawValue<300) { motor[mc]=60; motor[mb]=60; SensorValue(color); SensorValue(sonar); if(SensorValue(sonar)>18) { motor[mc]=0; motor[mb]=60; wait1Msec(500); SensorValue(color); SensorValue(sonar); } } } } |  |  |  |  |
|
Tue Jun 05, 2012 3:03 pm |
|
 |
Spiked3
Expert
Joined: Tue Feb 28, 2012 3:10 pm Posts: 197
|
 Re: problem with maze solve project
I don't understand why you would ever use a sonar in a line following program? What were you trying to accomplish with it again?
What does SensorValue(color); SensorValue(sonar);
on lines by themselves do??? I just looked at the help, and I do not see any functions by that name. Even if there are, you not reading from or assigning to them, so what are they for?
_________________Mike aka Spiked3 http://www.spiked3.com
|
Tue Jun 05, 2012 5:14 pm |
|
 |
fahd
Rookie
Joined: Tue Jun 05, 2012 2:31 pm Posts: 11
|
 Re: problem with maze solve project
because i don't know how to use color sensor on a right way . for SensorValue(color); SensorValue(sonar); i made for every time the program going in any loop because i want it to re-read again from the sensors
|
Wed Jun 06, 2012 5:19 am |
|
 |
JohnWatson
Site Admin
Joined: Thu May 24, 2012 12:15 pm Posts: 722
|
 Re: problem with maze solve project
These may be the problem though. The robot is looking at the sensors, reading the values...and then doing nothing with them. You need to assign them to a variable, put them in a function, or something. You're on the right track, though (no pun intended). For example: Hope this helps!
_________________Check out our Blog! And our Facebook page! Need help? Take a look at our updated help documentation and the ROBOTC Forums.
|
Wed Jun 06, 2012 9:33 am |
|
 |
Spiked3
Expert
Joined: Tue Feb 28, 2012 3:10 pm Posts: 197
|
 Re: problem with maze solve project
I'm thinking it may even be incorrect syntax. it should be SensorValue[color] ? using '()' should not even compile, or does robotC accept either syntax?
_________________Mike aka Spiked3 http://www.spiked3.com
|
Wed Jun 06, 2012 12:20 pm |
|
 |
NeXT-Generation
Senior Roboticist
Joined: Wed Sep 28, 2011 10:13 pm Posts: 630 Location: If I told you, I'd have to kill you.
|
 Re: problem with maze solve project
I've always used "()". I've seen some people use "[]" but the documentation and online lessons use "()". Either one compiles.
_________________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.
|
Wed Jun 06, 2012 12:45 pm |
|
 |
Spiked3
Expert
Joined: Tue Feb 28, 2012 3:10 pm Posts: 197
|
 Re: problem with maze solve project
The help file I have does not use (), but I suppose you are right. That is just so wrong, but you should have seen the look on my face when the compiler said, "oh you mis-spelled a variable, ill use one spelled a little different". I must have missed those classes in compiler design 
_________________Mike aka Spiked3 http://www.spiked3.com
|
Wed Jun 06, 2012 3:38 pm |
|
 |
MHTS
Guru
Joined: Sun Nov 15, 2009 5:46 am Posts: 1523
|
 Re: problem with maze solve project
That's one of the most confusing things about RobotC that some things are accessed by "Well-known" array variables and some are by functions. In the compiler/OS classes I took and the OS I wrote  , we seldom published global "Well-known" variables. Even in C++, if you need to access a variable, you make it private and provide an accessor function. In any case, it wouldn't be too bad if RobotC is at least consistent throughout (i.e. all accessed by well-known arrays or all accessed by functions), but mixing them is totally confusing. To this date, when I am programming the motors or sensors, I still have to search my past code to see which way it should be. To deal with this, I abstracted all sensor/motor accesses by simulated C++ objects so my main code never have to access them directly.
|
Wed Jun 06, 2012 4:50 pm |
|
 |
NeXT-Generation
Senior Roboticist
Joined: Wed Sep 28, 2011 10:13 pm Posts: 630 Location: If I told you, I'd have to kill you.
|
 Re: problem with maze solve project
You wrote a Operating System?!?!?! Where is it? What's it like? Also, do you have the simulated object code available? I'd like to see it.
_________________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.
|
Wed Jun 06, 2012 11:46 pm |
|
 |
MHTS
Guru
Joined: Sun Nov 15, 2009 5:46 am Posts: 1523
|
 Re: problem with maze solve project
Yes, I wrote part of Windows. You are probably using it. Our FTC library is publicly available here. http://proj.titanrobotics.net/hg/Ftc/20 ... 68b/ftclibNotice how every module has a structure defined and every function in the module has the structure passed to it by reference. That's very similar to how object oriented languages such as C++ is used.
|
Thu Jun 07, 2012 1:27 am |
|
 |
Spiked3
Expert
Joined: Tue Feb 28, 2012 3:10 pm Posts: 197
|
 Re: problem with maze solve project
I'd have to say, I took a look at his library a little while ago and immediately said, woa, someone who knows what they are doing, that is rare in these days of open source. and me, being a lifelong pessimist, that's a pretty good endorsement. I hope to put as much thought and time in to the stuff I do.
_________________Mike aka Spiked3 http://www.spiked3.com
|
Thu Jun 07, 2012 3:19 am |
|
 |
MHTS
Guru
Joined: Sun Nov 15, 2009 5:46 am Posts: 1523
|
 Re: problem with maze solve project
Oh thank you. I found this library very useful in teaching kids some aspects of multi-tasking which is very important in robotics programming.
|
Thu Jun 07, 2012 12:12 pm |
|
|
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
|
|