Detecting buttsex

You will recall that in my initial sensing application I failed to check to see if I could detect buttsex. Well, I am pleased to report that I have progressed somewhat from that! It took a while for me to work up the nerve, because my mold is a little thick and it’s been a while, if you know what I mean.

Anyway, science and a little boredom gave me the opportunity to test the insertable toy with all three gestures I wanted to detect.

You may recall that a hand job is quite unique with very clear signals from all of the sensors:

Hand job raw sensing data.

What is especially unique about the hand job is typically the hand can’t stimulate the entire shaft when it’s fully “in” this results in the tip of the toy poking out of your hand. Even if you had a particularly large hand, i would hazard that because of the shape of your hand, the tip would still lose stimulus at the peak of the “in” stroke.

A blow job is similar except that the tip gets stimulated in varied and complex ways when it enters the mouth, likely due to saliva. Also, I personally wasn’t about to uniformly stimulate the base of the shaft with my mouth alone.

Raw sensing data during a blow job.

Finally, the data you have all been waiting for. Insertion into the butt looks like so:

Raw data sensing in the butt.

Note that it’s a very different story to the previous two data sets. the tip is stimulated on entry and is essentially always stimulated throughout. This is even when I withdrew it as far as I dared. I think this is because even when it’s no longer inserted, your body is still close enough to the device to act as a capacitive body, even without direct contact or pressure.

With the above data I was able to crudely detect the difference between a hand job and butt stuff using the DTW algorithm “most of the time”. Evidence suggests I will need to improve my normalisation algorithm because in cases where a dataset is “flat” (e.g. as in the butt stuff), the normalisation tends to unnecessarily amplify noise, which can result in false positives. I also suspect that the 8 point moving average might be a little too aggressive.

Detecting cum with voltammetry

After my little stint of research, I set about putting the theory into practice. Before I go into it, here is a video of detection working (warning, contains bodily fluids).

Warning, this video contains bodily fluids.

Fluids in order: water, lube, salt water, urine, semen.

My laptop keyboard still has suspicious fluids on it…

Please note the above video is a best case scenario and a lot of testing is still required!

My first attempt was to just pass 5v into various samples and see what they did. I used the #2 digital output pin on the Arduino to control whether or not any power was sent to the sample and a 10 kΩ shunt resistor so I could measure the current across the sample by reading the A0 analog in for the Arduino. I measured the current once every 10 ms for 2 seconds, then rested the sample for 2 seconds.

The results were encouraging.

The graph below shows one round of stimulation of a sample of water, the orange line represents voltage in (5v) and the blue line is the current measurement. You can see I rest the sample between trials for 2 seconds (important).

Change in current over time when sending 5v through water.

The following shows the change in current measured in a sample of cum.

Change in current over time when sending 5v through cum.

So, there’s definitely something happening, the current across the sample is changing for the duration of the stimulation (2 seconds), but how to get a more meaningful comparison? I knew that I needed at least 1.23 v to electrolise water into into oxygen and hydrogen, but I didn’t want to use much more than that. I used a simple voltage divider made from two 22 k Ω resistors, resulting in something close to 1.8 v across the sample, which seemed to work OK.

Apologies to electrical engineers who are offended by my poor diagram.

After taking many samples and calculating an average for each sample, I could say with confidence that on average, a 2 second stimulation of the various samples looks like this:

Average change in current over time for different samples.

Now, it looks pretty cut & dry: cum has on average a much much lower final current after 2 seconds. Why not just measure the current value after 2 seconds of stimulation and if it’s below a threshold (say 35 in the example above), then it’s cum? Well, the problem is that this is an average, the real data is a whole lot messier:

Change in current over time, just for the cum sample. There’s a wide variety of data points.

Change in current over time for the urine sample only.

The fact that cum has a very distinctive “shape” on the average graph gave me the encouragement to try harder to untangle signal from the noise.

To overcome the variability in the data I did two things: firstly I took a 5 point moving average for all points, to smooth them out a little. I then expressed every set of 5 points as a ratio of the first 5 points. So, to get the value for point 8, I would calculate Average(Points(8-12))/Average(Points(1-5)), which is actually the same as Sum(Points(8-12))/Sum(Points(1-5)).

This resulted in the following graph (once again, taken as an average):

Ratio of the 5 point moving average to the first 5 point moving average.

That’s all very well, but this is still an average, how do we handle the fact that each trial (each time I stimulate a sample) may have variability to it? Looking at the minimum and maximums rather than the averages, we get this:

Minimum and Maximum current ratios.

If you look carefully, you can see at about 10 or 15 (between 100 and 150 ms), there’s a promising gap between all other minimums and the maximum value for cum. I focused my attention on this ratio.

So, that’s it right? If the ratio between the first 5 points and points 10-15 is less than 0.8, we have cum! Well, yes and no. As I said before, by passing a current through the sample, we are actually changing it, so we need to consider how the nature of the sample changes over time. Also, I wanted to speed up the time taken to get a result, up until now, I was stimulating for 2 seconds and resting for 2 seconds, that was quite slow for the detection I wanted.

