<?xml version="1.0" encoding="UTF-8"?>
	<rss version="2.0"
		xmlns:content="http://purl.org/rss/1.0/modules/content/"
		xmlns:wfw="http://wellformedweb.org/CommentAPI/"
		xmlns:dc="http://purl.org/dc/elements/1.1/"
		xmlns:atom="http://www.w3.org/2005/Atom"

			>

	<channel>
		<title>Cycling 74  &#187;  Topic: Writing an external to communicate with hardware (x-IMU sensor in this case)</title>
		<atom:link href="http://cycling74.com/forums/topic/writing-an-external-to-communicate-with-hardware-x-imu-sensor-in-this-case/feed" rel="self" type="application/rss+xml" />
		<link>http://cycling74.com/forums/topic/writing-an-external-to-communicate-with-hardware-x-imu-sensor-in-this-case/feed</link>
		<description></description>
		<pubDate>Wed, 19 Jun 2013 01:11:57 +0000</pubDate>
		<generator>http://bbpress.org/?v=2.2.4</generator>
		<language></language>

		
														
					
				<item>
					<guid>http://cycling74.com/forums/topic/writing-an-external-to-communicate-with-hardware-x-imu-sensor-in-this-case/#post-64144</guid>
					<title><![CDATA[Writing an external to communicate with hardware (x-IMU sensor in this case)]]></title>
					<link>http://cycling74.com/forums/topic/writing-an-external-to-communicate-with-hardware-x-imu-sensor-in-this-case/#post-64144</link>
					<pubDate>Wed, 29 Aug 2012 17:51:10 +0000</pubDate>
					<dc:creator>Rodrigo</dc:creator>

					<description>
						<![CDATA[
						<p>I&#8217;ve been building a 9DOF wireless sensor thing for a bit and have finally made some good progress on it (though it is far from done), but I might have come into some funding for an art project and am considering buying a &#8220;pro&#8221; module instead of using my DIY project. </p>
<p>I&#8217;ve been eye-balling the x-IMU for a long while now (<a href="http://www.x-io.co.uk" rel="nofollow">http://www.x-io.co.uk</a>). Looking through the (open source) code and reading the paper on the math involved. Basically I&#8217;ve been trying to build a budget version of that. With funding I could just own that. </p>
<p>Now the thing itself is a 9DOF wireless (bluetooth) board with on-board processor to handle all the math/calculations, and in terms of hardware it seems ideal for what I want. It&#8217;s even expandable and has on-board logging etc.. which will be useful in the future. It comes with a (windows) application to handle all the onboard settings. I wrote to them and they don&#8217;t have a mac version of it, but I&#8217;ve managed to run X-CTU fine in a wine wrapper, so I&#8217;m sure this thing would be no different. </p>
<p>In terms of actually interfacing with it I asked them how that would work and they said the following:</p>
<p>&#8220;You would have to create your own interface app that communicates to the x-IMU via serial and then sends the OSC commands to Max.  This does require you to develop and I cannot say how easy or hard this would be for you.  This simple C++ library is a good starting point:</p>
<p><a href="http://www.x-io.co.uk/res/sw/ximu_simple_c_receiver.zip&#038;#8221" rel="nofollow">http://www.x-io.co.uk/res/sw/ximu_simple_c_receiver.zip&#038;#8221</a>;</p>
<p>(the main body of the code below)</p>
<p>So it looks like it would need to interface with a dedicated program. I&#8217;m wondering how difficult it would be to implement that as an external, to do everything IN max. I&#8217;ve never created an external before, but seeing as the code is there already, and doesn&#8217;t really do anything but act as an interface between the device and Max, I&#8217;m thinking it shouldn&#8217;t be too hard. I&#8217;ve seen a couple posts on creating externals in Max, and I think Eric Lyon was even writing a book on that (not sure if that came out yet). This is small time compared to that as this doesn&#8217;t &#8220;do&#8221; much.</p>
<p>I asked about the bluetooth side of things and they said that connectivity is handled on the OS level, but I don&#8217;t know if it would require something like the wiimote objects where you &#8220;connect&#8221; or &#8220;disconnect&#8221; the object. </p>
<p>Has anyone written something like this before? (Not specifically for the x-IMU, but for a dedicated piece of hardware)<br />
How close would this be to a wiimote type external? (aka or ajh)<br />
Was it difficult to &#8216;wrap&#8217; the code into an external?<br />
How about making it for windows as well as mac? (I&#8217;d like to share the results)</p>
<p>Here&#8217;s the .c part of the code from the zip above.</p>
<p>//=====================================================================================================<br />
// Example.cpp<br />
// 06/08/2012<br />
//=====================================================================================================</p>
<p>//&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
// Includes</p>
<p>#include <fcntl .h><br />
#include <stdio .h><br />
#include <string .h><br />
#include <termios .h><br />
#include <unistd .h><br />
#include &#8220;xIMUReceiver.h&#8221;</unistd></termios></string></stdio></fcntl></p>
<p>//&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
// Functions</p>
<p>int main(void) {</p>
<p>	// Serial port variables<br />
	int serialHandle;<br />
	struct termios options;<br />
	unsigned char numBytes;<br />
	unsigned char serialBuf[256];</p>
<p>	// Packet decoding variables<br />
	unsigned char rxBuf[256];<br />
	unsigned char rxBufSize = 0;<br />
	ErrorCode ErrorCode = ErrNoError;<br />
	PacketHeader packetHeader;</p>
<p>	// Open serial port<br />
	serialHandle = open( &#8220;/dev/ttyUSB0&#8243;, O_RDWR | O_NOCTTY );<br />
	if (serialHandle == -1) {<br />
		printf(&#8220;Could not open serial portn&#8221;);<br />
	}<br />
	else {<br />
		fcntl(serialHandle, F_SETFL, 0);<br />
		printf(&#8220;Opened serial port successfully!n&#8221;);<br />
	}<br />
	bzero(&#038;options, sizeof(options)); 	// set all bits to zero<br />
	options.c_cflag = B115200 | CRTSCTS | CS8 | CLOCAL | CREAD;<br />
	tcflush(serialHandle, TCIFLUSH); 				// clean the serial line<br />
	tcsetattr(serialHandle, TCSANOW, &#038;options); 	//set the new option for the port</p>
<p>	// Main loop<br />
	while(1) {<br />
		// Fetch data from serial port<br />
		numBytes = read(serialHandle, &#038;serialBuf, sizeof(serialBuf));</p>
<p>		// Process each byte<br />
		for(int i = 0; i < numBytes; i++) {</p>
</p><p>			// Add data to receive buffer<br />
			rxBuf[rxBufSize++] = serialBuf[i];</p>
<p>			// Process receive buffer if framing char received<br />
			if(xIMUReceiverIsFramingChar(serialBuf[i]))	{<br />
				ErrorCode = xIMUReceiverProcess(rxBuf, rxBufSize, &#038;packetHeader);<br />
				rxBufSize = 0;	// clear receive buffer</p>
<p>				// Print data if decoded successfully else print Error code<br />
				if(ErrorCode == ErrNoError) {<br />
					switch(packetHeader) {<br />
						case(PktCalInertialAndMagneticData):<br />
							printf(&#8220;Gyr: %8.2f, %8.2f, %8.2f, Acc: %8.2f, %8.2f, %8.2f, Mag: %8.2f, %8.2f, %8.2fn&#8221;,gyroscope[0], gyroscope[1], gyroscope[2], accelerometer[0], accelerometer[1], accelerometer[2], magnetometer[0], magnetometer[1], magnetometer[2]);<br />
							break;<br />
						case(PktQuaternionData):<br />
							printf(&#8220;Pitch = %6.1f, tRoll = %6.1f, tYaw = %6.1fn&#8221;, eulerAngles[0], eulerAngles[1], eulerAngles[2]);<br />
							break;<br />
						default:<br />
							break;<br />
					}<br />
				}<br />
				else{<br />
					printf(&#8220;Error Code: %dn&#8221;, ErrorCode);<br />
				}<br />
			}<br />
		}<br />
	}<br />
}</p>
<p>//=====================================================================================================<br />
// End of file<br />
//=====================================================================================================</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/writing-an-external-to-communicate-with-hardware-x-imu-sensor-in-this-case/#post-231369</guid>
					<title><![CDATA[Re: Writing an external to communicate with hardware (x-IMU sensor in this case)]]></title>
					<link>http://cycling74.com/forums/topic/writing-an-external-to-communicate-with-hardware-x-imu-sensor-in-this-case/#post-231369</link>
					<pubDate>Fri, 31 Aug 2012 00:13:35 +0000</pubDate>
					<dc:creator>Rodrigo</dc:creator>

					<description>
						<![CDATA[
						<p>This thread seems to have some good resources, but I&#8217;m still not sure how bluetooth/connectivity is to be handled (or the port-ability of the above code).</p>
<p><a href="http://cycling74.com/forums/topic.php?id=28990" rel="nofollow">http://cycling74.com/forums/topic.php?id=28990</a></p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/writing-an-external-to-communicate-with-hardware-x-imu-sensor-in-this-case/#post-231370</guid>
					<title><![CDATA[Re: Writing an external to communicate with hardware (x-IMU sensor in this case)]]></title>
					<link>http://cycling74.com/forums/topic/writing-an-external-to-communicate-with-hardware-x-imu-sensor-in-this-case/#post-231370</link>
					<pubDate>Fri, 31 Aug 2012 08:18:05 +0000</pubDate>
					<dc:creator>Peter Castine</dc:creator>

					<description>
						<![CDATA[
						<p>I&#8217;ve written a fair few externals interfacing to different hardware interfaces. As long as the interface API is reasonably documented and works as advertised it&#8217;s not a big deal for anyone experienced with writing externals. </p>
<p>That said, by the time you&#8217;ve read&#038;understood the hardware API, designed&#038;implemented a wrapper (ie the external) for Max, written some test patches and a .maxhelp file and documented the thing up, a couple of days have come and gone.</p>
<p>As an aside, the information you quote from the manufacturer talks about C++, but the sample code is plain-vanilla C. So the API may well be plain-vanilla (which is in some ways the most straightforward way to go). I wrote one interface that required integrating C, C++, and Objective-C code. This all can be done, but does mean you have to pay attention to which flavor of the language you&#8217;re using when.</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/writing-an-external-to-communicate-with-hardware-x-imu-sensor-in-this-case/#post-231371</guid>
					<title><![CDATA[Re: Writing an external to communicate with hardware (x-IMU sensor in this case)]]></title>
					<link>http://cycling74.com/forums/topic/writing-an-external-to-communicate-with-hardware-x-imu-sensor-in-this-case/#post-231371</link>
					<pubDate>Fri, 31 Aug 2012 12:11:52 +0000</pubDate>
					<dc:creator>Rodrigo</dc:creator>

					<description>
						<![CDATA[
						<p>There&#8217;s a full API listed here:</p>
<p><a href="http://www.x-io.co.uk/node/9#ximu_api" rel="nofollow">http://www.x-io.co.uk/node/9#ximu_api</a></p>
<p>And it looks like it&#8217;s in C# and written for Microsoft .NET (will that be a problem for writing a Mac external?)</p>
<p>I&#8217;ve not worked with hardware (or software) APIs before, so I&#8217;m not exactly sure what I&#8217;m looking at. It looks like a few dozen .cs files and a .csproj file, but I take it these are the things that the external would call/access, all of this is what would be wrapped in the external. (ie I can just pack up all the data a certain way and have it come out a single outlet (like the wiimote objects where you &#8216;route&#8217; off the bits you need/want).</p>
						]]>
					</description>

					
					
				</item>

					
		
	</channel>
	</rss>

