Author |
Message |
fxlj007
Rookie
Joined: Sun Jun 17, 2012 11:18 am Posts: 26
|
 Pass a sensor as an argument?
Is is possible to pass a sensor as an argument to a function? If yes how to declare the type of the parameters?
|
Mon Sep 17, 2012 1:41 pm |
|
 |
JohnWatson
Site Admin
Joined: Thu May 24, 2012 12:15 pm Posts: 722
|
 Re: Pass a sensor as an argument?
You should be able to pass sensor values as parameters to a function. For example: You have to make sure that the data type you are sending up matches what is required for the function (in this case, 'int'; 'bool' would also work). You also have to make sure that you are sending the value of the sensor (by using the SensorValue command) and not the index of the sensor: The above code will compile but will pass the index location of the 'touch1' sensor, not the actual value of it.
_________________Check out our Blog! And our Facebook page! Need help? Take a look at our updated help documentation and the ROBOTC Forums.
|
Mon Sep 17, 2012 1:58 pm |
|
 |
MHTS
Guru
Joined: Sun Nov 15, 2009 5:46 am Posts: 1523
|
 Re: Pass a sensor as an argument?
I am not sure that's what he's asking. I thought he's asking if you can pass the sensor ID to a function. If so, yes, the type for it is tSensors. EDIT: fixed the spelling of tSensors in the code.
Last edited by MHTS on Mon Sep 17, 2012 3:40 pm, edited 2 times in total.
|
Mon Sep 17, 2012 2:03 pm |
|
 |
fxlj007
Rookie
Joined: Sun Jun 17, 2012 11:18 am Posts: 26
|
 Re: Pass a sensor as an argument?
>>JohnWatson: Sorry that I didn't express my question clearly. MHTS gets my question. Still it's very nice of you  >>MHTS: I tried to compile your codes but it yields below compilation errors. Is there anything wrong? Or with the software version? File "tSensorTest.c" compiled on Sep 18 2012 02:48:32 **Error**:Variable 'tSensor' declaration must be qualified with type. Type 'short' used. **Error**:Ummatched left parenthesis '(' **Error**:Expected->')'. Found 'sensorID' **Error**:No body declared for procedure **Error**:Expected->'}'. Found 'sensorID' **Error**:Undefined variable 'sensorID'. 'short' assumed. **Error**:Missing ';' before ')' **Error**:Executable statements not valid in 'main' declaration block **Error**:Unexpected scanner token-> ')' *Warning*:Meaningless statement -- no code generated **Error**:Duplicate definition for task 'main'.
|
Mon Sep 17, 2012 2:51 pm |
|
 |
MHTS
Guru
Joined: Sun Nov 15, 2009 5:46 am Posts: 1523
|
 Re: Pass a sensor as an argument?
I am sorry, I don't have RobotC in front of me. So I told you the wrong spelling. It should be tSensors not tSensor. Sorry about that.
|
Mon Sep 17, 2012 3:32 pm |
|
 |
mightor
Site Admin
Joined: Wed Mar 05, 2008 8:14 am Posts: 3654 Location: Rotterdam, The Netherlands
|
 Re: Pass a sensor as an argument?
Do you have the NXT set as the platform to compile for?
- Xander
_________________| Professional Conduit of Reasonableness| (Title bestowed upon on the 8th day of November, 2013) | My Blog: I'd Rather Be Building Robots| ROBOTC 3rd Party Driver Suite: [ Project Page]
|
Tue Sep 18, 2012 1:25 am |
|
 |
fxlj007
Rookie
Joined: Sun Jun 17, 2012 11:18 am Posts: 26
|
 Re: Pass a sensor as an argument?
Dear All,
Case settled. Thanks for your help.
Btw, I'm using RobotC 3.5 and a set of NXT for my undergraduate project. Can you recommend some material that introduces more advanced stuff of RobotC? The curriculum on RobotC's website seems a little too "basic" for me LOL~~
|
Tue Sep 18, 2012 10:06 am |
|
 |
Spiked3
Expert
Joined: Tue Feb 28, 2012 3:10 pm Posts: 197
|
 Re: Pass a sensor as an argument?
More advanced stuff? Programming wise or robot wise? C is (kinda) C. There are lots of books on that subject. Robot wise; There is not anything I know of, published as a book, it has been discussed. http://botbench.com/blog/ publishes code, as do I http://www.spiked3.com/I often find very good stuff from http://nxttime.wordpress.com/Other than that, google is your friend.
_________________Mike aka Spiked3 http://www.spiked3.com
|
Tue Sep 18, 2012 11:39 am |
|
 |
JohnWatson
Site Admin
Joined: Thu May 24, 2012 12:15 pm Posts: 722
|
 Re: Pass a sensor as an argument?
I would also suggest checking out our wiki ( https://www.robotc.net/wiki) for advanced programming material. We are continually adding to and updating it (we recently added overviews on pointers and recursion, for example). It also has a ' Programming Tips and Tricks' section that starts to dive into the more advanced features of ROBOTC with topics such as multitaskingand fuzzy logic being covered. Plus, most of the information is provided by the ROBOTC community members. If anyone has anything they would like to add or like to see added to the wiki, please do not hesitate to let me know!
_________________Check out our Blog! And our Facebook page! Need help? Take a look at our updated help documentation and the ROBOTC Forums.
|
Tue Sep 18, 2012 12:19 pm |
|
 |
roboRed
Expert
Joined: Fri Nov 02, 2012 12:07 am Posts: 163 Location: California, USA
|
 Re: Pass a sensor as an argument?
_________________ string Robored = "Awesome" ~~Neil Balch~~
|
Sat Dec 15, 2012 11:34 pm |
|
 |
roboRed
Expert
Joined: Fri Nov 02, 2012 12:07 am Posts: 163 Location: California, USA
|
 Re: Pass a sensor as an argument?
I mean also real world applications of this structure? thanks 
_________________ string Robored = "Awesome" ~~Neil Balch~~
|
Sat Dec 15, 2012 11:35 pm |
|
|