So, I sped it up, this time allowing the sample to rest only 100 ms and stimulating for only 200. I then recorded the ratio and plotted it over time. So, the graph below is showing many hundreds of trials (a cycle of stimulation and rest for the sample), where the x-axis is the trial number.

Fast sampling over time

Saliva appears to be quite unstable over time. All other samples I used appear to stabilise well above the ratio for cum. Saliva, however, comes dangerously close. To be fair, I don’t mind so much if I get false positives on saliva since I am not expecting saliva to find it’s way inside the masturbator toy.

I am still worried that the samples do change a fair bit over time, making stable readings difficult. I also note that my simple copper electrodes may not be good enough. The positive electrode slowly builds up a black layer of oxidation, probably from the electrolysis.

Simple code for the detector is here: voltammetry2.sdf.ino

Approaches for detecting cum

It’s been referred to as the “holy grail” of teledildonics, and in my hubris, I want to have a go at detecting male ejaculation. Why ejaculation? Well, this is specifically for uses where someone is playing with a male masturbator toy and they climax. Wouldn’t it be great if they got some kind of feedback for their effort? Maybe the game gives them a reward or the content changes somewhat. Without detecting their climax, there’s no way for the system to do so.

Such a detector would need to be:

  • Affordable (let’s say, less than $50 per sensor)
  • Safe (don’t want to give them a nasty shock or chemical burn as they cum)
  • No false negatives (would be disappointing even if it failed to work just once)
  • No false positives for other common fluids (lube, urine, pre-cum, saliva, water and sweat)
  • Nearly immediate – no point in recognising cum some minutes after the event!
  • Robust against environmental factors (like humidity or what they had for dinner)

I set about researching a number of techniques which I thought would bear fruit:

Florescence: The first thought one might have is to do what they do in the movies and use “black light” or UV. From reading this post on the florescence of semen, it turns out that you need Luminol to trigger semen’s fluorescence with UV, though it sill fluoresce under blue light. Besides all that, these fluorescence based tests only appear to work on dry semen, not liquid semen. This fails the “immediate” test.

pH: At between 7 and 8 on the pH scale, semen is slightly basic, but not enough that using a pH sensor is going to give you a distinguishing marker verus, say, tap water. Also, this pH would probably can vary from person to person. Finally, the pH sensors I have seen are rather bulky.

Spectral Analysis: From semen’s spectral response it looks like the 1650 cm-1 wave number range is good for detecting cum. Detection works this way because certain organic compounds in semen vibrate at a certain frequency. These compounds are found in many other organic samples. The problem with this approach is, this frequency is in the mid-range IR, which is very expensive to produce and detect since it’s so close to heat. It would require expensive specialised apparatus to do it this way and it would most likely both destroy the sample and possibly burn your penis in the process.

Resistance: I tried measuring the resistance of cum using various approaches, but just when I thought I understood how it related to other fluids, I got different readings. Besides which, urine (at approximately  70k ohms) is quite a good conductor compared to cum (about 700k ohms).

Electro-chemical: After reading this paper about detecting chemicals. It made sense to me that whatever technique is used to detect glucose in blood or specific ions in solution should be able to work with cum, because I knew cum contained some salts, in particular sodium and potassium ions (see Biochemistry of semen and the Wikipedia page for semen). We were finally getting somewhere!

Voltammetry: A technique known as Voltammetry, passes a known voltage through a sample and observes how the current through the sample changes over time. This recognises the fact that the act of passing a current through a solution will perform some kind of electrolysis on the solution.

Finally, the phenomenon where semen’s resistance changed over time made sense! You see, whenever you pass a current (no matter how small) through a sample such as semen, you are going to change its chemical composition somewhat. We can measure that change by measuring a change in current.

Next, I actually implement a voltammetric apparatus for detecting cum.

Insertable Speed Detection the Easy Way

So, I have gesture detection working relatively well, the next hurdle is speed of the gesture. It sounds like a relatively simple problem to solve, but it’s deceptively complex, especially since we’re dealing with a series of data points.

In the video above, I am using a simple moving average on stream 3 of the input. Whenever the current data point drops below the moving average, that’s considered an “out”, when it drops above, that’s considered an “in”, the result is data that looks something like this:

Every time the blue line crosses the yellow line, we count a “tick”. Speed is the number of ticks in the last 16 samples.

Whenever the data value crosses the moving average in any direction, I consider that a “tick”. I then count the number of ticks in the last n samples to get an average speed during those samples.

It works surprisingly well, you could increase the number of samples to get a smoother speed calculation, but I think a responsive value is better. I am currently summing across 16 ticks.

In theory, a Fast Fourier Transform should be able to give me the frequency of the signal I am recording and that frequency could be used to approximate speed of the “hand job” gesture. In practice, I think the moving average approach is relatively computationally cheap as well as robust.

Insertable gesture detection using DTW

I am pleased to report that the stream of data I have been collecting off the insertable device can be used to detect different user gestures. Gestures you ask? Well, I want to be able to tell what the user is doing with the device (e.g. blowjob, licking, hand job and penetrative buttsex). Not sure if I can tell the difference between a vagina and a butt, but why not try?

