大家好,我已经写了一些代码,看一个称为位置的子例程的输出,它返回一个浮点P。这个浮标被与一个叫做FRORORSELSET子程序的其他输入进行比较,我让这些FroRoSLead选项对应于浮点(F1,F2和F3)。其中,“地板”P最接近.FY.位置子程序是ADC中的一个输出,并将其转换成米的测量值。在构建时,我得到了下面的“非空洞函数结束时的隐式返回”。ENT if语句。代码是相当基本的,可以更流利的提示,将不胜感激。
以上来自于百度翻译
以下为原文
Hello All,
I have written some code, to look at the output of a subrou
tine called position, which returns a float p.
This float is compared to other input from a subroutine called floor_select, I have made these floor_select options correspond to floats (f1,f2 and f3) .
A calculation is made to determine which "floor" the p is closest to.
FYI the position subroutine is an out put from an ADC and converts its to a measurement in meters.
I have been getting the following when building,
"Implicit return at end of non-void function"
I have a general understanding that it might be do to with the 3 different if statements.
The code is fairly basic and could be more eloquent
Any hints would be greatly appreciated.
short Floor_Comparision (float p)
{
position; //Runs position subroutine to gain a value of the float "p"
float diff; //Float "diff" being the difference between selected floor and position "p"
short w;
int floor_selected;
float floor_level;
//Tolerance and Individual Floor Floats
float tole = 0.0125; //Allowable tolerance difference of +/- 0.0125 meters
float f1 = 0.0000; //Floor 1 Float of 0.0000 Meters
float f2 = 3.0000; //Floor 2 Float of 3.0000 Meters
float f3 = 6.0000; //Floor 3 Float of 6.0000 Meters
//For the particular floor_select short int
//A corresponding "floor_level" is given as a float
if (floor_selected == 1)
{
floor_level == f1;
}
if (floor_selected == 2)
{
floor_level == f2;
}
if (floor_selected == 3)
{
floor_level == f3;
}
//Comparison Calculation
floor_level - p == diff; //Requested floor height - current height = difference in height
//Either a positive or negative number
if (diff > 0.125) //If Difference is greater than +0.0125m
{ //Requested floor height is higher current position
w = 1; //Set w =1 (Lift Run and Up-wards )
return w;
}
if (diff < -0.125) //If Difference is less than -0.0125m
{ //Requested floor height is lower current position
w = 2; //Set w =2 (Lift Run and Down-wards )
return w;
}
if (-0.125 <= diff <= 0.125) //If Difference is greater than or equal to -0.0125m
{ //Or Difference is less than or equal to +0.0125m
w = 0; //Set w =0 (Lift Stop)
return w;
}
}