\hypertarget{group__lowerlevelusmeths}{}\section{Methods}
\label{group__lowerlevelusmeths}\index{Methods@{Methods}}
\subsection*{Functions}
\begin{DoxyCompactItemize}
\item 
unsigned long \hyperlink{group__lowerlevelusmeths_ga5f034198a28b069478c454c63dbfa225}{Code\+Racer\+::usonic\+\_\+measure\+\_\+cm} ()
\begin{DoxyCompactList}\small\item\em Measures the distance to the next object in front of the ultra sonic sensor in cm. \end{DoxyCompactList}\item 
unsigned long \hyperlink{group__lowerlevelusmeths_gaa01602a576fd57609bc7e08f8ef32e58}{Code\+Racer\+::usonic\+\_\+measure\+\_\+us} ()
\begin{DoxyCompactList}\small\item\em Measures the distance to the next object in front of the ultra sonic sensor in microseconds. \end{DoxyCompactList}\item 
unsigned long \hyperlink{group__lowerlevelusmeths_gafdd5c75d7a8e7b7c993e512ee93dde9a}{Code\+Racer\+::usonic\+\_\+measure\+\_\+cm} (unsigned long max\+\_\+echo\+\_\+run\+\_\+time\+\_\+us)
\begin{DoxyCompactList}\small\item\em Measures the distance to the next object in front of the ultra sonic sensor in cm. \end{DoxyCompactList}\item 
unsigned long \hyperlink{group__lowerlevelusmeths_ga1f3401ef472cb11997e7dc98ef3e2424}{Code\+Racer\+::usonic\+\_\+measure\+\_\+us} (unsigned long max\+\_\+echo\+\_\+run\+\_\+time\+\_\+us)
\begin{DoxyCompactList}\small\item\em Measures the distance to the next object in front of the ultra sonic sensor in microseconds. \end{DoxyCompactList}\item 
unsigned long \hyperlink{group__lowerlevelusmeths_ga0c00edbbf4a3169613c9ea84d6e7dc13}{Code\+Racer\+::usonic\+\_\+measure\+\_\+single\+\_\+shot\+\_\+cm} ()
\begin{DoxyCompactList}\small\item\em Measures the distance to the next object in front of the ultra sonic sensor in cm. \end{DoxyCompactList}\item 
unsigned long \hyperlink{group__lowerlevelusmeths_gad4309b6da17085575fb0c55559e240b8}{Code\+Racer\+::usonic\+\_\+measure\+\_\+single\+\_\+shot\+\_\+us} ()
\begin{DoxyCompactList}\small\item\em Measures the distance to the next object in front of the ultra sonic sensor in microseconds. \end{DoxyCompactList}\item 
unsigned long \hyperlink{group__lowerlevelusmeths_gab413551ea8a67e1b60eda1671029b645}{Code\+Racer\+::usonic\+\_\+measure\+\_\+single\+\_\+shot\+\_\+cm} (unsigned long max\+\_\+echo\+\_\+run\+\_\+time\+\_\+us)
\begin{DoxyCompactList}\small\item\em Measures the distance to the next object in front of the ultra sonic sensor in cm. \end{DoxyCompactList}\item 
unsigned long \hyperlink{group__lowerlevelusmeths_ga1b5b43372082f5daeee47410a09a590c}{Code\+Racer\+::usonic\+\_\+measure\+\_\+single\+\_\+shot\+\_\+us} (unsigned long max\+\_\+echo\+\_\+run\+\_\+time\+\_\+us)
\begin{DoxyCompactList}\small\item\em Measures the distance to the next object in front of the ultra sonic sensor in microseconds. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Detailed Description}


\subsection{Function Documentation}
\mbox{\Hypertarget{group__lowerlevelusmeths_ga5f034198a28b069478c454c63dbfa225}\label{group__lowerlevelusmeths_ga5f034198a28b069478c454c63dbfa225}} 
\index{Methods@{Methods}!usonic\+\_\+measure\+\_\+cm@{usonic\+\_\+measure\+\_\+cm}}
\index{usonic\+\_\+measure\+\_\+cm@{usonic\+\_\+measure\+\_\+cm}!Methods@{Methods}}
\subsubsection{\texorpdfstring{usonic\+\_\+measure\+\_\+cm()}{usonic\_measure\_cm()}\hspace{0.1cm}{\footnotesize\ttfamily [1/2]}}
{\footnotesize\ttfamily unsigned long Code\+Racer\+::usonic\+\_\+measure\+\_\+cm (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})}



Measures the distance to the next object in front of the ultra sonic sensor in cm. 

This is the medium one out of 3 measurements. The maximum measured distance is about 100cm and defined by the U\+S\+\_\+\+M\+A\+X\+\_\+\+E\+C\+H\+O\+\_\+\+T\+I\+M\+E\+\_\+\+US setting in the header file. \begin{DoxyReturn}{Returns}
The measured distance in cm. 
\end{DoxyReturn}


Definition at line 672 of file Code\+Racer.\+cpp.


\begin{DoxyCode}
673 \{
674     \textcolor{keywordflow}{return}(usonic\_measure\_cm(US\_MAX\_ECHO\_TIME\_US));
675 \}
\end{DoxyCode}
\mbox{\Hypertarget{group__lowerlevelusmeths_gaa01602a576fd57609bc7e08f8ef32e58}\label{group__lowerlevelusmeths_gaa01602a576fd57609bc7e08f8ef32e58}} 
\index{Methods@{Methods}!usonic\+\_\+measure\+\_\+us@{usonic\+\_\+measure\+\_\+us}}
\index{usonic\+\_\+measure\+\_\+us@{usonic\+\_\+measure\+\_\+us}!Methods@{Methods}}
\subsubsection{\texorpdfstring{usonic\+\_\+measure\+\_\+us()}{usonic\_measure\_us()}\hspace{0.1cm}{\footnotesize\ttfamily [1/2]}}
{\footnotesize\ttfamily unsigned long Code\+Racer\+::usonic\+\_\+measure\+\_\+us (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})}



Measures the distance to the next object in front of the ultra sonic sensor in microseconds. 

This is the medium one out of 3 measurements. The maximum measured distance is about 6000 microseconds and defined by the U\+S\+\_\+\+M\+A\+X\+\_\+\+E\+C\+H\+O\+\_\+\+T\+I\+M\+E\+\_\+\+US setting in the header file. \begin{DoxyReturn}{Returns}
The measured distance in microseconds. 
\end{DoxyReturn}


Definition at line 682 of file Code\+Racer.\+cpp.


\begin{DoxyCode}
683     \{
684         \textcolor{keywordflow}{return}(usonic\_measure\_us(US\_MAX\_ECHO\_TIME\_US));
685     \}
\end{DoxyCode}
\mbox{\Hypertarget{group__lowerlevelusmeths_gafdd5c75d7a8e7b7c993e512ee93dde9a}\label{group__lowerlevelusmeths_gafdd5c75d7a8e7b7c993e512ee93dde9a}} 
\index{Methods@{Methods}!usonic\+\_\+measure\+\_\+cm@{usonic\+\_\+measure\+\_\+cm}}
\index{usonic\+\_\+measure\+\_\+cm@{usonic\+\_\+measure\+\_\+cm}!Methods@{Methods}}
\subsubsection{\texorpdfstring{usonic\+\_\+measure\+\_\+cm()}{usonic\_measure\_cm()}\hspace{0.1cm}{\footnotesize\ttfamily [2/2]}}
{\footnotesize\ttfamily unsigned long Code\+Racer\+::usonic\+\_\+measure\+\_\+cm (\begin{DoxyParamCaption}\item[{unsigned long}]{max\+\_\+echo\+\_\+run\+\_\+time\+\_\+us }\end{DoxyParamCaption})}



