Why isn't my millis() function working?

Thread Starter

John A Bonilla

Joined Mar 11, 2017
92
Hello everyone,

I am working on this project where I have built a robot that will travel through a maze. The maze has lines in it so that it becomes a grid pattern as shown:

upload_2018-5-1_19-34-0.png

The entire maze has these grid line on the floor, and the bolder lines are the walls. I am using line sensors to find these lines so that the robot knows its position throughout the maze, and can properly orient itself. There are two line sensors on either side of the robot, and if it is off it takes into account the different times when the two sensors see the line. However, this is where the problem takes place. When reviewing my code I tried to account for all different issues that I may face, and when testing it I found the issue to be the millis() function. Everything up to when the robot is suppose to record the time was working, and thereby disrupting my code. My entire code is linked below, along with another file that has a working model of the millis() function. If anyone has any suggestions or solutions, it would be extremely helpful. Another thing I ask is if you can review my code just in case I may have missed something. I would like to thank everyone for their help in advance!
 

Attachments

Raymond Genovese

Joined Mar 5, 2016
1,653
Hello everyone,

I am working on this project where I have built a robot that will travel through a maze. The maze has lines in it so that it becomes a grid pattern as shown:

View attachment 151723

The entire maze has these grid line on the floor, and the bolder lines are the walls. I am using line sensors to find these lines so that the robot knows its position throughout the maze, and can properly orient itself. There are two line sensors on either side of the robot, and if it is off it takes into account the different times when the two sensors see the line. However, this is where the problem takes place. When reviewing my code I tried to account for all different issues that I may face, and when testing it I found the issue to be the millis() function. Everything up to when the robot is suppose to record the time was working, and thereby disrupting my code. My entire code is linked below, along with another file that has a working model of the millis() function. If anyone has any suggestions or solutions, it would be extremely helpful. Another thing I ask is if you can review my code just in case I may have missed something. I would like to thank everyone for their help in advance!

High John, glad to see you plugging away at this project. I Haven't gone through all of your code, but here is one red flag...

In parts where you have (for example)...

if(readQD0() >= X)
{
Time1 == millis(); //Time when sensor one sees the line
Derivative = Derivative + 1; //Determines the inner fuction
X = 4000;
}

change this
Time1 == millis(); //Time when sensor one sees the line
to
Time1 = millis(); //Time when sensor one sees the line

Everywhere that you have the "equal to" vs "assignment" confusion"
 

xox

Joined Sep 8, 2017
838
Some parts of your code are using the equivalence operator instead of the one for variable assignment.

Code:
Time1 == millis(); //Time when sensor one sees the line
 

Thread Starter

John A Bonilla

Joined Mar 11, 2017
92
High John, glad to see you plugging away at this project. I Haven't gone through all of your code, but here is one red flag...

In parts where you have (for example)...

if(readQD0() >= X)
{
Time1 == millis(); //Time when sensor one sees the line
Derivative = Derivative + 1; //Determines the inner fuction
X = 4000;
}

change this
Time1 == millis(); //Time when sensor one sees the line
to
Time1 = millis(); //Time when sensor one sees the line

Everywhere that you have the "equal to" vs "assignment" confusion"
Some parts of your code are using the equivalence operator instead of the one for variable assignment.

Code:
Time1 == millis(); //Time when sensor one sees the line
I very much appreciate the help both of you have given me.I will fix my mistake, and then crossing my fingers, I'm hoping that everything else works. If anything comes up I will be sure to reply to the both of you once again. I can't believe that I made that mistake lol.
 

Thread Starter

John A Bonilla

Joined Mar 11, 2017
92
heh beat ya by 60,000 millis :)
So everything worked, however I now have another issue. In my code I have to take the inverse tangent function of a fraction thereby spewing out a decimal, however integers do not work. What would I use so that the arduino stores the decimal value instead of just the integer?
 

Raymond Genovese

Joined Mar 5, 2016
1,653
So everything worked, however I now have another issue. In my code I have to take the inverse tangent function of a fraction thereby spewing out a decimal, however integers do not work. What would I use so that the arduino stores the decimal value instead of just the integer?
Take a look at this thread, and particularly post #5:

http://forum.arduino.cc/index.php?topic=160216.0

...and a general search like this one:

https://www.google.com/search?clien...j33i22i29i30k1j33i160k1j33i21k1.0.WEAGutpd4po
 

Thread Starter

John A Bonilla

Joined Mar 11, 2017
92
So i found my main issue with the code, the arduino won't proccess a dividing function, so if I do,

double calc = 100/900;

instead of calculating 0.11, it just makes calc = to 0. If anyone has a solution I would be very thankful
 
So i found my main issue with the code, the arduino won't proccess a dividing function, so if I do,

double calc = 100/900;

instead of calculating 0.11, it just makes calc = to 0. If anyone has a solution I would be very thankful
Dividing two integer values gives an integer result. Change the code to:
double calc = 100.0/900.0;
or
double calc = (double)100/(double)900;

For example, run this:
C:
void  setup(){
Serial.begin(9600);
}

void loop(){

double result;

result=100/900;
Serial.print("100/900=");
Serial.println(result);

result=100.0/900.0;
Serial.print("100.0/900.0=");
Serial.println(result);

result=(double)100/(double)900;
Serial.print("(double)100/(double)900=");
Serial.println(result);

here: goto here;
}
..and you will see this output:
Code:
100/900=0.00
100.0/900.0=0.11
(double)100/(double)900=0.11
 
Last edited:

Thread Starter

John A Bonilla

Joined Mar 11, 2017
92
Dividing two integer values gives an integer result. Change the code to:
double calc = 100.0/900.0;
or
double calc = (double)100/(double)900;

For example, run this:
C:
void  setup(){
Serial.begin(9600);
}

void loop(){

double result;

result=100/900;
Serial.print("100/900=");
Serial.println(result);

result=100.0/900.0;
Serial.print("100.0/900.0=");
Serial.println(result);

result=(double)100/(double)900;
Serial.print("(double)100/(double)900=");
Serial.println(result);

here: goto here;
}
..and you will see this output:
Code:
100/900=0.00
100.0/900.0=0.11
(double)100/(double)900=0.11
Thank you for the quick response, I was able to solve it with this!
 
Top