View Single Post
  #23   Spotlight this post!  
Unread 30-04-2013, 17:51
dubiousSwain's Avatar
dubiousSwain dubiousSwain is offline
The ride never ends
AKA: Christian Steward
FRC #5420 (Velocity)
Team Role: Mentor
 
Join Date: Oct 2011
Rookie Year: 2011
Location: USA
Posts: 304
dubiousSwain has a reputation beyond reputedubiousSwain has a reputation beyond reputedubiousSwain has a reputation beyond reputedubiousSwain has a reputation beyond reputedubiousSwain has a reputation beyond reputedubiousSwain has a reputation beyond reputedubiousSwain has a reputation beyond reputedubiousSwain has a reputation beyond reputedubiousSwain has a reputation beyond reputedubiousSwain has a reputation beyond reputedubiousSwain has a reputation beyond repute
Re: Introducing SwagDrive. The drive code of the future.

Quote:
Originally Posted by apalrd View Post
C:

Code:
//Constants
#define SWAG_BARRIER 0.1
#define SWAG_GAIN 1
#define SWAG_MAX 9000
#define SWAG_PERIOD 500

//Local variables
double old_throttle = 0;
double old_wheel = 0;
double diff_throttle = 0;
double diff_wheel = 0;
double out_throttle;
double out_wheel;
int swag_level = 0;
int swag_period = 0;

//SwagDrive
void SwagDrive(double throttle, double wheel, double* left, double* right)
{
    out_throttle = throttle;
    out_wheel = wheel;

    if(0 == swag_period)
    {
        diff_throttle = abs(throttle) + abs(old_throttle);
        diff_wheel = abs(wheel) + abs(old_wheel);
        if(diff_throttle < SWAG_BARRIER)
        {
            out_throttle = (diff_throttle * SWAG_GAIN) + throttle;
        }
        else
        {
            swag_level++;
        }
        if(diff_wheel < SWAG_BARRIER)
        {
            out_wheel = (diff_wheel * SWAG_GAIN) + wheel;
        }
        else
        {
            swag_level++;
        }

        if(swag_level > SWAG_MAX)
        {
            swag_period = SWAG_PERIOD;
            swag_level = 0;
        }
    }
    else
    {
        out_throttle = 0;
        out_wheel = 0;
    }

    //arcade drive
    left = out_throttle + out_wheel;
    right = out_throttle - out_wheel;

    old_throttle = throttle;
    old_wheel = wheel;
}
thank you
__________________
2015 MAR District Champions