Author Archive

## Tig Quick Reference Card

Simple reference card for tig, the text-mode interface for git.

This Tig Quick Reference Card shows all the key bindings supported by tig version 0.17.

The reference card is available as a PDF so you can print it out. The PDF version is derived from the TeX file which is hosted at http://github.com/gburca/git-qrc so anyone can update it.

Categories: Uncategorized Tags:

## From Acceleration to Displacement (part 2)

In a previous post I showed how to analytically double integrate (or rather repeat integrate) a $$\sin$$ wave to arrive at displacement or position. Here I’ll make it a little more generic, by integrating a sum of $$\sin$$ waves, each with its own amplitude and phase. This exercise is motivated by the fact that any arbitrarily complex waveform can be expressed as the sum of a number of sinusoids, so this will allow us to obtain the exact displacement when the acceleration is arbitrarily complex, as long as we’re able to determine (through FFT perhaps) the sinusoids that make up the acceleration.

$A = \sum\limits_{i} a_i \sin(c_i t) dt$

First integration, to obtain velocity:

\begin{align} V = \int\limits_{s}^{e} \sum\limits_{i} a_i \sin(c_i t) dt &= \sum\limits_{i}{ – \frac{a_i \cos(c_i x)}{c_i}\bigg|_{s}^{e}} \\ &= \sum\limits_{i}{ – \frac{a_i \cos(c_i e)}{c_i}} \ – \sum\limits_{i}{ – \frac{a_i \cos(c_i s)}{c_i}} \end{align}

Let $$m \equiv \sum\limits_{i}{ – \frac{a_i \cos(c_i s)}{c_i}}$$ and then do the second integration, to obtain displacement or position.

\begin{align} D &= \int\limits_{g}^{h} \sum\limits_{i}{ – \frac{a_i \cos(c_i e)}{c_i}} \ – m\ de \\ &= \sum\limits_{i}{-\frac{a_i \sin(c_i e)}{c_i^2} – me \bigg|_g^h} \\ &= \left[ \sum\limits_{i}{-\frac{a_i \sin(c_i h)}{c_i^2}} – mh \right] – \left[ \sum\limits_{i}{-\frac{a_i \sin(c_i g)}{c_i^2}} – mg \right] \end{align}

Substitute everything back in (given $$g \equiv s$$ and $$h \equiv e$$), and simplify:

\begin{align} D &= \left[ \sum\limits_{i}{-\frac{a_i \sin(c_i h)}{c_i^2}} – mh \right] – \left[ \sum\limits_{i}{-\frac{a_i \sin(c_i g)}{c_i^2}} – mg \right] \\ &= \left[ \sum\limits_{i}{-\frac{a_i \sin(c_i e)}{c_i^2}} – me \right] – \left[ \sum\limits_{i}{-\frac{a_i \sin(c_i s)}{c_i^2}} – ms \right] \\ &= \sum\limits_{i}{-\frac{a_i \sin(c_i e)}{c_i^2}} \ – \sum\limits_{i}{-\frac{a_i \sin(c_i s)}{c_i^2}} + (s-e)\sum\limits_{i}{ – \frac{a_i \cos(c_i s)}{c_i}} \\ &= \sum\limits_{i}{\frac{a_i \sin(c_i s)}{c_i^2}} \ – \sum\limits_{i}{\frac{a_i \sin(c_i e)}{c_i^2}} + (e-s)\sum\limits_{i}{\frac{a_i \cos(c_i s)}{c_i}} \end{align}

Finally, to take the phase of the signal into account, we would start with:

$A = \sum\limits_{i} a_i \sin(c_i t + p_i) dt$

And end with:

$D = \sum\limits_{i}{\frac{a_i \sin(c_i s + p_i)}{c_i^2}} \ – \sum\limits_{i}{\frac{a_i \sin(c_i e + p_i)}{c_i^2}} + (e-s)\sum\limits_{i}{\frac{a_i \cos(c_i s + p_i)}{c_i}}$

Categories: Uncategorized Tags:

## From Acceleration to Displacement

