Values arbitrarily won't print to serial monitor

borisaurus
Posts: 1
Joined: Sat Jan 14, 2017 8:49 pm

Values arbitrarily won't print to serial monitor

Postby borisaurus » Sat Jan 14, 2017 9:14 pm

Using the Arduino IDE to program the esp32 thing.

This is one example of the values not printing to serial monitor, that is, none of the values, not just certain ones. In this case, the logical statement in bold is desired to be "dtheta < 5". No values print out if this is included, however, values will print if this statement is changed to "dtheta-5<0". This is logically equivalent, but its just excessive and seems silly. I'm actually amazed this change worked. The code is below.

There was another instance where two raw sensor values would not print to serial monitor. I added another "Serial.println("something");" directly preceding it, and then all three values printed. What is going on here??

VALUES WILL PRINT TO SERIAL MONITOR WITH THE FOLLOWING CODE:
(emboldened is the focus of this issue)

void loop() {

double A = (mysensor.angleR(U_DEG, false)); //previous encoder reading in degrees
double B = (mysensor.angleR(U_DEG, true)); //current encoder reading in degrees
double dtheta = 0;
double rvelocity = 0;
int samp = 10; //initialize change in angle variable, velocity, and sample delay time


if(A > B){ //handles zero crossing edge case when one old angle
dtheta = (360-A)+B; //is larger than new angle i.e. 355 deg, 25 deg.
}
else{
dtheta = B-A;
}

if(dtheta > 355 || dtheta-5 < 0){
dtheta=0;
}

rvelocity = (dtheta/360)*(60000/(samp)); //calculate rotational velocity in rpm
Serial.println(rvelocity);

delay(samp);

}


VALUES WILL NOT PRINT IF THE EMBOLDENED STATEMENT IS CHANGED TO DTHETA<5.

User avatar
Frida854
Posts: 14
Joined: Sat Dec 24, 2016 11:51 am
Location: Middelfart, Denmark

Re: Values arbitrarily won't print to serial monitor

Postby Frida854 » Sun Jan 15, 2017 1:16 pm

Code: Select all

if(dtheta > 355 || dtheta-5 < 0){
Have you tryed:

Code: Select all

if( (dtheta > 355) || (dtheta<5) ){
Yes Frida is my watchdog!

Who is online

Users browsing this forum: No registered users and 56 guests