RobotC braking problem with NXT motors
Page 1 of 1

Author:  vizino [ Fri Mar 23, 2012 12:58 am ]
Post subject:  RobotC braking problem with NXT motors

I'm teaching RobotC to a group of FTC students and encountered what seems like a bug in RobotC. I want my robot to drive forward 1804 degrees (nothing special about this number), stop with braking, and then wait 2 seconds:

// RobotC Version
task main()
  bFloatDuringInactiveMotorPWM = false;
  nMotorEncoder[motorC] = 0;
  motor[motorB] = 100;
  motor[motorC] = 100;
  while (nMotorEncoder[motorC] < 1804) {}
  motor[motorB] = 0;
  motor[motorC] = 0;

I am using RobotC 3.08 w/ firmware v. 9.12. Using the 56mm (5.6cm) knobby tires with no gearing the robot should travel:

1804 deg * (5.6cm * PI / 360 deg) = 88cm

However, when run, the robot blows right past this distance to something like 120cm. There is a bit of a hesitation in the motors as it crosses the 88cm mark but the motors appear to coast on and not brake. If I take out the wait1Msec() function, the robot travels the expected distance so assume there is automatic braking at program end.

Using NXC (with Bricx Command Center 3.3 and v. 1.31 extended firmware) the robot works perfectly, exactly as I would expect (travels 88cm):

// NXC Version
task main()
  OnFwd(OUT_BC, 100);
  while (MotorRotationCount(OUT_C) < 1804);

Why are the motors not braking under RobotC when using "bFloatDuringInactiveMotorPWM = false;" and setting the motors to 0 power? Any assistance would be appreciated!

Author:  mightor [ Fri Mar 23, 2012 2:14 am ]
Post subject:  Re: RobotC braking problem with NXT motors

Try this code and see if it works. Change the motors if necessary :)

- Xander

#pragma config(Motor,  motorA,          LEFT,          tmotorNormal, PIDControl, encoder)
#pragma config(Motor,  motorB,          RIGHT,         tmotorNormal, PIDControl, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main ()
  // setup B to be the slave of A.
  nSyncedMotors = synchAB;

  // this is the ratio at which B turns in relationship to A
  // In this case, they both run at the same speed.
  nSyncedTurnRatio = 100;

  // because A is the master, you don't need to set B
  nMotorEncoderTarget[motorA] = 1804;

  // same applies to the speed
  motor[motorA] = 90; //  not setting it to 100 gives the controller a
                      //  little more wiggle room to modify the speeds.
  while (nMotorRunState[motorA] != runStateIdle)
  // motors will stop automagically.
  while (bSoundActive)

Author:  vizino [ Fri Mar 23, 2012 8:19 am ]
Post subject:  Re: RobotC braking problem with NXT motors

First of all, thank you for your quick reply. I am confident that it will work and will test it out at our next team meeting.

I understand exactly what you added but it doesn't explain the problem with my specific code and the robot not stopping. What you provided just worked around it. *Why* didn't the motors stop in the RobotC code I provided? We have some rookie team members and would like to try to keep things very simple for them as they learn the basics of motor control in RobotC. The problem encountered was in one of the student's codes and would like to explain it to him.

Again, thanks!

Author:  mightor [ Fri Mar 23, 2012 3:57 pm ]
Post subject:  Re: RobotC braking problem with NXT motors

I am not sure why it wouldn't work. What I do know is that using the nMotorEncoderTarget is the preferred method for moving a motor to specific target.

You may find that putting a 5 ms wait inside your while loop will give much better results for most things. There is no need to have a loop as tight as you make it and it will give the firmware more time to deal with other tasks (such as polling the motors, etc) while the main one sleeps.

- Xander

Author:  steelside [ Thu May 03, 2012 3:43 pm ]
Post subject:  Re: RobotC braking problem with NXT motors

We've got this issue too. It's very annoying. Have you tested this to see if you get the same behaviour, mightor?
Our motors continue running, or they do some kind of skip at the very end when they suddenly increase speed again before they power down. Turning of the breaking and allowing them to float seemed to ease the sudden speed increase somewhat, but it's not ideal.
Also, the synch command is not functioning for us at all, it tries to keep the motors at a constant 45(+-3ish) degree difference, so it won't go straight at all. Different speeds affect this slightly, but only like max 5 degrees.
Writing our own code to keep them synchronized works, as long as we use nMotorEncoderTarget for moving, else it skips when stopping the motors.

Author:  mightor [ Thu May 03, 2012 6:13 pm ]
Post subject:  Re: RobotC braking problem with NXT motors

I would suggest you write some short bits of code that demonstrate this issue and send a bug report to Make sure you also mention which version of ROBOTC you're using and anything else you think might help them track down the issue.

- Xander

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group