Just as a hint to those of you who might also own this system, when sending a direct command to the NXT module you have to omit the first byte (Byte0) in the output and response buffers. The framework does that for you (thanks Lego for not documenting that in the SDK, could have saved me two hours of frustrated debugging).
As an example, to start/stop the continuous rotation of motor A, you'd have to send the following data:
nFANTOM100::tStatus status;
nFANTOM100::iNXTIterator* nxtIteratorPtr = NULL;
nFANTOM100::iNXT* nxtPtr = NULL;
nxtIteratorPtr = nFANTOM100::iNXT::createNXTIterator( false, 0, status );
if( status.isNotFatal())
{
nxtPtr = nxtIteratorPtr->getNXT( status );
nFANTOM100::iNXT::destroyNXTIterator( nxtIteratorPtr );
ViUInt8 tachoticks = 360;
ViUInt8 speed = 100;
ViUInt8 directCommandBuffer[] = { // Removed the initial byte!
0x04, // Set outputstate
0x00, // The output port 0-2
speed, //power set point -100 to 100
0x01 | 0x04, // mode byte,
0x01, // Regulation mode (no regulation)
0x10, //turn ratio
0x20, // Run state (idle)
tachoticks
};
// Same thing here, decrease the size of the return buffer by 1 (documented size is 3)
unsigned char responseBuffer[2];
// Send the direct command to the NXT.
nxtPtr->sendDirectCommand( true /* we want a response */,
reinterpret_cast< ViByte* >( directCommandBuffer ), sizeof( directCommandBuffer ),
reinterpret_cast< ViByte* >( responseBuffer), sizeof( responseBuffer ),
status );
}
I'll post some further details as I get through the basic robots and finally get to program something on my own. I fear however that the NXT's measly 106k memory could become a major hurdle in my robot world domination plans.
Engin ummæli:
Skrifa ummæli