Measures the distance to the next object in front of the ultra sonic sensor in cm. 

This is the medium one out of 3 measurements. Be careful with high values for max\+\_\+echo\+\_\+run\+\_\+time\+\_\+us -\/ this may increase run time due to the fact that if there is nothing in range of the sensor it will wait until this specified run time of the echo is over. The maximum range the sensor is specified for is about 300cm. 
\begin{DoxyParams}{Parameters}
{\em max\+\_\+echo\+\_\+run\+\_\+time\+\_\+us} & Defines the maximum echo run time and by that the maximum of distance that can be measured. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The measured distance in cm. 
\end{DoxyReturn}


Definition at line 694 of file Code\+Racer.\+cpp.


\begin{DoxyCode}
695 \{
696     \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{long} echo\_runtime\_us = usonic\_measure\_us(max\_echo\_run\_time\_us);
697     \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{long} distance\_cm = echo\_runtime\_us * 0.0172;
698     \textcolor{comment}{//Serial.print("MEASURE\_DISTANCE. Distance in cm is: ");}
699     \textcolor{comment}{//Serial.println(distance\_cm);}
700     \_usonic\_distance\_cm = distance\_cm;
701     \textcolor{keywordflow}{return}(distance\_cm);
702 \}
\end{DoxyCode}
\mbox{\Hypertarget{group__lowerlevelusmeths_ga1f3401ef472cb11997e7dc98ef3e2424}\label{group__lowerlevelusmeths_ga1f3401ef472cb11997e7dc98ef3e2424}} 
\index{Methods@{Methods}!usonic\+\_\+measure\+\_\+us@{usonic\+\_\+measure\+\_\+us}}
\index{usonic\+\_\+measure\+\_\+us@{usonic\+\_\+measure\+\_\+us}!Methods@{Methods}}
\subsubsection{\texorpdfstring{usonic\+\_\+measure\+\_\+us()}{usonic\_measure\_us()}\hspace{0.1cm}{\footnotesize\ttfamily [2/2]}}
{\footnotesize\ttfamily unsigned long Code\+Racer\+::usonic\+\_\+measure\+\_\+us (\begin{DoxyParamCaption}\item[{unsigned long}]{max\+\_\+echo\+\_\+run\+\_\+time\+\_\+us }\end{DoxyParamCaption})}



Measures the distance to the next object in front of the ultra sonic sensor in microseconds. 

This is the medium one out of 3 measurements. Be careful with high values for max\+\_\+echo\+\_\+run\+\_\+time\+\_\+us -\/ this may increase run time due to the fact that if there is nothing in range of the sensor it will wait until this specified run time of the echo is over. The maximum range the sensor is specified for is about 300cm. 
\begin{DoxyParams}{Parameters}
{\em max\+\_\+echo\+\_\+run\+\_\+time\+\_\+us} & Defines the maximum echo run time in microseconds and by that the maximum of distance that can be measured. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The measured distance in microseconds. 
\end{DoxyReturn}


Definition at line 711 of file Code\+Racer.\+cpp.


\begin{DoxyCode}
712 \{
713     \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{long} echo\_runtime\_us[3] = \{ 0,0,0 \};
714     uint8\_t measnr = 0;
715 
716     \textcolor{keywordflow}{do} \{
717         echo\_runtime\_us[measnr] = usonic\_measure\_single\_shot\_us(max\_echo\_run\_time\_us);
718         \textcolor{keywordflow}{if} (echo\_runtime\_us[measnr] > 200) \{
719             measnr++;
720         \}
721     \} \textcolor{keywordflow}{while} (measnr < 3);
722 
723     \textcolor{comment}{// we will take the medium out of 3 values ... }
724     \textcolor{keywordflow}{if} (echo\_runtime\_us[0] > echo\_runtime\_us[1]) \{ std::swap(echo\_runtime\_us[0], echo\_runtime\_us[1]); \}
725     \textcolor{keywordflow}{if} (echo\_runtime\_us[1] > echo\_runtime\_us[2]) \{ std::swap(echo\_runtime\_us[1], echo\_runtime\_us[2]); \}
726     \textcolor{keywordflow}{if} (echo\_runtime\_us[0] > echo\_runtime\_us[1]) \{ std::swap(echo\_runtime\_us[0], echo\_runtime\_us[1]); \}
727 
728     \textcolor{comment}{//Serial.print("MEASURE\_DISTANCE\_US. Echo runtime in us is: ");}
729     \textcolor{comment}{//Serial.println(echo\_runtime\_us[1]);}
730 
731     \textcolor{comment}{// if the stop at minimal distance is enabeled - check for minimal distance is reached}
732     \textcolor{keywordflow}{if} (\textcolor{keyword}{true} == \_coderacer\_stop\_at\_distance\_enabled) \{
733         \textcolor{keywordflow}{if} (echo\_runtime\_us[1] <= \_usonic\_stop\_distance\_us) \{
734             \_coderacer\_stopped\_at\_min\_distance = \textcolor{keyword}{true};
735             stop\_driving();
736             \_coderacer\_stop\_at\_distance\_enabled = \textcolor{keyword}{false};
737         \}
738     \}
739     \_usonic\_distance\_us = echo\_runtime\_us[1];
740     \textcolor{keywordflow}{return}(echo\_runtime\_us[1]);
741 \}
\end{DoxyCode}
\mbox{\Hypertarget{group__lowerlevelusmeths_ga0c00edbbf4a3169613c9ea84d6e7dc13}\label{group__lowerlevelusmeths_ga0c00edbbf4a3169613c9ea84d6e7dc13}} 
\index{Methods@{Methods}!usonic\+\_\+measure\+\_\+single\+\_\+shot\+\_\+cm@{usonic\+\_\+measure\+\_\+single\+\_\+shot\+\_\+cm}}
\index{usonic\+\_\+measure\+\_\+single\+\_\+shot\+\_\+cm@{usonic\+\_\+measure\+\_\+single\+\_\+shot\+\_\+cm}!Methods@{Methods}}
\subsubsection{\texorpdfstring{usonic\+\_\+measure\+\_\+single\+\_\+shot\+\_\+cm()}{usonic\_measure\_single\_shot\_cm()}\hspace{0.1cm}{\footnotesize\ttfamily [1/2]}}
{\footnotesize\ttfamily unsigned long Code\+Racer\+::usonic\+\_\+measure\+\_\+single\+\_\+shot\+\_\+cm (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})}



Measures the distance to the next object in front of the ultra sonic sensor in cm. 

This is a one shot measurement. The maximum measured distance is about 6000 microseconds and defined by the U\+S\+\_\+\+M\+A\+X\+\_\+\+E\+C\+H\+O\+\_\+\+T\+I\+M\+E\+\_\+\+US setting in the header file. \begin{DoxyReturn}{Returns}
The measured distance in cm. 
\end{DoxyReturn}


Definition at line 748 of file Code\+Racer.\+cpp.


\begin{DoxyCode}
749 \{
750     \textcolor{keywordflow}{return}(usonic\_measure\_single\_shot\_cm(US\_MAX\_ECHO\_TIME\_US));
751 \}
\end{DoxyCode}
\mbox{\Hypertarget{group__lowerlevelusmeths_gad4309b6da17085575fb0c55559e240b8}\label{group__lowerlevelusmeths_gad4309b6da17085575fb0c55559e240b8}} 
\index{Methods@{Methods}!usonic\+\_\+measure\+\_\+single\+\_\+shot\+\_\+us@{usonic\+\_\+measure\+\_\+single\+\_\+shot\+\_\+us}}
\index{usonic\+\_\+measure\+\_\+single\+\_\+shot\+\_\+us@{usonic\+\_\+measure\+\_\+single\+\_\+shot\+\_\+us}!Methods@{Methods}}
\subsubsection{\texorpdfstring{usonic\+\_\+measure\+\_\+single\+\_\+shot\+\_\+us()}{usonic\_measure\_single\_shot\_us()}\hspace{0.1cm}{\footnotesize\ttfamily [1/2]}}
{\footnotesize\ttfamily unsigned long Code\+Racer\+::usonic\+\_\+measure\+\_\+single\+\_\+shot\+\_\+us (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})}



Measures the distance to the next object in front of the ultra sonic sensor in microseconds. 

This is a one shot measurement. The maximum measured distance is about 6000 microseconds and defined by the U\+S\+\_\+\+M\+A\+X\+\_\+\+E\+C\+H\+O\+\_\+\+T\+I\+M\+E\+\_\+\+US setting in the header file. \begin{DoxyReturn}{Returns}
The measured distance in microseconds. 
\end{DoxyReturn}


Definition at line 758 of file Code\+Racer.\+cpp.


\begin{DoxyCode}
759 \{
760     \textcolor{keywordflow}{return}(usonic\_measure\_single\_shot\_us(US\_MAX\_ECHO\_TIME\_US));
761 \}
\end{DoxyCode}
\mbox{\Hypertarget{group__lowerlevelusmeths_gab413551ea8a67e1b60eda1671029b645}\label{group__lowerlevelusmeths_gab413551ea8a67e1b60eda1671029b645}} 
\index{Methods@{Methods}!usonic\+\_\+measure\+\_\+single\+\_\+shot\+\_\+cm@{usonic\+\_\+measure\+\_\+single\+\_\+shot\+\_\+cm}}
\index{usonic\+\_\+measure\+\_\+single\+\_\+shot\+\_\+cm@{usonic\+\_\+measure\+\_\+single\+\_\+shot\+\_\+cm}!Methods@{Methods}}
\subsubsection{\texorpdfstring{usonic\+\_\+measure\+\_\+single\+\_\+shot\+\_\+cm()}{usonic\_measure\_single\_shot\_cm()}\hspace{0.1cm}{\footnotesize\ttfamily [2/2]}}
{\footnotesize\ttfamily unsigned long Code\+Racer\+::usonic\+\_\+measure\+\_\+single\+\_\+shot\+\_\+cm (\begin{DoxyParamCaption}\item[{unsigned long}]{max\+\_\+echo\+\_\+run\+\_\+time\+\_\+us }\end{DoxyParamCaption})}



Measures the distance to the next object in front of the ultra sonic sensor in cm. 

This is a one shot measurement. Be careful with high values for max\+\_\+echo\+\_\+run\+\_\+time\+\_\+us -\/ this may increase run time due to the fact that if there is nothing in range of the sensor it will wait until this specified run time of the echo is over. The maximum range the sensor is specified for is about 300cm. 
\begin{DoxyParams}{Parameters}
{\em max\+\_\+echo\+\_\+run\+\_\+time\+\_\+us} & Defines the maximum echo run time in microseconds and by that the maximum of distance that can be measured. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The measured distance in cm. 
\end{DoxyReturn}


Definition at line 770 of file Code\+Racer.\+cpp.


\begin{DoxyCode}
771 \{
772     \textcolor{comment}{// convert into cm ... 344m/sec is the speed of noise - thus 34400cm/sec ... or 34,400cm/milisec ... or
       0,0344cm/microsec}
773     \textcolor{comment}{// the echo has to go the distance twice - forth and back - so the duration has to be the half of the
       measured one}
774     \textcolor{comment}{// distance\_cm = echo\_duration/2 * 0,0344   or   distance\_cm = echo\_duration/2 / 29,1 or distance\_cm =
       echo\_duration * 0,0172}
775     \textcolor{comment}{// distance\_cm = (echo\_duration/2) / 29.1;}
776     \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{long} echo\_runtime\_us = usonic\_measure\_single\_shot\_us(max\_echo\_run\_time\_us);
777     \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{long} distance\_cm = echo\_runtime\_us * 0.0172;
778     \textcolor{comment}{//Serial.print("MEASURE\_DISTANCE. Distance in cm is: ");}
779     \textcolor{comment}{//Serial.println(distance\_cm);}
780     \_usonic\_distance\_cm = distance\_cm;
781     \textcolor{keywordflow}{return}(distance\_cm);
782 \}
\end{DoxyCode}
\mbox{\Hypertarget{group__lowerlevelusmeths_ga1b5b43372082f5daeee47410a09a590c}\label{group__lowerlevelusmeths_ga1b5b43372082f5daeee47410a09a590c}} 
\index{Methods@{Methods}!usonic\+\_\+measure\+\_\+single\+\_\+shot\+\_\+us@{usonic\+\_\+measure\+\_\+single\+\_\+shot\+\_\+us}}
\index{usonic\+\_\+measure\+\_\+single\+\_\+shot\+\_\+us@{usonic\+\_\+measure\+\_\+single\+\_\+shot\+\_\+us}!Methods@{Methods}}
\subsubsection{\texorpdfstring{usonic\+\_\+measure\+\_\+single\+\_\+shot\+\_\+us()}{usonic\_measure\_single\_shot\_us()}\hspace{0.1cm}{\footnotesize\ttfamily [2/2]}}
{\footnotesize\ttfamily unsigned long Code\+Racer\+::usonic\+\_\+measure\+\_\+single\+\_\+shot\+\_\+us (\begin{DoxyParamCaption}\item[{unsigned long}]{max\+\_\+echo\+\_\+run\+\_\+time\+\_\+us }\end{DoxyParamCaption})}



Measures the distance to the next object in front of the ultra sonic sensor in microseconds. 

This is a one shot measurement. Be careful with high values for max\+\_\+echo\+\_\+run\+\_\+time\+\_\+us -\/ this may increase run time due to the fact that if there is nothing in range of the sensor it will wait until this specified run time of the echo is over. The maximum range the sensor is specified for is about 300cm. 
\begin{DoxyParams}{Parameters}
{\em max\+\_\+echo\+\_\+run\+\_\+time\+\_\+us} & Defines the maximum echo run time in microseconds and by that the maximum of distance that can be measured. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The measured distance in microseconds. 
\end{DoxyReturn}


Definition at line 791 of file Code\+Racer.\+cpp.


\begin{DoxyCode}
792     \{
793         \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{long} echo\_runtime\_us;
794         \textcolor{comment}{// start measurement - send a short pulse "HIGH" to the TRIG pin of the ultrasonic sensor}
795         pinMode(\_us\_echo\_pin, OUTPUT);
796         pinMode(\_us\_echo\_pin, INPUT);
797         digitalWrite(\_us\_trigger\_pin, LOW);
798         delayMicroseconds(2);
799         digitalWrite(\_us\_trigger\_pin, HIGH);
800         delayMicroseconds(10);
801         digitalWrite(\_us\_trigger\_pin, LOW);
802         \textcolor{comment}{// measure runtime in microseconds until the ECHO pin aof the sensor goes HIGH}
803         echo\_runtime\_us = pulseInLong(\_us\_echo\_pin, HIGH, max\_echo\_run\_time\_us);
804         \textcolor{keywordflow}{if} (echo\_runtime\_us == 0) \{
805             echo\_runtime\_us = max\_echo\_run\_time\_us; \textcolor{comment}{// US\_MAX\_ECHO\_TIME\_US;}
806         \}
807         \textcolor{comment}{//Serial.print("MEASURE\_DISTANCE\_US. Echo runtime in us is: ");}
808         \textcolor{comment}{//Serial.println(echo\_runtime\_us);}
809         \_usonic\_distance\_us = echo\_runtime\_us;
810         \textcolor{keywordflow}{return}(echo\_runtime\_us);
811     \}
\end{DoxyCode}