Recently I was trying to double integrate a sinusoidal acceleration (ex: a frog leaping forward) and was a bit puzzled at first why double integrating the $$\sin(t)$$ wave resulted in no displacement after an integral number of cycles:

$\begin{eqnarray} v(t) = \int \sin(t) dt &=& -\cos(t) \\ d(t) = \int -\cos(t) dt &=& -\sin(t) \end{eqnarray}$

Everybody knows that integrating once gives you velocity, and integrating twice gives you displacement (or position). But if that’s the case, why is the displacement ($$-sin(t)$$) above sinusoidal? Shouldn’t the frog be moving forward instead of back and forth?

It turns out my calculus was rusty enough to where I missed one very obvious fact. In the process I learned the distinction between a multiple (or double) integral, which is an integral taken over different variables (ex: $$\int \int f(x, y) dx\ dy$$) and a repeated integral which is taken multiple times over the same variable. What I missed was the difference between an indefinite integral (shown above) and a definite integral (shown below).

So let’s make the problem a little more generic and add amplitude and frequency component to our acceleration signal, and then see what happens to it as we integrate it twice. We’ll start with an acceleration signal defined as:

$A = a \sin(c*t)$

and we’ll integrate it twice over the interval start..end ($$s..e$$) to see what we get.

For the first integration we have:

\begin{align} V_{t = e} = \int_{s}^{e} a \sin(ct) dt &= \ – \frac{a \cos(ct)}{c}\bigg|_{s}^{e} \\ &= -\frac{a \cos(ce)}{c} + \frac{a \cos(cs)}{c} \end{align}

So that allows us to calculate the velocity at any point $$t = e$$ after the starting time $$s$$. Now we want to integrate a second time to get the displacement. To avoid confusion with the $$s..e$$ interval used for the first integration, we’ll use $$g..h$$ as the integration interval this time around. To simplify things, let’s also rename the integration constant (time independent) term $$\frac{a \cos(cs)}{c} \equiv m$$.

\begin{align} D_{t = h} = \int_{g}^{h} -\frac{a \cos(ce)}{c} + m\ de &= -\frac{a \sin(ce)}{c^2} + me \bigg|_{g}^{h} \\ &= \left[ mh – \frac{a \sin(ch)}{c^2} \right] – \left[ mg – \frac{a \sin(cg)}{c^2} \right] \end{align}

Since both integrations are over the same intervals, we know that $$g \equiv s$$ and $$h \equiv e$$. Now substitute everything back in and simplify:

\begin{align} D_{t = e} &= \left[ mh – \frac{a \sin(ch)}{c^2} \right] – \left[ mg – \frac{a \sin(cg)}{c^2} \right] \\ &= \left[ me – \frac{a \sin(ce)}{c^2} \right] – \left[ ms – \frac{a \sin(cs)}{c^2} \right] \\ &= m(e-s)\ – \frac{a \sin(ce)}{c^2} + \frac{a \sin(cs)}{c^2} \\ &= \frac{a \cos(cs)}{c} (e-s)\ – \frac{a \sin(ce)}{c^2} + \frac{a \sin(cs)}{c^2} \end{align}

If we want to take into account the phase of the signal, we start with:

$A = a \sin(ct + p)$

and end with:

$D = \frac{a \cos(cs+p)}{c} (e-s)\ – \frac{a \sin(ce+p)}{c^2} + \frac{a \sin(cs+p)}{c^2}$

So there you have it. The result of integrating a sinusoidal acceleration twice on the interval $$s..e$$ in order to arrive at the displacement.

Categories: Uncategorized Tags:

## Git – deleting the current branch is denied

Here’s a solution if you ever get the following error when trying to delete the master branch in a remote repository:

remote: error: By default, deleting the current branch is denied, because the next
remote: error: 'git clone' won't result in any file checked out, causing confusion.
remote: error:
remote: error: You can set 'receive.denyDeleteCurrent' configuration variable to
remote: error: 'warn' or 'ignore' in the remote repository to allow deleting the
remote: error: current branch, with or without a warning message.
remote: error:
remote: error: To squelch this message, you can set it to 'refuse'.
remote: error: refusing to delete the current branch: refs/heads/master
To /somewhere/in/the/cloud/repo.git
! [remote rejected] master (deletion of the current branch prohibited)
error: failed to push some refs to '/somewhere/in/the/cloud/repo.git'