The video below shows the device distinguishing between blow jobs and hand jobs.

The detection algorithm is taken from the excellent Kinect DTW implementation.

Dynamic Time Warping (or DTW) is a great little solution for matching time-series data where the data points might be stretched or squashed over time. Apart from detecting blow jobs it has been used for speech recognition among other things.

I retrieve the stream of 8 data points from the device, let’s call a collection of these 8 data points a set. I get a set every 100 ms. When I have more than 8 sets of data, I attempt to match those 8 sets of 8 data points to a prerecorded “example” sequence of 32 sets in memory using the Dynamic Time Warping algorithm.

The image below is an example sequence of a “hand job” gesture:

Template sequence used to determine if a gesture is a hand job.

Because lube and other environmental factors can change the baseline considerably, I “normalise” the data to a value from 0 to 1 for each independent stream (line) of data. This seems to be a pretty robust approach.

Template sequence normalised to remove bias due to environmental factors. .

Normalising in this way is helpful, especially if you consider that the conductive silicone will also have a capacitance and due to my imperfect construction process, I can’t guarantee this will be consistent in any way.

A last step (which I haven’t yet tried but will shortly) is to apply a simple moving average to smooth the data out. This should result in more reliable matches.

The normalised sequence is smoothed to allow for more reliable detection.

I have been able to get this same algorithm working in C# as well as Renpy, a Python based gaming engine I intend to use for a game that interacts with the device. Unfortunately Renpy is a little too slow for the processing and is not really designed for this kind of real-time processing anyway.

Next step: move the gesture recognition processing onto the arduino itself for performance reasons. Turns out there’s not enough memory to implement a DTW algorithm for more than one gesture on an arduino. Never mind, I learnt how to do threads in Renpy instead (renpy.invoke_in_thread).

Insertable toy prototype

So, here we are, the moment you have all been waiting for: behold a working prototype of an insertable toy.

After building up the layered conductive and non-conductive silicone per my insertable design, the next challenge was getting a negative mold of a penis. My penis to be precise, because I wanted the first prototype to be of my own wang!

I managed to make a 3D model of a fox using 32 still images.
I managed to make a 3D model of a fox using 32 still images.

Turns out it’s a lot harder than you think to make a clone of your penis. I investigated doing a 3D scan using photogammetry, which could have worked but it really requires a lot more of a “still” model as it were. I did, however, get this great 3D model of a plush fox by taking 32 still images and stitching them together in 3D using freely available software.

The negative penis mold life-cast with alginate.
The negative penis mold life-cast with alginate.

In the end, I bought one of those “clone a willy” kits. “Casting from life” as it’s called is usually done with alginate (the same stuff that’s used to make a mold of your teeth at the dentist). It’s body-safe, non-toxic and (unlike plaster of Paris) doesn’t heat up as it sets, but it also sets rather rapidly so you have to be quick. It’s also heavily reliant on water to keep its shape so you have to keep it well hydrated. I found that filling the negative mold with water and putting it in the fridge allowed it to last longer.

You have to get the temperature of the alginate correct (32 degrees C) whilst maintaining an erection, all within 2 minutes. It took a few goes, but I managed it (with a little help).

The sensing core for the insertable held together better than I expected.
The sensing core for the insertable held together better than I expected.

The other, most important part, was getting a protective layer of silicone around the sensing apparatus because I didn’t want little carbon fibres poking people in the butt. The sensing apparatus had now developed into a rather scary looking porcupine with 8 wires coming out of it, terminated by alligator clips.

Effectively what I am trying for is a process known as overmolding, where you mold a material over another to achieve the desired effect.

The silicone that came with the “Clone a willy” kit was a harder shore value than the silicone I already had, it was also much slower to cure. For this reason, when I poured it into the negative, it just pooled in the tip and didn’t really cover the sides as I hoped. So, I used my softer, faster curing silicone to coat the inside first, filled it with the (pink) harder silicone and then rammed the sensing apparatus down the center of the mold.

To be honest, I don’t think this is entirely the best approach and will need some re-thinking.

Once I hooked up the alligator clips to pins 4 through 11 on the MPR-121 shield, I was able to output tab separated values out onto the serial port. The Arduino software I am using conveniently converts those into a graph if you like.

The insertable test script is here. Note that I overwrote the initial voltage and threshold values in a bit of a brute-force manner because I didn’t want to mess with the existing cpp files that come with the MPR-121.

I get nice clean signals when I interact with ant part of the device, cleaner than I expected. My next challenge is interpreting all this data as “gestures”. I am thinking of getting information like % insertion, speed (rpm) and the kind of activity (e.g. touch, buttsex, handjob, blowjob, lick, squeeze, etc).

I think the dynamic time warp algorithm would be ideal for this kind of processing because not only could it match gesture curves without being time-based, the amount of “time warp” I get could tell me how fast the gesture is happening.

Of course, after I have done all this work, I discovered the concept of Swept Frequency Capacitive Sensing which could actually be the ultimate answer to my challenge.  I guess we’ll see how we go!

Next: See how I implemented the gesture recognition for the insertable toy.