AForge.NET

  :: AForge.NET Framework :: Articles :: Forums ::

LEGO NXT: What does BRAKE flag really do?

Forum to discuss AForge.NET Framework, its features, API, how-tos, etc.

Re: LEGO NXT: What does BRAKE flag really do?

Postby linusa » Fri May 20, 2011 5:13 am

1.) Stupid question, but the MotorControl program is running on your brick, displaying a status & copyright message? You are using a firmware of the 1.2x generation? Just to make sure, verify that you've done these steps: http://www.mindstorms.rwth-aachen.de/tr ... ntroltoNXT . There's also video instructions here: http://people.clemson.edu/~nwatts/engr141/instructions/ . Oh, and you must of course also START the program. If you don't send a "StartProgram" direct command and check with "GetCurrentProgramName", than it won't work. You can still launch the program manually from the NXT menu of course :-).

2.) Sending direct commands and fiddly around with byte packages can be really annoying. If you've got MATLAB and the RWTH toolbox working (Bluetooth can be a hardware problem, try USB), you can use the command DebugMode on. It will display the direct command packets in hex on the console, and you can dump your packets from C# and you can compare.

3.) As far as I understood, AForge does have some basic direct command support? Can't you find out how they are sent? I guess there should exist some communication layer or helper functions / classes? If unsure, use your debugger to step deep into AForge to see when and how and WHERE the packets actually gets sent. Once you've done this, you can try to extent or utilize the available functions...

Anyway, as I said, I'm not familiar with AForge at all, and I don't have the time to look at the source and help you with this problem :-/
User avatar
linusa
 
Posts: 18
Joined: Mon May 16, 2011 5:04 pm
Location: Aachen, Germany

Re: LEGO NXT: What does BRAKE flag really do?

Postby mrbencowell » Fri May 20, 2011 8:19 am

Hello,

Thanks for the tips, I'll look into it again tonight.

Eventually I did plan to use the forge base classes and extend them out to support motor control commands, but I first wanted to write some direct command code of my own to ensure I knew what I was doing and that motorcontrol was functioning on my brick.

I've got the brick playing a tone based on my own Bluetooth byte codes so I know I'm at least part way there. I think as you say I should test using another tool like matlab to ensure motorcontrol is working and then start expanding out the a forge commands to support byte commands for motor control.

Cheers,
Ben
User avatar
mrbencowell
 
Posts: 17
Joined: Sat May 14, 2011 4:29 pm

Re: LEGO NXT: What does BRAKE flag really do?

Postby mrbencowell » Sun May 22, 2011 9:18 pm

Hello,

Ok, after a few days of trying to understand Bluetooth and byte communication, I figured out how to send commands to MotorControl and get it to respond. I've also downloaded the Aforge source and started expanding it out to support the motor control program in full.

I've used Andrew's direct command code as a guide and so hopefully it should hopefully look and feel like the rest of Aforge enough that it could be included in the future.

I'll update once I get everything working and set up a little neater It really is fantastic to finally see my motors turning pretty precisely and under direct control, Linus thank you so much for your guidance.

cheers
ben
User avatar
mrbencowell
 
Posts: 17
Joined: Sat May 14, 2011 4:29 pm

Re: LEGO NXT: What does BRAKE flag really do?

Postby mrbencowell » Sun May 22, 2011 9:19 pm

Hello,

Ok, after a few days of trying to understand Bluetooth and byte communication, I figured out how to send commands to MotorControl and get it to respond. I've also downloaded the Aforge source and started expanding it out to support the motor control program in full.

I've used Andrew's direct command code as a guide and so hopefully it should hopefully look and feel like the rest of Aforge enough that it could be included in the future.

I'll update once I get everything working and set up a little neater It really is fantastic to finally see my motors turning pretty precisely and under direct control, Linus thank you so much for your guidance.

cheers
ben
User avatar
mrbencowell
 
Posts: 17
Joined: Sat May 14, 2011 4:29 pm

Re: LEGO NXT: What does BRAKE flag really do?

Postby linusa » Sun May 22, 2011 11:58 pm

Hey ben,

thanks for posting this, very good news. Of course I'm always happy to see open source code getting adapted by other projects!

On a side-note I have to say, that MotorControl -- while doint its job well -- is probably getting a bit outdated. It still works, is stable and precise, but it lacks the feature of updating the target position in real time, and it requires those little pauses. If MotorControl was rewritten today with either this new firmware (I already posted above) http://nxt-firmware.ni.fr.eu.org/change ... egulation/ or with new NXC commands (apparently, those changes have been introduced into the language), it could probably be more responsive and have more features. Anyway, for direct commands, it's still state of the art and the best we've got :-)

Good luck, and as usual, feel free to ask questions
User avatar
linusa
 
