检查主要If条件无法到达if和while时 [英] After checking main If condition unable to reach if and while
问题描述
从范围读取的硬件线程存储在beforeRightValue中。在此之前,无效的Motion :: _ Grid()车将停止2秒。有时值不匹配,所以我想计算错误值的时间然后我想重新定位。
Hardware reading from scope Thread stored in beforeRightValue. Before that is coming inside void Motion::_Grid() car will stop 2 seconds. Sometimes values will not match so that time I want to calculate error value then I want to make repositioning.
float degree_check; // calculating error value will store here.
我创建了4个条件。所有条件都将检查硬件(firstdataValue)和当前值(beforeRightValue)中的第一个存储值。如果发生任何差异将计算误差值(degree_check),那么汽车需要先移动相同的
度取决于误差度。
I have created 4 conditions. All condition will check first stored value from hardware (firstdataValue) and current value(beforeRightValue). If any difference happened that will calculate the error value (degree_check), then the car need to move same first degree depends upon the error degree.
工作正常。如果有条件的话就会进入内部。例如条件1如果,条件4如果打印。如果那是在主条件if条件下进入的,那么这个条件也只是真的,但是这不会进入这个if条件,而不是在
里面。我无法理解这个错误。
That is working fine. That is coming inside if condition. For example condition 1 if, condition 4 if printing. If that is coming inside of main if condition, this condition also true only, but that is not coming inside of this if condition, not inside of the while. I was unable to understand the mistake.
void Motion::_Grid()
{
float beforeRightValue = ScopeThread::data;
if((int)beforeRightValue != (int)firstdataValue)
{
float degree_check; // calculating error value will store here.
if(firstdataValue > 0 && beforeRightValue > 0)
{
degree_check = (firstdataValue)-(beforeRightValue);
if(degree_check > 0)
{
cout<<"condition 1 if : "<<degree_check<<endl;
if(!beforeRightValue == firstYawValue)
{
softPwmWrite(Motr2, 0);
softPwmWrite(Motr1, 0);
delay(200);
softPwmWrite(Motr1,5);
softPwmWrite(Motr2,0);
while(true)
{
cout<<"2nd while : "<<firstdataValue<<endl;
if(int(ScopeThread::data) == firstdataValue)
{
softPwmWrite(Motr2, 0);
softPwmWrite(Motr1, 0);
delay(2000);
break;
}
break;
}
}
}
}
}
}
推荐答案
在1/28/2018 6:45 AM,Syslvester写道:
On 1/28/2018 6:45 AM, Syslvester wrote:
if(!beforeRightValue == firstYawValue)
if(!beforeRightValue == firstYawValue)
这个条件毫无意义。它相当于if(firstYawValue == 0)。在beforeRightValue不为零之前,所以在布尔上下文中它是真的,它的布尔否定是假的,它被转换对于数值比较,它检查
变量firstYawValue,它在代码的其他地方从未出现过,之前或之后,所以不清楚它可能具有什么重要性。
This condition makes little sense. It's equivalent to if(firstYawValue == 0). beforeRightValue is not zero, so it's true in boolean context, its boolean negation is then false, which is converted to 0 for numerical comparisons. Also, it checks the variable firstYawValue, which never appears elsewhere in the code, before or after, so it's not clear what significance it might have.
while(true)
{
if(int(ScopeThread) :: data)== firstdat aValue)
while(true)
{
if(int(ScopeThread::data) == firstdataValue)
这看起来很可疑。你在比较的一边截断一个整数但在另一边截断不是 - 除非firstdataValue偶然碰巧是一个整数,否则这种比较不会成立。
This looks suspicious. You truncate to an integer on one side of the comparison but not on the other - that comparison won't be true unless firstdataValue just accidentally happens to be a whole number.
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;&NBSP;休息;
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;&NBSP; }
break;
}
你有一个`while`循环 - 但你在第一次迭代时无条件地突破它。您可以删除"while(true)"和两个"休息";行,而不改变代码的行为。
You have a `while` loop - but you break out of it unconditionally on the very first iteration. You can remove "while(true)" and the two "break;" lines, without changing the behavior of the code.
这篇关于检查主要If条件无法到达if和while时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!