Visar inlägg med etikett wheeled robot. Visa alla inlägg
Visar inlägg med etikett wheeled robot. Visa alla inlägg

2009-10-07

Communication framework and a broken NXT

When I first bought the NXT the sound from its speakers were not good at all, at first I thought it was supposed to be like that, it's just Lego and probably a cheap speaker. Anyhow just a couple of days later there were no sound from it at all so for a couple of weeks ago I sent it in to be repaired/replaced and now the new one has arrived :) So that's why we haven't been able to do and write especially much the last time.

PenemuNXTFramework 0.1

Anyhow what I have done while the NXT was gone is that I've written a communication framework that's supposed to be a middle layer between the existing communication classes in leJOS and the programmer. It's based at some interfaces that you must implement and then it will handle a lot of stuff for you.

Some key features are:
Queue: Let you to setup a queue of set of data to send. This allows you to send data when the NXT has time, maybe there is much to do at the moment.
Priority: Give priority to a set of data, this means that it will be sent first of all items in the queue and it will be processed first at the receiver. Good to use for shutdown commands.
Consistent: The syntax and classes used is exactly the same ones at the NXT as at the PC.
Choose type: When you setup the communication you specify if to use USB or bluetooth. You only specify it once and you don't have to change anything else.

This is how the base part might look:
// Setup data factories
// They produce empty instances of the data objects
NXTCommunicationDataFactories DataFactories = new NXTCommunicationDataFactories(
new ServerMessageDataFactory(), new TiltSensorDataFactory());

// Setup ..
NXTCommunication NXTC = new NXTCommunication(true, DataFactories,
new NXTDataStreamConnection());

// .. and start the communication
NXTC.ConnectAndStartAll(NXTConnectionModes.USB);


// Setup a data processor
// It will be given the incoming queue of data and handle it
ServerMessageDataProcessor SMDP = new ServerMessageDataProcessor(NXTC, DataFactories);
SMDP.start();

//Add some data to the send queue
NXTC.sendData(new TiltSensorData(TS.getXTilt(), TS.getYTilt(), TS.getZTilt()))


A data factory might look like this:
public class SensorDataFactory implements INXTCommunicationDataFactory {
@Override
public SensorData getEmptyInstance() {
return new SensorData(NXTCommunicationData.MAIN_STATUS_NORMAL,
NXTCommunicationData.DATA_STATUS_EMPTY);
}

@Override
public INXTCommunicationData getEmptyIsShuttingDownInstance() {
return new SensorData(NXTCommunicationData.MAIN_STATUS_SHUTTING_DOWN,
NXTCommunicationData.DATA_STATUS_ONLY_STATUS);
}

@Override
public INXTCommunicationData getEmptyShutDownInstance() {
return new SensorData(NXTCommunicationData.MAIN_STATUS_SHUT_DOWN,
NXTCommunicationData.DATA_STATUS_ONLY_STATUS);
}
}


And part of a data processor like this:
@Override
public void ProcessItem(INXTCommunicationData dataItem,
NXTCommunication NXTComm) {
SensorData SensorDataItem = (SensorData) dataItem;

Acceleration.add(new AccelerationValues(SensorDataItem.getAccX(),
SensorDataItem.getAccY(), SensorDataItem.getAccZ()));
}


So it's not finished yet but soon I hope. Anyhow this will make things much easier for us when we want to share data to the computer and back.

Right now we are rebuilding the robot and hopefully we will upload some pictures later this evening.
We are basing the new model on the Explorer from NXTPrograms.com, it's much more stable the our previous construction.

/Peter Forss

2009-07-26

First test of the new sensors

So we finally decided to buy the sensors I told you about a couple of weeks ago.
We bought this from Mindsensors.com:
* High Precision Long Range Infrared distance sensor for NXT (DIST-Nx-Long-v2)
* Multi-Sensitivity Acceleration Sensor v3 for NXT - (ACCL-Nx-v3)
And this from HiTechnic.com:
* NXT Compass Sensor
* NXT Extended Connector Cable Set



And now they've finally arrived to Sweden :)
I've been able to test the Compass and the distance sensor so far, Josef still got the Acceleration Sensor at home and we will test it together when we meet in a couple of weeks.

Anyhow they look really good :) The accuracy of the distance sensor is very high, it gives you the distance in mm and it works good!



I put together a simple bot to test out the CompassNavigatorin LeJos.



We will do some more advanced stuff soon!