SimpleIDE finds Propeller when BST IDE doesn't
rjo__
Posts: 2,114
I have been using Processing.org to write a serial interface between the Propeller and a Kinect. Everything works fine. Installation of the Kinect libraries for Processing.org to use is a bit rough on a Mac. Nothing on the web seemed to work for me. I ended up just dragging copies of Kinect libraries from OpenNI to everywhere I thought Processing would look for them. Processing is an open platform language and IDE that handles all kinds of data streams. If you haven't heard of it... check it out.
The code below is from the Processing IDE, which interacts with the Kinect to send (over a serial link to the Propeller) the distance (inches) from the Kinect to any object located at the center of the field of view of the Kinect from about 17" and 20 feet. The code can be used to generate a stand alone application, to output a java version, or to run within the Processing IDE.
As you can see... it is very Spinish. The only thing that could confuse a spinhead is the Draw routine... which in fact is a repeat loop. When the code finishes at the bottom... it just goes back to the start of the Draw routine. Everything else seems pretty familiar.
On the Propeller side of things, I am using the BST IDE on a Mac. The code is:
To disconnect, I first stop the Processing.org app. However, when I go to the BST IDE and try to run my program again... it can't find the Propeller.
A fix for this is to put a pause at the beginning of the Propeller app. This will find the Propeller, if the attempt is made within 5 seconds of a reset. The other option is to load to RAM only and have some other more agreeable program
sitting on your EEPROM.
Interestingly... SimpleIDE finds the Propeller on the first try!!!:)
Rich
The code below is from the Processing IDE, which interacts with the Kinect to send (over a serial link to the Propeller) the distance (inches) from the Kinect to any object located at the center of the field of view of the Kinect from about 17" and 20 feet. The code can be used to generate a stand alone application, to output a java version, or to run within the Processing IDE.
import SimpleOpenNI.*; SimpleOpenNI kinect; import processing.serial.*; Serial myPort; int closestValue; int closestX; int closestY; int inByte; float centerdepth; void setup() { size(640, 480); kinect = new SimpleOpenNI(this); kinect.enableDepth(); String portName = Serial.list()[0]; myPort = new Serial(this, portName, 9600); myPort.write(10); myPort.write("Kinect Connected"); } void draw() { closestValue = 8000; kinect.update(); // get the depth array from the kinect int[] depthValues = kinect.depthMap(); // for each row in the depth image for(int y = 0; y < 480; y++){ // look at each pixel in the row for(int x = 0; x < 640; x++){ // pull out the corresponding value from the depth array int i = x + y * 640; int currentDepthValue = depthValues[i]; // if that pixel is the closest one we've seen so far if(currentDepthValue > 0 && currentDepthValue < closestValue){ // save its value closestValue = currentDepthValue; // and save its position (both X and Y coordinates) closestX = x; closestY = y; } } } //draw the depth image on the screen image(kinect.depthImage(),0,0); // draw a red circle over it, // positioned at the X and Y coordinates // we saved of the closest pixel. fill(255,0,0); ellipse(closestX, closestY, 25, 25); int i = 320 + (240 * 640); int currentDepthValue = depthValues[i]; println("closest value=" + closestValue + " Center value=" + currentDepthValue/25.4); fill(0,255,0); ellipse(320, 240, 25, 25); centerdepth = currentDepthValue/25.4; // myPort.write(str(centerdepth)); myPort.write(str(currentDepthValue)); myPort.write(13); }
As you can see... it is very Spinish. The only thing that could confuse a spinhead is the Draw routine... which in fact is a repeat loop. When the code finishes at the bottom... it just goes back to the start of the Draw routine. Everything else seems pretty familiar.
On the Propeller side of things, I am using the BST IDE on a Mac. The code is:
CON _CLKMODE = xtal1 + pll16x _XINFREQ = 5_000_000 RCV_PIN = 31 XMT_PIN = 30 CR = 13 KeyBd = 26 'keyboard KeyBclk = 27 nl =10 OBJ sio : "FullDuplexSerial" tv : "tv_wtext" 'kb : "keyboard" VAR long chk,nlk,x,y,rxptr,i,j,counter,oldrxptr,errnum,delay long stack[100] long stack2[200] long stack3[30] long stack4[30] long numarray[100] long myflag byte tosendval[4] long myarray[256] byte rxarray[200] byte mybytes[4] byte okd[2] byte mybyte,myx 'many variables are used in another flavor of this program but not here:) PUB start tv.start(12) tv.str(string("Prop Paused for 5 Seconds to work around--Prop not found-- report by BST")) waitcnt(clkfreq*5+ cnt) sio.start(RCV_PIN,XMT_PIN,0, 9600) mybyte:=49 x:=cognew(getresponse,@stack) tv.str(string("Prop_Kinect_com",cr)) repeat {Pub sendval(val) tosendval[3]:=val//10 val:=val/10 tosendval[2]:=val//10 val:=val/10 tosendval[1]:=val//10 val:=val/10 tosendval[0]:=val//10 repeat i from 0 to 3 myx:=48+tosendval[i] tv.dec( tosendval[i]) tv.out(13) sio.tx(myx) x:=sio.tx(10) sio.tx(10) } PUB getresponse | iii, myval repeat nlk:=sio.rx 'tv.out(nlk) if nlk <> 13 mybytes[mybyte]:=nlk-48 mybyte++ if nlk == 13 myflag:=1 myval:=0 if mybyte == 4 myval:=mybytes[0]*1000 myval:=myval + mybytes[1]*100 myval:=myval+ (mybytes[2]*10) + mybytes[3] if mybyte == 3 myval:=(mybytes[0]*100) + (mybytes[1]*10) + mybytes[2] tv.str(string("mybytes = ")) tv.dec(mybyte) mybyte := 0 tv.str(string(" myval:= ")) tv.dec((myval*10)/254) tv.str(string(".")) tv.dec(((myval*10)//254)*10/254) tv.out(13)
To disconnect, I first stop the Processing.org app. However, when I go to the BST IDE and try to run my program again... it can't find the Propeller.
A fix for this is to put a pause at the beginning of the Propeller app. This will find the Propeller, if the attempt is made within 5 seconds of a reset. The other option is to load to RAM only and have some other more agreeable program
sitting on your EEPROM.
Interestingly... SimpleIDE finds the Propeller on the first try!!!:)
Rich
Comments