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 one_eddie » Mon May 16, 2011 1:40 pm

I prepared a patch with my changes and I suggested it to Andrew (link to issue #219). I made few improvements in the implementation of AForge (LEGO). I think you should be interested, because it could help you to develop efficient communication.

Best regards,
Krzysztof
one_eddie
 
Posts: 25
Joined: Tue Mar 29, 2011 2:59 pm
Location: Poland

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

Postby mrbencowell » Mon May 16, 2011 2:45 pm

Ah .. excellent .. I'll take a look at using that. Do I just copy these classes over the top of the aforge one's or do I need to manually insert them ?.
User avatar
mrbencowell
 
Posts: 17
Joined: Sat May 14, 2011 4:29 pm

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

Postby linusa » Mon May 16, 2011 6:01 pm

Hi, I'm Linus, developer of the MotorControl program linked before and of the RWTH - Mindstorms NXT Toolbox for MATLAB. I saw you linked to our site, so allow me to comment some of the questions here. By the way, a very good place to ask further questions and discuss anything NXT-related: http://mindboards.sourceforge.net/ (use the forum there).

First, to answer the original question: The BRAKE bit doesn't directly control "braking a motor" as in "stopping it". Apparently it consumes a bit more power but makes the whole motor system more precise. We always keep this bit enabled all the time, we've been using it for years. The term relates to "electronic braking" or something, see here: http://en.wikipedia.org/wiki/H-bridge

mrbencowell wrote:I can't get Turn Ratio to do anything at all, likewise Sync seems to cause the motors to run forever rather than respect the Tacho limits which leads me to think there's a bit more to getting control of these motors than is immediately apparent. If anyone can give me any pointers how to successfully sync motors I'd be MOST appreciative.


Turnratio (in NXC it's called TurnPct) should be 0 for starters. You can use it to drive smooth curves. It works, but not as reliable / accurate as you'd want it to.

To drive two motors synced, you need to send 2 direct commands (SetOutputState), one for each motor, with "regulation mode" set to SYNC. If you do it correctly, everything works. It may seem "crazy" or buggy in the beginning. You should always reset all motor counters before sending another command. If you turn the motors by hand and then send direct commands, they correct the moves done by hand. This is complicated and can seem confusing. It's the NXT's automatic error correction. You can't really disable it via direct commands. Best not touch the motors by hand, or understand what happens. Read this: http://www.mindstorms.rwth-aachen.de/do ... ing.html#7

mrbencowell wrote:To expand on my post above, my suspicion is that when NXT-G syncs the motors it's doing something far cleverer than just sending direct commands, I suspect it's monitoring and anticipating motor position and constantly setting and reseting the motors as required, however direct commands alone aren't enough to keep motors synced or regulated.


It's always been a great mystery WHAT EXACLT the NXT-G "move" and "motor" blocks do (two different things). They actually DO rely on basic direct commands and motor states, or similar things. Nothing too fancy. I created diagrams of the various firmware variables etc here http://www.mindstorms.rwth-aachen.de/tr ... _NoReg.png and here http://www.mindstorms.rwth-aachen.de/tr ... eBlock.png . I think I fully understood what they do. You can't really emulate this via direct commands (via Bluetooth), as short latency is critical!

You can find more motor tests and diagrams here, I hope they are self explaining:
http://www.mindstorms.rwth-aachen.de/tr ... otorTests/


The whole topic is a bit more complicated, and after MotorControl (the link was posted), recently there has been more development. I really suggest you have a look at these links posted here: http://www.mindstorms.rwth-aachen.de/tr ... rInternals


My best understanding of direct commands I got from the old "NXC Guide" (a PDF), the new NXC documantation, and the LEGO Mindstorms SDK and BDK. Go to the mindstorms hompage. There's also a document called "Executable file specification", it describes the bytecode. Turnratio is explained there, for example.
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 linusa » Mon May 16, 2011 6:06 pm

one_eddie wrote:
Sending commands ¶
When we want the motor to execute a movement, we simply send the correct string to the according mailbox. The motor for the specified port must be idle, i.e. it can't be carrying out any other movement commands at the time when the new command arrives. If this should happen, the NXT will indicate this erroneous user behavior by a signal (high and low beep) and will drop (ignore) the message.
Source: http://www.mindstorms.rwth-aachen.de/tr ... torControl


Simple approach as a workaround you should always check current state before changing it to another I quess.

I think this quote doesn't apply here and it's out of context... It's only necessary to check the current state when actually using the MotorControl program. For direct commands, you don't have to do it...

You are free to use MotorControl in your own AForge application, i.e. build a C# interface for it. It's GPL and heavily documented and the protocol is open. NXT-Python ( https://code.google.com/p/nxt-python/ ) recently adapted it as well.

mrbencowell wrote:Great thanks Eddie, that does sound like the noise I'm hearing .. it's strange that it comes from the motors though ! .. I'll look into this.


I quote from here http://www.mindstorms.rwth-aachen.de/tr ... sorsMotors :

I'm controlling two motors, and when their movement has stopped, the motors make a strange high-pitched noise…

This is a feature of the NXT firmware. The sound occurs when working with two synchronized motors, e.g. for driving robots. Once the movement has stopped (using old-fashioned SendMotorSettings command from toolbox version 2.*, or using ActionAtTachoLimit = 'Coast' with NXTMotor in toolbox version 4.*, or DirectMotorCommand), the motors are still synced. If you move one motor, the other will move, too. This by design, and this is when you hear the high-pitched sound from the motors. To disable this noise, just send a .Stop() command from NXTMotor or use StopMotor(). The next motor command should clear / override the synchronization anyway.


I hope I could answer all your 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 linusa » Mon May 16, 2011 6:11 pm

Oh, and if you want an example of how to form direct commands for synced driving, here's the source (MATLAB) of a function that does it: http://www.mindstorms.rwth-aachen.de/tr ... rCommand.m (although it contains some historically grown stuff and is not the cleanest minimal sample). Other source codes that helped me (don't know if they support synced driving though) where NXT-Python, LEGO::NXT (Perl), and maybe MindSqualls. There are more libraries (aNXT, NXT++, libnxt), or you can look at the source of NeXTTool (it is part of the BricxCC / NXC / NBC project).
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 May 17, 2011 9:02 am

Hello there,

Thank you so much for the information, all this will prove invaluable. I'm going to get back onto this tonight .. I'll report back on how I get on.

I'll also make sure to get onto the http://mindboards.sourceforge.net/ forum as it looks like a great source for unpicking the inner workings of the NXT.

All the best and thanks again,
ben
User avatar
mrbencowell
 
Posts: 17
Joined: Sat May 14, 2011 4:29 pm

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

Postby jtracymn » Wed May 18, 2011 2:15 pm

Hi,

I have been working with the NXT brick and controlling it with C#. I have just started reading some of the posts here. The Braking post about electronic braking answers one of the two questions below...

I actually contacted lego last week. I explained my questions to them and they said they had to elevate this to Denmark. So I am still hoping for an answer from them.

The two questions I asked are as follows:

1. The only drive control I can find is using the "tacholimit" variable. This does not seem reliable, repeatable and precise [gave them info from my testing]. Is there another command set to send that can control the exact rotations? Since we can query this value, and based on my testing, it is very accurate, why can we not control the motor using this as the variable (similar to closed loop motion control systems I have controlled for years).

2. The "Brake" flag does not seem to do what it is supposed. to. I verified that it is being set (it does cause a change in function) but does not do what we expect it to do: which is brake the motor after the move is done. Can they verify this [gave them the detailed info and code from my test].

In order to solve these two problems for the short term, i wrote my own control method:
1. I set the tacholimit to "0" (run forever).
2. then set the motor state and the motor start turning.
3. I then query the rotationcount parameter until I get to the distance I want.
4. then set the motor state to off. even though the "brake" mode is set, it will not brake (although it does behave differently if the brake paraemter is not set, this is how I know the change is being accepted). Thus, I have to do the following to brake it.
a. set the power to -10 (or whatever the opposite sign of the move is).
b. set the tacholimit to 1 (i think... cant recall, it is at home)
c. set the motorstate to run.

this works fairly well.

One of the main problems with this of course is the communication time. Thus, when I reach the counts I want, then tell it to stop, it will go a distance beyond this. However, this distance is very consistent. So I wrote a small calibration routine which calcluates the offset for different speeds (and you would do it when you change surfaces or tires, etc). Then this offset is used to determine when to brake the motor.

anyway, it is an OK short term solution, but hopefully we will get the correct one soon.

by the way, the lego representative said the NXT-G program is written in Labview. Thus, I am guessing that perhaps some of the control is similar to what I have started to do above. The advantage they have is that this runs resident on the brick, thus no communication and execution delay similar to sending real time commands via bluetooth as I am doing in C#. I wonder if we can run a compiled C# program resident... probably not.

Joe
jtracymn
 
Posts: 2
Joined: Wed May 18, 2011 2:08 pm

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

Postby jtracymn » Wed May 18, 2011 2:34 pm

p.s. I just received a reply from lego... they are still working on getting the answers to my questions, but it's nice to see they are responding.

I modifed my braking question to confirm the electronic braking, and if so, suggested method of "stopping on a dime".

I also added the question of whether we can run a C# program resident on the brick.

I will update the forum when the reply comes.

Joe
jtracymn
 
Posts: 2
Joined: Wed May 18, 2011 2:08 pm

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

Postby mrbencowell » Wed May 18, 2011 2:47 pm

Excellent Joe .. thanks for taking the time to let us know about this. I'm amazed that Lego are so responsive, I guess all those childhood years I spent playing with it weren't wasted !.

Last night I started experimenting with the Motor Control software running on the NXT brick that Linus has produced and suggested as that seems possibly the quickest and neatest solution for my particular project. I didn't actually get very far as it means digging back through aforge to see how Andrew is communicating and sending bytes to the brick and then building a new interface based on what I learn. I'm not a C# programmer by any means so I'm pretty slow. I do think I'll have something working in a day or two though !.

Luckily the information here : http://www.mindstorms.rwth-aachen.de/trac/wiki/MotorControl is very clear .. I'm more grappling with C# and my lack of ability than anything else.

I'm very pleased that there's been a real sharing of knowledge about this. Very much in the spirit of open source !.

let us know how you get on with Lego.

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 one_eddie » Wed May 18, 2011 5:35 pm

jtracymn wrote:I wonder if we can run a compiled C# program resident... probably not.


I almost 100% sure there isn't (review the hardware spec) but this forced me to think a little bit about this issue and I came to an idea (hybrid solution). The inaccuracy in movements is obvious. As for today we do not have a valid solution based on bluetooth communication (I mean current Aforge implementation) to fix it but what if there were something like stored procedures? This can be a very simple solution. AForge should deliver basic programs like move, moveWithTurn, turnNDegree, turn180, etc. which should be downloaded to the brick (say auto after connected to robot). Then AForge should allow us to run those programs. This will allow to combine few simple actions in one command and compress the communication command used. I think I see how this should be implemented but whether it will be practical to use, can't say. What do you think?

@jtracymn: How did you contact lego? Phone, email?

Regards,
Krzysztof
one_eddie
 
Posts: 25
Joined: Tue Mar 29, 2011 2:59 pm
Location: Poland



PreviousNext

Return to AForge.NET Framework