With a tip from this thread, I was able to get the motors to stop dynamic braking at speed=0 and instead coast. The motivation was that the hard braking was damaging the gearboxes in our motors.

The main idea is "don't use speed = 0." Setting the speed to 1 avoids the braking mode. But this only works if the current speed was > 0 (forward). If the current speed was < 0 (backward), setting speed to +1 caused braking to happen. In this case using -1 avoided braking mode. In other words, the value to use for "coast" depends on the current direction of the motor.

Therefore this requires access to the current speed setting of the motor. I created a "speed-setting" function for each motor that remembers the speed it was set to:

Code:

setLeftSpeed( speed );

These functions are used in place of

Code:

motor[left] = speed;

The function also contains the logic to set the speed to +1 or -1 if a speed of zero is requested, thus causing the motor to coast instead of brake:

Code:

short leftSpeed = 0; // globalbool coastMode = true;

voidsetLeftMotor( short speed ){ // the motor controller will brake (short) the motor // if the speed value is zero. But setting the motor to 1 // only makes it coast if the previous motor value was > 0. // So we set it to -1 if the previous speed was < 0. if ( speed == 0 && coastMode ) { if ( leftSpeed < 0 ) speed = -1; else speed = +1; }

leftSpeed = speed; // remember it motor[left] = speed;

}

Below is an example of a simple "tophat drive" method that uses coasting:

voidsetLeftMotor( short speed ){ // the motor controller will brake (short) the motor // if the speed value is zero. But setting the motor to 1 // only makes it coast if the previous motor value was > 0. // So we set it to -1 if the previous speed was < 0. if ( speed == 0 && coastMode ) { if ( leftSpeed < 0 ) speed = -1; else speed = +1; }

Nice job on figuring this out. There are some easier ways to do these things though.If you want your motors to coast, you can always use

Code:

bFloatDuringInactiveMotorPWM = true;

There is also no need to store the current value of the motor in your program. Just reading motor[motorName] will give you the speed that it's been set at.If you still want to do it by yourself, making all these functions for every motor is a hassle. Use the tMotor variable instead:I'll try and follow your code as closely as possible.

Back in December I tried to read the motor value as you indicated. motor[left] looks like a pointer dereference, but the values I got back did not make any sense. So I figured it was some kind of special RobotC syntax. It's not? I wonder what I did wrong?

-norm

Wed Feb 08, 2012 5:22 pm

magicode

Moderator

Joined: Tue Sep 14, 2010 9:19 pmPosts: 496

Re: How to make motors coast instead of brake

I did not know that you were referring to TETRIX motors in this post. Well, I guess that you should continue using the +-1 method. As for reading the motor value by calling motor[motorname], I know that this works on the VEX Cortex. I've not tested it with NXT/Tetrix yet, but I assume that it should work.

_________________sudo rm -rf /

Wed Feb 08, 2012 6:16 pm

ronb

Rookie

Joined: Sat Nov 01, 2014 2:28 amPosts: 1Location: San Jose

Re: How to make motors coast instead of brake

Thanks for these suggestions. I was thinking of using SGN and then saw you did this. How elegant.I think even a more concise way of writing this is to alter the formal parameter and thus only have one line that sets the motor speed. like this:

Who is online

Users browsing this forum: No registered users and 2 guests

You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum