Go to Post The jags are powered with magic... - Aren Siekmeier [more]
Home
Go Back   Chief Delphi > Other > FIRST Tech Challenge
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 08-02-2012, 08:32
gnormhurst's Avatar
gnormhurst gnormhurst is offline
Norm Hurst
AKA: gnorm
#0381 (The Tornadoes)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Trenton, NJ
Posts: 138
gnormhurst will become famous soon enoughgnormhurst will become famous soon enough
[FTC]: coasting mode: save your gearboxes!

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; // global
bool coastMode = true;

void
setLeftMotor( 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:
Code:
// globals:
//
// 
short rightSpeed = 0;
short leftSpeed  = 0;
void setLeftMotor( short speed );
void setRightMotor( short speed );

bool coastMode = true;

task main()
{

  short speed = 75;  // (could be changed using buttons or joystick.)

  initializeRobot();
  waitForStart();   // wait for start of tele-op phase.  REQUIRED BY FIRST!


  // let the driver press and hold RT to change from COAST to BRAKE mode.
  if ( (joystick.joy1_Buttons & BTN_RT) )
    coastMode =  false;  // brake
  else
    coastMode =  true;   // coast


  // simple tophat drive: forward, backward, spin left, spin right:
  switch( joystick.joy1_TopHat )
  {

  case 0:  // forward
    setLeftMotor ( speed );
    setRightMotor( speed );
    break;

  case 4:  // backward
    setLeftMotor ( -speed );
    setRightMotor( -speed );
    break;

  case 6:  // spin left
    setLeftMotor ( -speed );
    setRightMotor( +speed );
    break;

  case 2:  // spin right
    setLeftMotor ( +speed );
    setRightMotor( -speed );
    break;

  default:  // stop
    {
      setLeftMotor ( 0 );
      setRightMotor( 0 );
    }

  }  // switch( joystick.joy1_TopHat )

}



void
setLeftMotor( 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;

}

void
setRightMotor( short speed )
{
  // (see note about coasting in setLeftMotor()).
  if ( speed == 0 && coastMode )
  {
    if ( rightSpeed < 0 )
      speed = -1;
    else
      speed = +1;
  }
  
  rightSpeed = speed; // remember it.
  motor[right] = speed;
}
__________________
Trenton Tornadoes 381
2004 Philadelphia Regional Winners
2006 Xerox Creativity Award
---
My corner of the USPTO.
My favorite error message from gcc: main is usually a function
My favorite error message from Windows: There is not enough disk space available to delete this file.
Reply With Quote
  #2   Spotlight this post!  
Unread 09-02-2012, 00:14
dcribbs dcribbs is offline
Registered User
AKA: Dave Cribbs
FTC #5598 (Parish Robotics)
Team Role: Coach
 
Join Date: Mar 2009
Rookie Year: 2004
Location: Denton, TX
Posts: 35
dcribbs has a spectacular aura aboutdcribbs has a spectacular aura about
Re: [FTC]: coasting mode: save your gearboxes!

RobotC has a function similar to this built in, but I think it only works with the three LEGO NXT motors.

http://www.education.rec.ri.cmu.edu/..._res_words.pdf

bFloatDuringInactiveMotorPWM = true; (or false; )
This is used to set whether the motors on the NXT will float or brake when there is no power applied.
There are two settings:
false - motors will brake when inactive
true - motors will float when inactive

Thanks for posting code that provides the same functionality for the 12V DC motors!
__________________
Dave Cribbs
Coach & Teacher

FTC - Team 5598, 6635, 6795
FRC - Team 3626
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 13:14.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi