Shock Collar App: Development Part I

 

The biggest project I want to complete this year is my smartphone app for controlling a ponyboy. I have not been as on top of this as I would like, but I'm determined to get a basic prototype built, which I can then add new features to.

In the most basic sense, I want to develop a shock collar that is controlled by a smartphone app. Since I have an iPhone, it will be an iPhone app (though it will have to be an app only for jailbroken (i.e. rooted) iPhones since I seriously doubt that the app store will want anything to do with an app like this).

Controlling a basic shock collar with an app does not seem that difficult to do using a bluetooth interface. After examining the collar's shocking mechanism, I believe it would be trivial attach a bluetooth headset via a relay and activate the collar's shocking mechanism. However, my worry here is the limited range of bluetooth devices.

The alternative would be to attach the phone to an RF transceiver, but this would of course require the trainer to carry both the phone and transceiver. Another possibility would be to use a separate RF transceiver that communicates with the phone/app via bluetooth (so it could be kept in the trainer's pocket or otherwise nearby but not physically attached to the phone) but uses a different frequency to communicate with the collar.

I actually like the last option best, and that is what I would like to ultimately implement, but for my initial design I will use straight bluetooth communication from the phone to the collar so I don't overly complicate things right away.

The features I would like to include in the collar/phone combination are:

After looking through the feature set I want above, I'm going to have to completely gut the commercially available collar I'm using for this project. The only components I can use from it are the later parts of the shocking unit chain: everything from the amplifier to the electrodes can stay, but everything else will have to go.

Here is an overview of the features I intend to implement:

Advanced Shocking Mechanism
The "advanced mode" will allow the trainer to set within app: a waveform, basic frequency, pulse duration, pulse repetition frequency, and stimulation level (i.e. amplitude) for the shocking pulse. Initially, the possible waveforms will be chosen from basic shapes (sinusoidal, square, sawtooth, triangle), but I intend to expand on this to permit user generated waveforms.

Once these values are set within the app, the trainer simply depresses the "shock" button (and holds it down for as long as she wishes the stimulation to continue), which transmits the digital waveform to the collar. The collar receives transmission, demodulates it, and passes along the received waveform to the DAC. The output of the DAC is amplified, and the output of the amplifier is passed on to the step up voltage transformer, which is connected to the electrodes, which are in contact with the pony.

Being able to choose the waveform, basic frequency, pulse length, and pulse repetition frequency in addition to the amplitude gives the trainer significantly more granularity in determining the sensation the pony experiences.

GPS Corralling
The second feature is "corralling" the pony. The collar will contain a GPS module (I priced one out, and they're only about $50 for a small board). The accuracy of the GPS module is approx. 2.5m, and it will refresh its location 20 times per second. On a command from the trainer via the app, the current location of the pony will be stored in the collar's memory.

The trainer can then specify the size of the "corral", which will transmitted to the collar and also be stored in the collar's memory. The microprocessor on board the collar will then compare the distance from the collar's current location to the original "set" location 20 times per second. If the distance between the current and set location is less than the preset "corral" size, it will do nothing. If the distance is greater than the preset size, the microprocessor will pass on a simple, pre-determined waveform to the shocking unit, which will amplify it and deliver the shock.

Since the GPS unit is contained on the collar itself, and both the "set" location and corral size are stored within the collar's own memory, corralling is a "set and forget" feature. Even if the trainer walks away from the pony and the app loses contact with the collar, the pony must remain within the pre-designated area until the feature is disabled by the trainer from within the app interface.

Accelerometer Motion Restriction/Enforcement
The third feature utilizes a 3 axis accelerometer to track the movement of the pony (i.e. walking). The trainer will set from within the app whether or not the "movement" module should be active. This binary value is stored in the collar's memory. The trainer will also specify a numerical speed for the pony, which is transmitted to the collar and also stored in memory.

When the value of the "movement" variable is true, the microprocessor will accept the output of each of the accelerometer's axes and calculate a speed for the pony by averaging several samples of the accelerometer (the accelerometer I was thinking of using has a sample rate of 50Hz, so averaging 5 samples would give an average sampling rate of 10Hz, which might or might not be sufficient). The speed will then be compared to the value set by the trainer (and now stored in memory). The error between the values must remain below a preset threshold (which will have to be empirically determined) otherwise the pony will receive a shock.

Thus if the "speed" value set by the trainer is 0, the pony will have to remain still. This also has the advantage of allowing the trainer to keep the pony in four legged mode by simply making him get onto all fours and then setting the speed value to 0. Alternatively, the trainer may set the "speed" value to something other than 0 and require the pony to move at the speed specified (though it can be walking in place or in circles, so it would still be compatible with the corralling feature).

Similar to the corralling, the motion restriction/enforcement is also "set and forget" since all values are stored within the collar's own memory.

Piezoelectric Noise Sensing
A piezoelectric is held in contact with the front part of the pony's neck (attached to the inside of a collar). The output of the piezo is amplified and used as an input to the microprocessor. If the trainer sets the collar to "quiet" mode within the app, this value is transmitted to the collar, where it is stored in memory. The trainer is then able to select an integer value from 1-10 that determines how quiet the pony is to be. This value is also transmitted to the collar and stored in memory there.

When the "quiet" value is true, the microprocessor will accept the amplified piezo signal and compare it to a preset (empirically determined) minimal value multiplied by the integer selected by the trainer. If the amplified piezo signal is greater than the product of those two values, the pony will receive a shock, otherwise the collar will do nothing.

The value from piezo will be sampled at an appropriate rate (likely around 48kHz) to ensure adequate sampling of the pony's noises while still attempting to conserve battery life.

Ideally, I would like to include a DSP to do the Fourier analysis of a ponyboy's whinny in-collar to permit/require the pony to whinny (based on comparison and error analysis to a pre-recorded whinny or set of whinnies), but a quality one of these is not inexpensive, and I'm not really sure what the accuracy would be, so I'm leaving that part for future development.

Development
With the overall design outlined, my next step is to develop the barebones application to communicate with the collar over a standard bluetooth communication protocol and deliver a shock. With a rough user interface made, I'll add on the features in the order outlined above. Hopefully, I'll at least have a working app that can send advanced waveforms to the collar over bluetooth in the near future (this only requires a simple DAC in addition to the bluetooth communication interface, so no need to get fancy with the microcontroller right away).

Overall design of the smartphone controlled shock collar

What do you think? Are there any other features you would like to see included? If so, please let me know. Since the design isn't final, I would love to include other features that might be useful to human pony trainers.