perkee's blog

I heard you like science. tags
Jun 04
Permalink
Unit multiplication in #LaTeX

When I’m multiplying a bunch of quantities with units, it’s pretty nice to show that they cancel, especially when you want to step through your reasoning when converting units that are actually made up of a lot of SI base units.  I developed this little number for showing this in a report or whatever, with the numbers on the left side and units on the right, separated by at least a \quad.


\newcommand{\ufrac}[4]{\frac{\hfill#1\quad\hfill\mathrm{#2}}{\hfill#3\hfill\quad\mathrm{#4}}}

Unit multiplication in #LaTeX

When I’m multiplying a bunch of quantities with units, it’s pretty nice to show that they cancel, especially when you want to step through your reasoning when converting units that are actually made up of a lot of SI base units. I developed this little number for showing this in a report or whatever, with the numbers on the left side and units on the right, separated by at least a \quad.

\newcommand{\ufrac}[4]{\frac{\hfill#1\quad\hfill\mathrm{#2}}{\hfill#3\hfill\quad\mathrm{#4}}}
Comments (View)
May 26
Permalink
Comments (View)
22 notes
Permalink
[Flash 9 is required to listen to audio.]

Tres Coronas - Locked In

These guys are so fucking good. Why? I dunno. This EP is a classic even though I’ve listened to it continuously for about five years now.

Comments (View)
May 15
Permalink
LaTeX math with anotations that doesn’t look horrible.
Of note is the use of align with multiple points of alignment, each denoted by a single ampersand.
I’m pretty proud of this. Source is below, with some stuff taken out.
Sorry I can’t post full source anymore.


\usepackage{commath}
\newcommand\cartesian\times
\newcommand\union\cup

…

Let us choose $a\in A$ and let $A'=A-\set a$.
Then $\absolute{A'}=k$ and so---by our inductive
hypothesis---$\absolute{A'\cartesian A'}=k^2$
\begin{align*}
  &\text{But}&\absolute{A\cartesian A}
  &=\absolute{\left(A'\union\set a\right)\cartesian
    \left(A'\union\set a\right)}&\\
  &&&=\absolute{\left(A'\cartesian A'\right)\union
    \left(\set a\cartesian A'\right)\union
    \left(A'\cartesian\set a\right)\union
    \left(\set a\cartesian\set a\right)}&
      \parbox{10em}{
        \raggedleft
          \scriptsize{%\noindent
          The cartesian product
          distributes over union.
          }
      }\\
  &&&=\underbrace{\absolute{A'\cartesian A'}}_
    {\parbox{4em}
      {
        \centering
          \scriptsize{
            $k^2$
            \begin{flushleft}
              by the inductive hypothesis
            \end{flushleft}
          }
        %centering ends here
      }
    }+
    \underbrace{\absolute{\set a\cartesian A'}}_
    {\parbox{4.5em}
      {
        \centering
          \scriptsize{
            $k$
            \begin{flushleft}
              because each one of the $k$
              elements in $A'$ matches up
              once with the single element
              in $\set a$
            \end{flushleft}
          }
        %centering ends here
      }
    }+
    \underbrace{\absolute{A'\cartesian\set a}}_
    {\parbox{4em}
      {
        \centering
          \scriptsize{
            $k$
            \begin{flushleft}
              likewise
            \end{flushleft}
          }
        %centering ends here
      }
    }+
    \underbrace{\absolute{\ordered{a,a}}}_1&
    \parbox{10em}{
      \raggedleft
      \scriptsize{
      The size of a union of sets is equal to the 
      sum of the sizes of the constituent sets.}
    }\\
  &&&=k^2+2k+1&\\
  &&&={(k+1)}^2&\text{as desired.}
\end{align*}

LaTeX math with anotations that doesn’t look horrible. Of note is the use of align with multiple points of alignment, each denoted by a single ampersand. I’m pretty proud of this. Source is below, with some stuff taken out. Sorry I can’t post full source anymore.

\usepackage{commath}
\newcommand\cartesian\times
\newcommand\union\cup

Let us choose $a\in A$ and let $A'=A-\set a$.
Then $\absolute{A'}=k$ and so---by our inductive
hypothesis---$\absolute{A'\cartesian A'}=k^2$
\begin{align*}
  &\text{But}&\absolute{A\cartesian A}
  &=\absolute{\left(A'\union\set a\right)\cartesian
    \left(A'\union\set a\right)}&\\
  &&&=\absolute{\left(A'\cartesian A'\right)\union
    \left(\set a\cartesian A'\right)\union
    \left(A'\cartesian\set a\right)\union
    \left(\set a\cartesian\set a\right)}&
      \parbox{10em}{
        \raggedleft
          \scriptsize{%\noindent
          The cartesian product
          distributes over union.
          }
      }\\
  &&&=\underbrace{\absolute{A'\cartesian A'}}_
    {\parbox{4em}
      {
        \centering
          \scriptsize{
            $k^2$
            \begin{flushleft}
              by the inductive hypothesis
            \end{flushleft}
          }
        %centering ends here
      }
    }+
    \underbrace{\absolute{\set a\cartesian A'}}_
    {\parbox{4.5em}
      {
        \centering
          \scriptsize{
            $k$
            \begin{flushleft}
              because each one of the $k$
              elements in $A'$ matches up
              once with the single element
              in $\set a$
            \end{flushleft}
          }
        %centering ends here
      }
    }+
    \underbrace{\absolute{A'\cartesian\set a}}_
    {\parbox{4em}
      {
        \centering
          \scriptsize{
            $k$
            \begin{flushleft}
              likewise
            \end{flushleft}
          }
        %centering ends here
      }
    }+
    \underbrace{\absolute{\ordered{a,a}}}_1&
    \parbox{10em}{
      \raggedleft
      \scriptsize{
      The size of a union of sets is equal to the 
      sum of the sizes of the constituent sets.}
    }\\
  &&&=k^2+2k+1&\\
  &&&={(k+1)}^2&\text{as desired.}
\end{align*}
Comments (View)
Apr 14
Permalink

Set Theory in LaTeX

I hate the lack of syntax in a lot of LaTeX math, especially now that I’ve started typing my notes and problem sets in two classes that are all set theory. Think about it, syntactically I am entering the symbol for set union, so why should I call it \cup? I shouldn’t. Thus, I have put together a whole heaping helping of set theory commands that I use all the time. If you want to see the kind of notes I’m making, head over here.

\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{amsfonts}
\theoremstyle{definition}% default 
\newtheorem{prop}{Proposition}[enumii]

\theoremstyle{definition}
\newtheorem*{Proof}{Proof}

\theoremstyle{remark} 
\newtheorem{case}{Case}[prop]

%%%%%%This is where I put in math commands
\renewcommand{\implies}{\ensuremath{\to}}%the normal implies arrow is double width, so this makes it thinner
%particular sets
\newcommand{\naturals}{\ensuremath{\mathbb{N}}}
\newcommand{\integers}{\ensuremath{\mathbb{Z}}}
\newcommand{\rationals}{\ensuremath{\mathbb{Q}}}
\newcommand{\reals}{\ensuremath{\mathbb{R}}}
%words
\renewcommand{\iff}{\ensuremath{\operatorname{iff}}}
 %\renewcommand{\st}{\ensuremath{\operatorname{s.t.\ }}}
 %\DeclareMathOperator{\st}{s.t.\ }
%logic
\newcommand{\nd}{\ensuremath{\operatorname{and}}}
\newcommand{\ro}{\ensuremath{\operatorname{or}}}
\DeclareMathOperator{\then}{then}
\DeclareMathOperator{\but}{but}
%set operators
\newcommand{\set}[1]{\left\{#1\right\}}
\newcommand{\ordered}[1]{\left(#1\right)}
\let\propsubset\subset
\renewcommand{\subset}{\subseteq}
\let\propsupset\supset
\renewcommand{\supset}{\supseteq}
\newcommand{\intersect}{\cap}
\newcommand{\union}{\cup}
\newcommand{\symdif}{\vartriangle}
\newcommand{\complementset}[2][]{\ensuremath{\mathcal{C}_{#1} \left(#2\right)}}
\newcommand{\powerset}[1]{\ensuremath{\mathscr{P}\left(#1\right)}}
\newcommand{\cartesian}{\ensuremath{\times}}
 
Comments (View)
Mar 17
Permalink

The exam sucked.  But on the other hand here’s something fun.  My school has HID Global™ brand RFID access to all of the buildings.  Some rooms actually use a magnetic stripe, which is on that same card.  The school says not to mar the cards at all, but fuck that, because you can totally drill through an RFID card if you are smart about it.  I don’t want to lose my key or ID anymore, so I drilled through an old ID I had lost and then found again, and discovered that it was still reading.  So then I did it to my new one.  Since I couldn’t find any good info on acceptable drilling locations on HID RFID cards, here is my guide.  Drill where I did, and you’ll probably be OK.

The hole is centered in the middle of the card vertically, 7.5mm from the left-hand side when viewing the face with the magnetic strip up, with the stripe on top.  I hate millimeters, but that’s the only ruler I have on hand. 


There are probably a lot of other acceptable locations; what you have to avoid is cutting through the loop antenna that goes around the edge of the card, and cutting through the chip and wires leading to it.  These are, I think, on the opposite side of the card from where I drilled, in vertical line with the HID logo.

Really hoping HID doesn’t dump hatorade upon me on account of that image existing.  it’s their trademark, hence the “™” earlier.  I am no stooge.

The exam sucked. But on the other hand here’s something fun. My school has HID Global™ brand RFID access to all of the buildings. Some rooms actually use a magnetic stripe, which is on that same card. The school says not to mar the cards at all, but fuck that, because you can totally drill through an RFID card if you are smart about it. I don’t want to lose my key or ID anymore, so I drilled through an old ID I had lost and then found again, and discovered that it was still reading. So then I did it to my new one. Since I couldn’t find any good info on acceptable drilling locations on HID RFID cards, here is my guide. Drill where I did, and you’ll probably be OK.

The hole is centered in the middle of the card vertically, 7.5mm from the left-hand side when viewing the face with the magnetic strip up, with the stripe on top. I hate millimeters, but that’s the only ruler I have on hand.

There are probably a lot of other acceptable locations; what you have to avoid is cutting through the loop antenna that goes around the edge of the card, and cutting through the chip and wires leading to it. These are, I think, on the opposite side of the card from where I drilled, in vertical line with the HID logo.

Really hoping HID doesn’t dump hatorade upon me on account of that image existing. it’s their trademark, hence the “™” earlier. I am no stooge.

Comments (View)
Mar 16
Permalink
Fuck off liberal arts nerds.

Fuck off liberal arts nerds.

Comments (View)
Permalink

LaTeX and Electromagnetics +1

…and maybe you finished studying for this exam, or you think you did, but really you can’t be sure, and you want to eat batteries, and this kind of looks like shit but you don’t care, and this is every equation you need to know for emag but it still won’t help goddamnit. Vita meretrix est.

\documentclass[11pt]{amsart}
\usepackage[margin=.75in]{geometry}                % See geometry.pdf to learn the layout options. There are lots.
\geometry{letterpaper}                   % ... or a4paper or a5paper or ... 
%\geometry{landscape}                % Activate for for rotated page geometry
%\usepackage[parfill]{parskip}    % Activate to begin paragraphs with an empty line rather than an indent
\usepackage{graphicx}
\usepackage{amssymb}
\usepackage{epstopdf}
\usepackage{amsmath}
\DeclareGraphicsRule{.tif}{png}{.png}{`convert #1 `dirname #1`/`basename #1 .tif`.png}

%%%%%%%%%%%   Bold style  Vectors%%%%%%%%%%%%%
\newcommand{\vect}[1]{\ensuremath{\boldsymbol{#1}}}
\newcommand{\unit}[1]{\ensuremath{\boldsymbol{\widehat{#1}}}}
\newcommand{\del}{\ensuremath{\boldsymbol{\nabla}}}

%%%%%%%%%%% arrow style vectors %%%%%%%%%%%%%%
%\newcommand{\vect}[1]{\ensuremath{\overrightarrow{#1}}}
%\newcommand{\unit}[1]{\ensuremath{\widehat{#1}}}
%\newcommand{\del}{\ensuremath{\nabla}}

\newcommand{\dotp}{\ensuremath{\!\cdot\!}}
\newcommand{\cross}{\ensuremath{\!\times\!}}
\newcommand{\entry}[2]{\item[#1] \hfill $#2$}


\begin{document}
\section{Electric}
\subsection{Charge}
	\begin{description}
		\entry{Electric Field Examples}{~}
			\begin{description}
	 			\entry{due to point charge}{\vect{E}=\frac{Q\unit{R}}{4\pi\epsilon R^2} = \frac{Q\vect{R}}{4\pi\epsilon R^3}}
	 			\entry{due to an infinitely long wire}{E=\frac{\rho_l}{2\pi\epsilon_0R}}
	 		\end{description}
 		\entry{Electric Flux Density}{\vect{D} = \epsilon_0\vect{E}  + \vect P= \epsilon\vect{E}=\frac{Q\unit{R}}{4\pi R^2} }
 		\entry{Gauss's Law}{Q=\oint\vect{D}\dotp\vect{ds} = \oint\vect{D}\dotp\unit{n}ds  = \int\del \dotp\vect{D}dv = \int\rho_vdv} \\ \hfill (``$v$'' as in volume.)
 		\entry{Voltage}{V_{\left(\textit{1 2}\right)}=-\int_2^1\vect{E}\dotp\vect{dl}}
 		\entry{Capacitance}{C=\frac{Q}{V}}
 		\item[Charge Density] ~
 		 	\begin{description}
 		 		\entry{Surface}{\rho_s=\frac{Q}{S}}
 		 		\entry{Volume}{\rho_v=\del\dotp\vect{D}}
 		 		\entry{Polarization Surface}{\rho_{\textit{ps}}=\vect{P}\dotp\unit{n}}
 				\entry{Polarization Volume}{\rho_{\textit{ps}}=-\del\dotp\vect{P}}
 		 	\end{description}
 		\entry{Polarization}{\oint\rho_{\textit{ps}}\vect{ds}+\int\rho_{\textit{pv}}\vect{dv} = 0}
 		\item[Boundary Conditions]  ~
 			\begin{description}
 				\entry{Tangential}{E_{t1} = E_{t2}}
 				\entry{Normal}{D_{n1} - D_{n2}=\rho_s}
 			\end{description}
 		\entry{Energy Density}{W=\frac{1}{2}\vect{D}\dotp\vect{E}=\frac{1}{2}\epsilon\vect{E}\dotp\vect{E}}
 		\entry{Total Energy}{W=\frac{1}{2}\int_{v'}\rho_vvdv = \frac{1}{2}\int_{v'} \epsilon \vect{E}\dotp\vect{E} dv = \frac{1}{2}CV^2= \frac{ 1}{2}QV=\frac{1}{2}\frac{Q^2}{C}}
		\entry{Force}{\vect{F}=-\del W=QE}
		\entry{Poisson's Equation}{\del^2V=\frac{-\rho_v}{\epsilon}}
		\entry{Laplace Equation}{\del^2V=0}
	\end{description}
\subsection{Current}
\begin{description}
	\entry{Current Density}{\vect J = \sigma \vect E }
	\entry{Resistance}{ R = \frac{l}{\sigma s}}
	\entry{Calculus with $\vect J$}{ \del \dotp \vect J = 0} ; $\oint\vect J \dotp \vect{ds} = 0$
	\item[Current Boundary Conditions]  ~
		\begin{description}
			\entry{Tangential}{\frac{J_{t1}}{\sigma_1} = \frac{J_{t2}}{\sigma_2} }
			\entry{Normal}{J_{n1} = J_{n2}}
		\end{description}
\end{description}
\section{Magnetic}
\begin{description}
	\entry{Ampere's Law}{\oint \vect B \dotp \vect{dl} = \mu I} ; $\del \cross \vect B = \mu_0 \vect J \therefore \int \del \cross\vect B \dotp \vect{ds}=\mu_0\int\vect J \dotp \vect ds \therefore \del \cross \vect H = \vect J$
	\entry{Current Density}{J=\frac I A} where $A= \textrm{cross-sectional area}$
	\entry{Biot--Savart's Law}{\vect B = \frac {\mu_0I}{4\pi}\int\frac{dl\cross\unit R}{R^2}=\del\cross\vect A} where $\vect A$ is Magnetic Vector Potential.
	\entry{Magnetic Field Intensity}{ H=\frac 1 {\mu_0}\vect B - \vect M} ; $\vect B=\mu\vect H$
	\entry{Vector Poisson's Equation}{\del^2\vect A = -\mu_0 \vect J}
	\entry{Magnetization Current}{\vect{J_\textit{ms}}=\vect M \cross \unit{n}}
	\entry{Magnetic Flux}{\Phi = \int_s\vect B \dotp \vect{ds} = \oint \vect A \cdot \vect{dl}}
	\item[Boundary Conditions] ~
		\begin{description}
			\entry{Normal}{\vect{B_{1n}}=\vect{B_{2n}}}
			\entry{Tangential}{\vect{H_{1t}}=\vect{H_{2t}}}
		\end{description}
	\entry{Flux Linkage}{\Lambda_{\left(\textit{1 2}\right)}=L_{\left(\textit{1 2}\right)}I_1=N_2\Phi_{\left(\textit{1 2}\right)}}
	\entry{\textit{M\'as} Flux Linkage}{L_{\left(\textit{1 2}\right)} = \frac{\Lambda_{\left(\textit{1 2}\right)}}{I_1}=\frac{N_2}{I_1}\int_{S_2}\vect{B_1} \dotp \vect{ds_2}}
	\entry{Energy Density}{W = \frac 1 2 \vect H \dotp \vect B = \frac 1 2 \frac{ B^2}{\mu}}
	\entry{Energy}{W = \frac 1 2 LI^2=\frac 1 2 \int_{v'}\frac{B^2}{\mu}dv}
	\entry{Force}{F=I\oint_c\vect{dl}\cross\vect B}
	\entry{Lorentz's Force Equation}{\vect F = \vect{F_e}+\vect{F_m}=q\left(\vect E + \vect u \cross \vect B\right)} where $\vect u$ is velocity
	\entry{Torque for Dipole or Loop}{\vect T = \vect m \cross \vect B $ where $ \vect m= IS \unit n$ and $ F_\Phi = -\unit y \frac{I^2}{\mu_0I}}
	\entry{Vector Magnetic Potential}{\vect A = \frac{\mu_0}{4\pi}\int_{v'}\frac {\vect J} R dv'} in Webers per Meter $\left(\frac {\mathrm{Wb}}{\mathrm{m}}\right)$
	\entry{Magnetic field examples}{~}
		\begin{description}
			\entry{Axis of a Loop on $z=0$ plane with axis at origin}{\vect B = \unit z \frac{\mu I}{2}\left(\frac{a^2}{\left(a^2+z^2\right)^{3/2}}\right)} 
			\entry{Distance from a wire}{\vect B = \unit \Phi \frac {\mu_0I}{4\pi}\left[\frac {z}{r\sqrt{z^2+r^2}} \right]_{z=-L}^{L} =   \unit \Phi \frac {\mu_0I}{4\pi r}\left(\frac {2L}{\sqrt{L^2+r^2}} \right) }
		\end{description}
	\entry{Modeling magnetic circuits as their Electrical Equivalents}{~}
		\begin{description}
			\entry{Resistance}{R = \frac{l}{\mu S}}
			\entry{Equivalency}{\Phi R = NI}
		\end{description}
\end{description}
\end{document}  
 
Comments (View)
Permalink

LaTeX and Electromagnetics

maybe you have an electromagnetics final in 7.5 hours like I do. maybe you want a study sheet. Maybe I have one for you, because I’ve got the LaTeX if you’ve got the time…

\documentclass[11pt]{amsart}
\usepackage{geometry}                % See geometry.pdf to learn the layout options. There are lots.
\geometry{letterpaper}                   % ... or a4paper or a5paper or ... 
%\geometry{landscape}                % Activate for for rotated page geometry
%\usepackage[parfill]{parskip}    % Activate to begin paragraphs with an empty line rather than an indent
\usepackage{graphicx}
\usepackage{amssymb}
\usepackage{epstopdf}
\usepackage{amsmath}
\DeclareGraphicsRule{.tif}{png}{.png}{`convert #1 `dirname #1`/`basename #1 .tif`.png}

%%%%%%%%%%%   Bold style  Vectors%%%%%%%%%%%%%
\newcommand{\vect}[1]{\ensuremath{\boldsymbol{#1}}}
\newcommand{\unit}[1]{\ensuremath{\boldsymbol{\widehat{#1}}}}
\newcommand{\del}{\ensuremath{\boldsymbol{\nabla}}}

%%%%%%%%%%% arrow style vectors %%%%%%%%%%%%%%
%\newcommand{\vect}[1]{\ensuremath{\overrightarrow{#1}}}
%\newcommand{\unit}[1]{\ensuremath{\widehat{#1}}}
%\newcommand{\del}{\ensuremath{\nabla}}

\newcommand{\dotp}{\ensuremath{\!\cdot\!}}

\begin{document}
\section{Electric}

\begin{description}
	\item[Field due to point charge] \hfill $\vect{E}=\frac{Q\unit{R}}{4\pi\epsilon R^2} = \frac{Q\vect{R}}{4\pi\epsilon R^3}$
	\item[Electric Flux Density] \hfill $\vect{D} = \epsilon_0\vect{E}  + \vect P= \epsilon\vect{E}=\frac{Q\unit{R}}{4\pi R^2} $
	\item[Gauss's Law] \hfill $Q=\oint\vect{D}\dotp\vect{ds} = \oint\vect{D}\dotp\unit{n}ds  = \int\del \dotp\vect{D}dv = \int\rho_vdv$ \\ \hfill (``$v$'' as in volume.)
	\item[Voltage] \hfill $V_{1-2}=-\int_2^1\vect{E}\dotp\vect{dl}$
	\item[Capacitance] \hfill $C=\frac{Q}{V}$
	\item[Charge Density] ~
	 	\begin{description}
	 		\item[Surface] \hfill $\rho_s=\frac{Q}{S}$
	 		\item[Volume] \hfill $\rho_v=\del\dotp\vect{D}$
	 		\item[Polarization Surface] \hfill $\rho_{\textit{ps}}=\vect{P}\dotp\unit{n}$
			\item[Polarization Volume] \hfill $\rho_{\textit{ps}}=-\del\dotp\vect{P}$
	 	\end{description}
	\item[Polarization] \hfill $\oint\rho_{\textit{ps}}\vect{ds}+\int\rho_{\textit{pv}}\vect{dv} = 0$
	\item[Boundary Conditions]  ~
		\begin{description}
			\item[Tangential] \hfill $E_{t1} = E_{t2}$
			\item[Normal] \hfill $D_{n1} - D_{n2}=\rho_s$
		\end{description}
	\item[Energy Density] \hfill $W=\frac{1}{2}\vect{D}\dotp\vect{E}=\frac{1}{2}\epsilon\vect{E}\dotp\vect{E}$
	\item[Total Energy] \hfill $W=\frac{1}{2}\int_{v'}\rho_vvdv = \frac{1}{2}\int_{v'} \epsilon \vect{E}\dotp\vect{E} dv = \frac{1}{2}CV^2= \frac{1}{2}QV=\frac{1}{2}\frac{Q^2}{C}$
	\item[Force] \hfill $\vect{F}=-\del W=QE$
	\item[Poisson's Equation] \hfill $\del^2V=\frac{-\rho_v}{\epsilon}$
	\item[Laplace Equation] \hfill $\del^2V=0$
\end{description}
\section{Current}
\begin{description}
	\item[Current Density] \hfill $\vect J = \sigma \vect E $
	\item[Resistance] \hfill $ R = \frac{l}{\sigma s}$
	\item[Calculus with $\vect J$] \hfill $ \del \dotp \vect J = 0$
	\item[Current Boundary Conditions]  ~
		\begin{description}
			\item[Tangential] \hfill $\frac{J_{t1}}{\sigma_1} = \frac{J_{t2}}{\sigma_2} $
			\item[Normal] \hfill $J_{n1} = J_{n2}$
		\end{description}
\end{description}
\section{Magnetic}
This will be a long night\dots
\end{document}
Comments (View)
Mar 11
Permalink

Collapsible Tag cloud in tumblr

Hey, so maybe you want a sweet collapsible tag could in your tumblr page like mine. I took the tag cloud code from here and the collapsing javascript from here and rolled them up into this. Drop this in your Customize → Info → Description as you see fit.

<a href="javascript:;" onmousedown="if(document.getElementById('tags').style.display == 'none'){ document.getElementById('tags').style.display = 'block'; }else{ document.getElementById('tags').style.display = 'none'; }">tags</a> 

<div id="tags" style="display:none">
<!-- Start Tumblr Tag Cloud -->
<script type="text/javascript" src="http://code.hr1v.com/jquery.1.2.6.min.js"></script><script type="text/javascript" src="http://tumblrtags.hr1v.com/widget.js?css=default&minsize=120&maxsize=280"></script>
<!-- End Tumblr Tag Cloud -->
</div>
Comments (View)
1 note
Permalink

flip() for Arduinos, or really any C-esque language

I just helped a friend with a digital art project. She is a great artist and a great programmer (double major in Visual Art and Computer Science) so she knows what she’s doing. What she needed was to borrow my soldering iron and expertise, both of which I love lending out, especially when I get cookies in return. Anyways, her project has 6 potentiometers functioning as voltage dividers. They have one leg on the Arduino’s +5V pin, the other on Ground, and each has a wiper going to an Analog in pin. The input is read in as follows:

v0 = analogRead(0);
v0 = map(v0, 0, 1023, 0, 255);
Serial.print(v0);

After this, a bunch of reading happens in processing that manipulates video frames, so the knob position plays back a short clip. Pretty cool, eh. Problem is that we might have soldered them in backwards, such that turning to the right lowers the voltage. Not a problem. May I present flip():

int flip(int value, int from, int to)
{
    return to-value+from;
}

int flip(int value, int to)
{
    return flip(value, 0, to);
}

int flip(byte value)
{
   return (byte) flip(value, 255);
}

Note that the operation order in the first one is important; you might have weird overflows, etc. if you add before subtracting.

Comments (View)
Mar 09
Permalink

Speedometer Project Update 01

More thinking, more plotting, more science since we last left off. I just discovered the AMAZING capabilities of Arduino’s pulseIn() function. I now have a new plan.

loop
     do this 5 times
          if the speed sensor is low
               pulseIn HIGH the speed sensor pin
               write that value to an array
          else
               pulseIn LOW the speed sensor pin
               write that value to an array
      average that array
      calculate a speed from that average
      write that speed to the display
      write a timestamp to the memory card
      write that value to the memory card
      write throttle and brake position to the memory card
      delay 10ms
Comments (View)
Mar 06
Permalink

Speedometer project

I am on my college’s SAE Mini-Baja team. I really like it, even though I don’t know too much about car design. Building shit that moves is so righteous. I f you don’t know, a Baja car is a single passenger car designed for offroading. It gets its name from the Baja rally in Mexico, where a number of vehicles of all types race across really rough terain in the desert. We don’t go down to Mexico, but we do go to SAE competitions around the country, usually one per year. Some competitions emphasize rock crawling, some flotation. We usually go to the East one, which has a water component, for which the car has to not only float, but propel itself through water, which is pretty cool. This year we are going west to Oregon, for a more hill climbing, possibly rock crawling experience.

I have been tasked with building a sweet speedometer. My basic plan is to build the main function (sensing how quickly the rear wheels are turning) with an Arduino, a reed switch and some magnets on the sprocket. Output will be to three 7-segment LED displays, probably using either a 7-segment driver or LED driver. Then, provided that that goes well, record the time of each magnet trigger onto some kind of external storage device. Provided all of that goes well, I would like to add a lap button, to let the driver try to record laps as well. If all of that goes well, then I’d also like to have a 2 line LCD inside the cockpit giving average lap time.

So I think that this is my overall pseudocode for the ideal realization of the project. Don’t worry about millis() overflowing; that takes 49.7 days.

setup
   Constantly check for interrupts on the reed switch pin
   Ditto lap button

loop
    use mayfly loop to check the logging button as I may have used all my interrupts.
    another mayfly loop for the lap button

Interrupt block for the reed switch:
    current millis() minus last millis() is elapsedTime.
    tireCircumpherence/numMagnets/ellapsedTime is speed
    send current millis() to storage if logging is true

half or one or two second block
   send speed to LED displays
   currentLapTime = millis() - lastLapTime
   write the current lap time to the lcd display
   if it hasn't detected the reed switch in the second, set speed to zero

lap button block
   write some code indicating a lap has passed to the storage
   make the lastLapTime equal to the current millis()
   increment the lapNumber
   averageLapTime = lastLapTime/lapNumber
   write the average lap time to the display

This is all subject to change, of course. I need to get the speed accurate first; I think a photodetector (aka slot sensor) across the brake disk might be better. The brake disk has evenly space vent holes, meaning that there is an equal amount of steel and space in there. That means I can trigger the interrupt on change across the slot sensor. Disadvantage is if there is any prospect of mud getting in there. The brake disc is on the main frame, and not at the end of a suspension component, so the wiring is basically the same as having magnets on the sprocket.

The storage is pretty huge; I don’t know if I’ll be able to figure out writing to some kind of memory card, which this would definitely need. And if we do that, I think I’ll want to use text, not raw hex, as text lets me indicate laps pretty easily and visually debug lines with errors. On the other hand, maybe it won’t be so bad if each line is really well structured, i.e. 4 bytes for each datapoint, with 0xFACEBEEF or some other very high control code to indicate a lap is done.

Interface is sort of an issue. If I want to use 7 segment drivers, I will need 4 bits per digit, as I think they use BCD. I think I want to have a decimal for speed, because hey, why not, right? So that will mean 12 pins, which is impossible. Instead, I will have to use a shift register to output 12 bits to the 7-segment drivers. If I do that, I might not even need the 7-segment drivers. What I maybe will need is one big set of AND gates, one gate per LED on the speed display. This is to make sure that the LEDs aren’t turned on while they are being written to over serial, as the flashing could be distracting to the driver. The top left line on the leftmost 7-segment is never lit, but the decimal point on the middle one is, so that’s 21 AND gates, meaning six 7408s. However, since all of these AND gates share an input, I can maybe use a transistor instead, albeit one that can handle a not insignificant amount of current. OK never mind, LED drivers have an Enable Output pin that does exactly that. I can even use PWM with it. It also needs 4 pins, because it sends the data from the shift register to internal storage using the Strobe pin.

The other thing is the number of interrupts; the Arduino language does not have a pretty way of setting up timer interrupts, so that’s annoying to make that play nice between stuff written at the Arduino level, and stuff written in AVR C, a similar but slightly shaggier beast. The only critical (as in timing) interrupt is the one sensing the wheel speed. Everything else is pretty loose, as button presses are rather long, and the second is not really used for any critical timekeeping.

So my current tally is:

  • 1 pin for serial display (TX, which is digital pin 1)
  • 4 pins for Speed display
  • 1 pin with interrupt for speed sensor (photogate or hall effect or reed switch)
  • 1 pin with or without interrupt for logging button
  • 1 pin with interrupt for lap counter
  • 4 pins for interface with SD card
Maybe this will work, maybe it won’t. I know that at very least some of the things I am planning will work, and that’s pretty dang cool. Here are some resources I’ve come across for doing this.

And my parts list:

Comments (View)
Mar 05
Permalink
I made a little terminal/header block thing to hook the meter to the board.  This allows me to keep from having to have an breadboard with the resistor on it just to run the thing.  I only had 10kΩ resistors, so I used two in parallel to get a net resistance of 5kΩ.

I made a little terminal/header block thing to hook the meter to the board. This allows me to keep from having to have an breadboard with the resistor on it just to run the thing. I only had 10kΩ resistors, so I used two in parallel to get a net resistance of 5kΩ.

Comments (View)
Mar 04
Permalink

Laying out Code in tumblr

(X)HTML’s <pre> is pretty cool for laying out codeblocks.  It allows you to put everything monospace, and interprets the whitespace literally. I thik it also is pretty forgiving if your code contains reserved HTML characters, but that might just be tumblr.  I actually just borrowed the CSS from my tumblr dashboard to make it look nice on my page.  If you want to do that, just go to your dashboard and click Customize.  Then click “Advanced” up top, and put the following into your “Add Custom CSS” box.
pre
{
margin:10px 0px 10px 0px;
padding:10px;
background-color:#e6e6e6;
font-family: "Bitstream Vera Sans Mono", Courier, monospace;
font:normal 11px;
overflow:auto;
}

code
{
background-color:#e6e6e6;
font-family: "Bitstream Vera Sans Mono", Courier, monospace;
font:normal 11px;
}

EDIT: I figured it would be worthwhile to format the <code> tag as well; it’s what allows for inline code à la twelve word prior

Comments (View)