Because we started trying to read out the objects the camera sensor saw from the fantom lib, we got stuck! Nothing was seen.
After a lot of trying out different settings we discovered and concluded that in the bluetooth setting the commands A and E for setting up the sensor were not received.
We started trying out the clock sensor, which has RAM registers, and we tried out setting the clock, all using bluetooth. This didn't work. So in the end we remembered reading somewhere about the master slave concept and tested a prog on the brick. In this prog, so without using bluetooth, the camera registers could be set, and it started tracking objects.
As expected the tracking of objects is not a very sensitive proces. The colors have to be well set in the PC prog NXTCAMVIEW, then uploaded. All depends on the setting of the light in the environment. But in the end it worked and we learnt again about some other complexities of the NXT.
Here an example in Lejos JAVA using the nxtcam, it draws the recognized blob on the LCD screen and can be expanded to an NXT following this blob...
import java.awt.Rectangle; import javax.microedition.lcdui.Graphics; import lejos.nxt.Button; import lejos.nxt.NXTCam; import lejos.nxt.Sound; import lejos.nxt.LCD; import lejos.nxt.SensorPort; /** * Demonstration of leJOS nxtcam * * draws the rectangle of a recognized color on the LCD screen * gives different beeps for the two sides of the screen (left right) * can be used to steer motors to make a following NXT * * uses one very good recognizable color entered with NXTCAMVIEW * * @author Five March * */ public class follow { static NXTCam cam = new NXTCam(SensorPort.S1); static Rectangle myRect = new Rectangle(); static Sound beep; public static void main(String[] args ) { Graphics g = new Graphics();//to draw a rectangle on the screen //-------------------------------------------------------- Sound.beep();//we are starting cam.sendCommand('A');//preparation of the camera: sort objects cam.sendCommand('E');//start camera tracking //-------------------------------------------------------- while(!Button.ESCAPE.isPressed() ) { int nb = cam.getNumberOfObjects() ; if (nb ==1 ) { LCD.clear(); g.drawRect(0,0,98,63);//max width on screen myRect = cam.getRectangle(0);//the biggest rectangle seen by the camera double scale = .6;//the camera width is different from the LCD with int rectWidth = (int)(scale*myRect.width); int middle = (int)(scale*myRect.x) + (int)(.5*rectWidth); g.drawRect((int)(scale*myRect.x), (int)(scale*myRect.y), (int)(scale*myRect.width), (int)(scale*myRect.height)); //Integer midInt = new Integer(middle);//JAVA way of doing difficult converting an int to a String //g.drawString( midInt.toString(),1,1); g.refresh(); if (middle > 50 ) beep.playTone(2000, 100);//shape to the right else beep.playTone(4000, 100);//shape to the left pause(100);//small pause otherwise the rectangles are only partially drawn } } } public static void pause(int time) { try{ Thread.sleep(time); } catch(InterruptedException e){} } } |

to be continued...
1 comments:
hey guys i'm a student and i'm a korean
i'm studying NXTcam-v2 now
but I doesn't have any source Robotc.
so , i want to your favor
please send email to me
Post a Comment