Skip to content

Instantly share code, notes, and snippets.

#define ENC_ERROR_THRESHOLD 3000
int checkEnc = nMotorEncoder[curMotor];
int knownGoodEnc = motorStates[curMotor].lastRealEncoderPos;
int curEnc;
if (abs(checkEnc - knownGoodEnc) > ENC_ERROR_THRESHOLD) {
//do nothing because enc val is bad
} else {
curEnc = checkEnc; //enc val is good
motorStates[curMotor].lastRealEncoderPos = curEnc;
@jimmyli97
jimmyli97 / LiftPreset2-18.c
Last active August 29, 2015 14:15
LiftPreset2-18
#define LIFT_UP_POW -100
#define ENC_SIGN sgn(LIFT_UP_POW)
#define LIFT_MAX ENC_SIGN * 9800 //high goal
#define NINETY_GOAL ENC_SIGN * 7400
#define SIXTY_GOAL ENC_SIGN * 4600
#define THIRTY_GOAL ENC_SIGN * 2000
#define LIFT_MIN 0
void joyLift(DesiredMotorVals *desiredMotorVals, DesiredEncVals *desiredEncVals, TJoystick *joyState){
@jimmyli97
jimmyli97 / longencoder_2-19.c
Last active August 29, 2015 14:15
longencoder2-19
//Struct definition for holding states of motors
typedef struct MotorState {
long encoder;
long lastRealEncoderPos;
} MotorState;
//Array for storing MotorState for each motor
static MotorState motorStates[MAX_NUM_MOTORS];
//Called once per main loop to update MotorState
@jimmyli97
jimmyli97 / timePos.c
Last active August 29, 2015 14:16
2-19 timepos
#define MAX_HARVESTMOVE_TIME_POS 800
typedef struct MotorState {
... //encoder data
long timePosMs; //stores position in "time" (50 means net movement forward for 50 ms)
long lastUpdateTimeMs; //last time this motorstate as updated
} MotorState;
void motorUpdateState() {
for (int i=0; i<NUM_MOTORS; i++) {
@jimmyli97
jimmyli97 / math_subset.xml
Created June 11, 2015 14:41
example for formula ID ambiguity
<mws:expr url="math.3.0">
<math xmlns="http://www.w3.org/1998/Math/MathML" id="p1.1.m1" class="ltx_Math" alttext="{\displaystyle a}" display="inline" xml:id="p1.1.m1.1" xref="p1.1.m1.1.cmml">
<semantics xml:id="p1.1.m1.1a" xref="p1.1.m1.1.cmml">
<mi xml:id="p1.1.m1.1.1" xref="p1.1.m1.1.1.cmml">a</mi>
<annotation-xml encoding="MathML-Content" xml:id="p1.1.m1.1.cmml" xref="p1.1.m1.1">
<ci xml:id="p1.1.m1.1.1.cmml" xref="p1.1.m1.1.1">a</ci>
</annotation-xml>
<annotation encoding="application/x-tex" xml:id="p1.1.m1.1b" xref="p1.1.m1.1.cmml">{\displaystyle a}</annotation>
</semantics>
</math>