ROBOTC.net forums
http://www.robotc.net/forums/

Function Return Value to Variable Error
http://www.robotc.net/forums/viewtopic.php?f=11&t=13192
Page 1 of 1

Author:  maxvit99 [ Wed Jan 20, 2016 12:07 pm ]
Post subject:  Function Return Value to Variable Error

Hi, I am using a third party sensor (UVTron Flame Sensor) that outputs a number of pulses per second. It's pulses of 100 milliseconds and the value from the sensor during that time is 1. The rest of the time it's 0. So it's basically like a touch sensor.

I have to do different things depending on how many pulses there are per second (there can be 0 to 10 depending on the flame and distance to it). For this, I have to count the number of "tushes" the sensor sends. I wrote some test code, but the problem is in the function. The compiler says that:

Code:
**Error**:Undefined procedure 'numPulse'.
*Warning*:Unreferenced function 'numPulse'


numPulse is the name of the function that counts the number of pulses per second. Just in case, the code is this:

Code:
#pragma config(Sensor, dgtl8,  UVTron,         sensorTouch)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main()
{
   clearLCDLine(0);
   //int tmp = numPulse(2);  //Test of setting the numPulse Return Value to Varable
   displayLCDNumber(0, 0, numPulse(2));
}

int numPulse(int secReps) //Conts # of UVTron Pulses/Sec
{
   int j = 0;
   while(j <= secReps)
   {
      j++;
      int pulseSec = 0;
      clearTimer(T1);
      while(time1[T1] < 1000)
      {
         waitUntil(SensorValue(UVTron) == 1);
         pulseSec++;
         waitUntil(SensorValue(UVTron) == 0);
      }
      return pulseSec;
   }
}


I hope you guys can help me. Also, I would think that there would be a function to do this, but I couldn't find it, so if anyone knows it, please tell me.

Thank you.

Author:  Tabor473 [ Wed Jan 20, 2016 3:23 pm ]
Post subject:  Re: Function Return Value to Variable Error

So the change you need to make it work is move the function declaration of numPulses to be above void main.
The computer hasn't heard of the function numPulses by the time it sees you use it for the first time.

Author:  maxvit99 [ Wed Jan 20, 2016 9:43 pm ]
Post subject:  Re: Function Return Value to Variable Error

It works! Thank you so much!
So, is there a function to do this automatically? (a push counter, or something similar)

Author:  Tabor473 [ Wed Feb 03, 2016 5:15 pm ]
Post subject:  Re: Function Return Value to Variable Error

maxvit99 wrote:
It works! Thank you so much!
So, is there a function to do this automatically? (a push counter, or something similar)

So there would be a way to do it using built in functions. If you declared it as a single wire encoder in the motor and sensor setup and every second you check sensorValue[pulses] and then set it to be 0. This run a lot faster because the incrementing is done on a hardware level(could handle thousands of pulses per second). In your case it is probably not needed and would unintuitive as to why it works without a proper understanding of how encoders work. Your solution is the simplest and should never really have problems with 100 ms pulses.

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/