The reason you’re seeing the error is that HEAD on the remote repository by default contains something like this (see also line 9 in the error message above):

ref: refs/heads/master


If you have access to the remote repository, simply modify the HEAD file to point to a different branch and then you’ll be able to delete the remote master branch. There are some significant implications to modifying the remote HEAD, especially if other users are tracking that branch, so make sure you know what you’re doing if you choose to point it to some other arbitrary branch.

Categories: Uncategorized Tags:

## Using Android IPC binders from native code

This is a follow-up (with actual code examples) to a post I wrote a while ago on how to use the Android IPC system from native C++ code. The code is hosted on GitHub at Android IPC binder demo. A number of readers have asked for sample code after reading the previous post, so hopefully this helps.

When executed without any arguments, the binary acts as a service (named “Demo”). When executed with an integer argument (ex: “binder 743”), the binary acts as a client that searches for the “Demo” service, binds to it, and exercises its API. To keep things simple, there’s virtually no error checking. Some debug messages are sent to stdout, and others to logcat.

The suggested way to run this demo to have 3 windows open and issue the following commands in them:

1. adb logcat -v time binder_demo:* *:S

Now for a brief explanation of the code. The IInterface, BpInterface, and BnInterface classes are provided by the Android framework.

We start by defining an interface (think AIDL) that will be shared between the service and the client:

class IDemo : public IInterface {
public:
enum {
PUSH,
};
// Sends a user-provided value to the service
virtual void        push(int32_t data)          = 0;
// Sends a fixed alert string to the service
// Requests the service to perform an addition and return the result
virtual int32_t     add(int32_t v1, int32_t v2) = 0;

DECLARE_META_INTERFACE(Demo);
};

// This implementation macro would normally go in a cpp file
IMPLEMENT_META_INTERFACE(Demo, "Demo");


Next we define the server end, which is made up of 2 classes: BnDemo, and its derived class, Demo. BnDemo extracts the arguments from the data Parcel sent by the client, calls the appropriate virtual function (implemented in the Demo class) to do the heavy-lifting, and packs the returned values (if any) into a reply Parcel to be sent back to the client.

class BnDemo : public BnInterface<IDemo> {
virtual status_t onTransact(uint32_t code, const Parcel& data,
Parcel* reply, uint32_t flags = 0);
};

status_t BnDemo::onTransact(uint32_t code, const Parcel& data,

data.checkInterface(this);

switch(code) {
return NO_ERROR;
} break;
case PUSH: {
push(inData);
return NO_ERROR;
} break;
return NO_ERROR;
} break;
default:
}
}



This is the Demo class, which would normally do the real work on the service side of the binder.

class Demo : public BnDemo {
virtual void push(int32_t data) {
// Do something with the data the client pushed
}
}
virtual int32_t add(int32_t v1, int32_t v2) {
return v1 + v2;
}
};


Now we define a service proxy, to be used on the client side. Notice again that any data the client needs to send to the service is packed in a Parcel and results (if any) are also returned in a Parcel.

class BpDemo : public BpInterface<IDemo> {
public:
BpDemo(const sp<IBinder>& impl) : BpInterface<IDemo>(impl) { }

virtual void push(int32_t push_data) {
data.writeInterfaceToken(IDemo::getInterfaceDescriptor());
data.writeInt32(push_data);
}

data.writeInterfaceToken(IDemo::getInterfaceDescriptor());
}

virtual int32_t add(int32_t v1, int32_t v2) {
data.writeInterfaceToken(IDemo::getInterfaceDescriptor());
data.writeInt32(v1);
data.writeInt32(v2);

int32_t res;
return res;
}
};


Finally, we start the service as follows:

        defaultServiceManager()->addService(String16("Demo"), new Demo());


And the client can now connect to the service and call some of the provided functions:

    sp<IServiceManager> sm = defaultServiceManager();
sp<IBinder> binder = sm->getService(String16("Demo"));
sp<IDemo> demo = interface_cast<IDemo>(binder);