Posts: 18
Joined: Mon May 16, 2011 5:04 pm
Location: Aachen, Germany

Re: LEGO NXT: What does BRAKE flag really do?

Postby mrbencowell » Wed May 25, 2011 9:35 pm

Andrew, I wonder if I can call on your expertise?

I've got everything working and integrated into Aforge to support MotorControl, however I cannot for the life of me figure out how to implement the Is_Motor_Ready command. I can send the command, and I think I understand how to get the response but I'm unable to understand your code for ReadMessage. My code currently looks like this :

Code: Select all
public byte[] ReadMotorControlMessage(bool waitReply)
        {
            byte[] byteBuffer = new byte[5];
            byte[] replyBuffer = {0x01, 0x01, 0x01};

            // prepare Message Header
            byteBuffer[0] = (byte)((waitReply) ? NXTCommandType.DirectCommand : NXTCommandType.DirectCommandWithoutReply);
            byteBuffer[1] = (byte)NXTDirectCommand.ReadMailbox;
            byteBuffer[2] = (byte)0x00; // read Mailbox 00;
            byteBuffer[3] = (byte)0x00; // length of this message
            byteBuffer[4] = (byte)0x01; // remove message from mailbox

            SendCommand(byteBuffer, replyBuffer);

            return replyBuffer; // return the Boolean Contents of the Message
        }


The three 0x01's in replyBuffer are there whilst I chase bugs around. My plan was that I would use your SendCommand method, and output the reply found in the mailbox, however I always just get ReplyBuffer as I've initialised it, and when I look into the source for SendCommand I'm confused, This line :

Code: Select all
communicationInterface.ReadMessage( reply, out bytesRead )


leads me to assume that you're only returning the Length of the bytes read rather than the body of the message ?, ie only bytesRead has the keyword 'out' before it, which would explain why my replyBuffer array is never being filled with a response from the brick. I'm probably being dim but your help would be greatly appreciated.

Cheers
ben
User avatar
mrbencowell
 
Posts: 17
Joined: Sat May 14, 2011 4:29 pm

Re: LEGO NXT: What does BRAKE flag really do?

Postby andrew.kirillov » Wed Jun 01, 2011 12:36 pm

mrbencowell wrote:This line :


Code: Select all
communicationInterface.ReadMessage( reply, out bytesRead )

leads me to assume that you're only returning the Length of the bytes read rather than the body of the message ?, ie only bytesRead has the keyword 'out' before it, which would explain why my replyBuffer array is never being filled with a response from the brick. I'm probably being dim but your help would be greatly appreciated.

The reply parameter is an array, which is a reference type. Nothing stops the called method from modifying the array. I would recommend a C# book/tutorial for such type of questions.

Also you can check implementation of the ReadMessage() to get the idea, if you already started looking into the code.

P.S. Don't need to flood the topic with questions which don't have relation to it. Have a new unrelated question - create a new topic.
With best regards,
Andrew


Interested in supporting AForge.NET Framework?
User avatar
andrew.kirillov
Site Admin, AForge.NET Developer
 
Posts: 3451
Joined: Fri Jan 23, 2009 9:12 am
Location: UK

Re: LEGO NXT: What does BRAKE flag really do?

Postby linusa » Tue Aug 02, 2011 4:26 pm

Hi, sorry for reviving this old thread, but now there's ready-to-use support for MotorControl in .net. The MindSqualls framework has just added this feature, see http://www.mindsqualls.net/MotorControl.aspx . Maybe you can directly use / include this?
User avatar
linusa
 
Posts: 18
Joined: Mon May 16, 2011 5:04 pm
Location: Aachen, Germany

Re: LEGO NXT: What does BRAKE flag really do?

Postby mrbencowell » Tue Aug 02, 2011 5:40 pm

Hi there,

Thanks for the link .. that's great. I did actually get everything working in Aforge .. I guess I should upload my updated AForge source code in case it's useful for anyone ?.

I never did get the response back from IsMotorReady working properly, but everything else works great.

Thanks
ben
User avatar
mrbencowell
 
Posts: 17
Joined: Sat May 14, 2011 4:29 pm

Re: LEGO NXT: What does BRAKE flag really do?

Postby andrew.kirillov » Tue Aug 02, 2011 8:13 pm

mrbencowell wrote:I guess I should upload my updated AForge source code in case it's useful for anyone ?.

You are always welcome to share your work ...
With best regards,
Andrew


Interested in supporting AForge.NET Framework?
User avatar
andrew.kirillov
Site Admin, AForge.NET Developer
 
Posts: 3451
Joined: Fri Jan 23, 2009 9:12 am
Location: UK



PreviousNext

Return to AForge.NET Framework