Bowsense – A minimalistic Approach to Wireless Motion Sensing Hans WILMERS Norwegian Centre for Technology in Music and the Arts (NOTAM) Nedre Gate 5, 0551 Oslo – Norway [email protected] Abstract should be usable in real stage performance sit- uations. In addition, the device should be easy Anovelwirelessmotionsensingdeviceforcontrolof to extend with external sensors such as push- realtime electronics is presented. The device consists of a small (20×40mm) cir- buttons and a finger pressure sensor. cuit board including all circuitry and battery, and A first model shown in [1] contains a 3D ac- contains a complete inertial measuring unit (IMU), celerometer, and a 2D gyroscope providing an- measuring both acceleration and angular velocity in gular velocity. The second model now contains 3 dimensions. Data is transmitted wirelessly via a a3rdgyroscope, enhancingthedevicetoacom- bluetooth link and can be read from applications plete IMU with 6 degrees of freedom. It is thus either using bluetooth serial emulation, or using a possibletocalculateagoodestimatefortheori- smallstandaloneserverapplicationthatconvertsin- entation of the device in respect to the gravity coming data and sends reformatted data out via OSC. vector. Keywords 3 Electronics Wireless, Bluetooth, Bow, Motion, Controller The first model contained a 1.5V AAA battery and a step-up converter. This solution was re- 1 Introduction placed by a Li-Polymer battery, reducing both weight and complexity of the design. A battery In [1] a new sensorbow project was presented charger was integrated into the device, and the - a project that was started at the Norwe- battery can be mounted in a way that enables gian Academy of Music in colaboration with “emergency exchange” in stage situations. The NOTAM. The project is primarily focused on device can be charged from a standard mini- the artistic value of augmenting string instru- USB cable. ments, but some of our findings can be applied Toreducenoiseintheanalogcircuitry,thede- to other controlling tasks, and the sensor device vicecontainsaseparate3V lowdropoutregula- itself is versatile and flexible in design. In fact, tor for the analog supply, and a 3.3V regulator the hardware and software design itself is open, for digital components, including the bluetooth and can be retrieved from the author’s website. module. With this circuitry, the device is able In this article, the main focus is on the elec- to run very near the cutoff-voltage of a typical tronics used in the project, the technical chal- Li-Polymer battery, and the resulting runtime lenges encountered on the way, and the solu- is well over 2h. tions to them. Function Component 2 Sensing the Bow Microcontroller C8051F530 / Silabs Wirelessmotionsensingdeviceshaveexistedfor Bluetooth Module RN41 / Roving Networks quite a while. Many of these have been used Accelerometer ADXL330 / Analog Dev. with bowed string instruments [2; 3; 4; 5], and Gyroscope, X/Y IDG300 / Invensense severalhavehadtheaimofaugmentingexisting Gyroscope, Z LISY300AL / ST instruments by adding new controlling possibil- Battery LPP402025 / Varta ities [3; 4; 5]. Battery Charger MCP73831 / Microchip For our project, a new device was devel- oped that could be adapted closely to the task. Table 1: Components It needed to be small and inobtrusive, and it The device is built around a C8051F530 microcontroller from Silabs, which contains a 25MIPS core and a 12bit A/D-converter that can be used with any of the unused port pins. Withatotalof16portpins, and5oftheseused fordigitalsignals, thisleavesupto11inputsfor analog values. Of these, one is used to sample the battery voltage, 3 for the 3D accelerometer, and another 3 for the gyroscopes. The remain- ing 4 unused inputs are made available at the edge of the PCB, and can be used to connect additional sensors to the device. Asabluetoothtransmitter,theRN41module made by Roving Networks is used. The RN41 has a max. range of 100m in open air. Data Figure 1: Front view, showing processor and is sent into the module by a serial port with gyroscopes. The bluetooth module and the ac- 115kbaud. As the bluetooth data rate drops celerometer are mounted on the back. considerablywithincreasingdistance,hardware flow control is used to avoid data loss. In the choice of sensors, both technical spec- colusedbyDanOverholtontheCUI[6]device. ifications and resulting simplicity of the design Every data item is sent as a 2byte integer (low were important criteria. All sensors in this de- byte first), and each packet framed by a hard- sign can run from 3V, so a single analog sup- coded sequence. The resulting packet length is ply was sufficient. The sensor outputs are con- constant. nected to analog inputs of the microcontroller, with only a few additional passive components. Header Data Footer As accelerometer, an ADXL330 from Ana- 0x23 0x40 data0, data1, ... 0x24 log Devices is used. It measures up to ±3g (1) along 3 axes X,Y (along the PCB surface) Table 2: Transfer Protocol and Z (perpendicular to the surface). To mea- sure angular velocity in 3 dimensions, two gyro- scopes are used: An IDG300 from Invensense, Data can be sent with a rate of up to measuring up to ±500deg/s around the X and 200samples/s. Y axes, and a LISY300AL from ST, measur- Sending slip encoded OSC messages directly ing up to ±300deg/s around the Z axis. The wastested,butasnumericaldatavaluesinOSC battery used (Varta LPP402025) is a single cell are sent as 4bytes, this approximately doubles Li-Polymerbatterywithacapacityof150mAh, the bandwidth requirement. It would certainly and a weight of under 4g (2). The total weight be nice to define smaller OSC data types. Here, of the sensor board inkl. battery is approxi- theefforttointroducetheuOSC[7]variantmay mately 12g. beastepintherightdirection,althoughsmaller The electronics layout was done with Eagle data types are not yet part of the specification. 5.3 professional, but as only two PCB layers are 5 Calibration used, further work can be done with the free edition Eagle Light. Special consideration has MEMS 3 components such as the sensors used been made to make handsoldering of the board in this design typically reveal significant errors possible,thenecessaryexperienceandtoolspro- in offset and scale. Especially the offset can be vided. affected considerably by the mechanical stress thatoccurswhenmountingthecomponent,and 4 Transfer Protocol in some components by temperature. It is thus Data is sent via bluetooth, using the Serial Port possible to calibrate the sensors on the finished Profile (SPP). A very simple binary packet pro- board,andexpectlittlechangeintheoffsetover tocol is used, which was derived from the proto- time, but only if temperature can be kept close to the calibration conditions. 1with 1g=9.81m/s2 2with 1g=1gram 3Micro-Electro-Mechanical System However, in some applications even a small cosα ∼ 1, with an error of less than 0.1%. This offset in angular velocity must be avoided. We will lead to following simplification: know that for most musicians, the mean rota- tion speed of a device attached to the body is 1 0 0 small, seen against the magnitude of the mo- R = 0 1 −α (2) tionsofinterest. Thegyroscopeoffsetcanthere- 0 α 1 fore be removed almost completely by applying Thegeneralcaseofasmallrotationbyangles ahighpasswithaverylongtimeconstanttothe α,β,γ can be written as: output values. Removing the offset from the accelerometer 1 −γ β output values is more complicated, as the in- fluence of gravity in general prevents the mean R = γ 1 −α (3) −β α 1 acceleration to become zero. We will later show a method to estimate the direction of gravity in If this is applied iteratively, the resulting vec- respect to the sensor device, and to effectively tor will grow slowly, and in addition rounding calibrate offset and scale of both the accelerom- errors can accumulate. This can be corrected eters and the gyroscopes automatically. by scaling the vector to unity length. Drift in the orientation of the estimated gravity can be 6 Where is gravity? corrected by adding a small portion †~a of the Theorientationofanobjectinspacecanbecon- measured acceleration~a. trolled very intuitively by a musician, and may The algorithm for one iteration step is as fol- therefore be a good control parameter for mu- lows (for simplicity, scaling to unity length is sic applications. Also, knowing the direction of omitted): gravity will make it easy to split the measured acceleration into two parts, one part equaling 1 −γ β gravity, and the other equaling the dynamic ac- ~g0 = γ 1 −α ~g+†~a (4) celeration of the object. −β α 1 Todeterminetheorientationofthedeviceto- wards gravity, the gravity vector can be esti- An algorithm based on this concept is imple- matedfromthemeasureddata. In[8], agravity mented in the bowsense firmware. estimator that is also used to correct for offset If the additional assumption can be made in angular rate is constructed using a Kalman that acceleration and angular rate of the ob- Filter. In [9], a gravity estimator that is used ject are not strongly correlated, the result of to compensate for the effect of gravity is con- the gravity estimator could be used to calibrate structed using rotation by the integrated angu- both the gyroscope and the accelerometer off- lar rate. setautomatically: Theangledifferencebetween The gravity estimator proposed here is based the estimated gravity vector and the measured on continously iterated coordinate rotation, de- acceleration vector could be used to correct the pending on the measured angular rate. It is so scaleofthegyroscopes. Eachofthecomponents simplethatitcanbeimplementedinfixedpoint x,y,z of the estimated gravity vector could be arithmetic, and without the use of trigonomet- used to correct the offset of the corresponding ric functions. accelerometer when small, and to correct the A coordinate rotation by an angle α around scale, when big. the X-axis can be defined by following rotation A tested and finetuned algorithm for auto- matrix: matic calibration is subject to further investi- gation. 1 0 0 R = 0 cosα −sinα (1) 7 Firmware 0 sinα cosα The firmware resources are constrained by the With a data rate of 200 samples/s, and if the internal 256byte RAM and 8kbyte FLASH assumption can be made that the typical an- memory of the C8051F530 microcontroller. In gular rate does not exceed 360 deg/s, the ex- the most recent version, less than 2kbyte pected angle differences from one sample to the FLASH is used for program storage, leaving next are small, and we can write sinα ∼ α and space for future enhancements. The firmware is written in C, and compiled [6] Dan Overholt. Musical interaction de- with Keil C51. It could probably be ported to sign with the create usb interface. Proc. the SDCC compiler suite with little effort. ICMC2006, International Computer Music Conference, New Orleans, 2006. 8 Conclusions [7] Andy Schmeder and Adrian Freed. uosc: A compact 6 degrees IMU system has been pre- The open sound control reference platform sented, that can be used as a wireless controller for embedded devices. Proc. NIME2008, for realtime music applications. The hardware New Interfaces for Musical Expression, is easily extendible, either by connecting sen- Genova, 2008. sors to the existing board, or by extending the [8] H. J. Luinge and P. H. Veltink. Measur- design based on existing material. ing orientation of human body segments us- A simple algorithm that calculates an esti- ing miniature gyroscopes and accelerome- mateforthegravityvectorhasbeenshown,and ters. MedicalandBiologicalEngineeringand the algorithm may be used for automatic sensor Computing, 43:273–282, 2005. calibration. More information can be found at: [9] ManuelaBandalaandMalcolmJoyce. Wire- http://notam02.no/proj/bowsense less inertial sensor for tumour motion track- ing. Journal of Physics: Conference Series, 9 Acknowledgements 76, 2007. Special appreciation goes to the Norwegian Academy of Music, namely Knut Guettler, Vic- toria Johnson and Haakon Thelin for inspiring cooperation in the sensorbow project. Thanks also to Dan Overholt, Anders Vinjar and Giso Grimm for participating in the implementation and debugging of the transfer protocol and con- version to OSC. References [1] Knut Guettler, Hans Wilmers, and Victo- ria Johnson. Victoria counts - a case study withelectronicviolinbow.Proc.ICMC2008, International Computer Music Conference, Belfast, 2008. [2] A. Askenfelt. Measurement of bow mo- tion and bow force in violin playing. Jour- nal of the Acoustical Society of America, 80(4):1007–1015, 1986. [3] F. Bevilacqua, N. Rasamimanana, and E. Flety. The augmented violin project: research, composition and performance re- port. Proc. NIME2006, New Interfaces for Musical Expression, Paris, 2006. [4] Keith A. McMillen. Stage-worthy sen- sor bows for stringed instruments. Proc. NIME2008, New Interfaces for Musical Ex- pression, Genova, 2008. [5] Diana Young. The hyperbow: A pre- sision violin interface. Proc. ICMC2002, International Computer Music Conference, G¨oteborg, 2002.