View unanswered posts | View active topics It is currently Mon Oct 23, 2017 12:43 am






Reply to topic  [ 4 posts ] 
Function Return Value to Variable Error 
Author Message
Rookie

Joined: Wed Jan 20, 2016 11:31 am
Posts: 2
Post 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.


Wed Jan 20, 2016 12:07 pm
Profile
Moderator
Moderator

Joined: Tue May 19, 2015 3:07 pm
Posts: 91
Post 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.


Wed Jan 20, 2016 3:23 pm
Profile
Rookie

Joined: Wed Jan 20, 2016 11:31 am
Posts: 2
Post 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)


Wed Jan 20, 2016 9:43 pm
Profile
Moderator
Moderator

Joined: Tue May 19, 2015 3:07 pm
Posts: 91
Post 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.


Wed Feb 03, 2016 5:15 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

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

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.