Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of IEEE_14_Freescale by
robot.cpp@9:aff48e331147, 2014-02-03 (annotated)
- Committer:
- soonerbot
- Date:
- Mon Feb 03 20:37:35 2014 +0000
- Revision:
- 9:aff48e331147
- Parent:
- 8:c23cd84befa2
- Child:
- 10:926f142f16a3
First working absolute motor control "W" (moves reverse 100 counts)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
soonerbot | 1:c28fac16a109 | 1 | #include "robot.h" |
soonerbot | 1:c28fac16a109 | 2 | |
soonerbot | 1:c28fac16a109 | 3 | #define MIN(a,b) ((b<a)?(b):(a)) |
soonerbot | 1:c28fac16a109 | 4 | #define MAX(a,b) ((b>a)?(b):(a)) |
soonerbot | 1:c28fac16a109 | 5 | |
soonerbot | 7:3b2cf7efe5d1 | 6 | //this is the main place pinouts are put |
soonerbot | 7:3b2cf7efe5d1 | 7 | //also sets up the control system constants |
soonerbot | 3:a223b0bf8256 | 8 | robot::robot() : spi(PTD2, PTD3, PTD1), bigenc(spi,PTD0), gyro(PTE0, PTE1), |
soonerbot | 9:aff48e331147 | 9 | right(bigenc,0,1,PTA5), left(bigenc,2,3,PTA4), motors(spi,PTD0) { |
soonerbot | 1:c28fac16a109 | 10 | |
soonerbot | 1:c28fac16a109 | 11 | bigenc.setDirections(1,-1,1,1); |
soonerbot | 1:c28fac16a109 | 12 | left.setReversed(1); |
soonerbot | 1:c28fac16a109 | 13 | x=y=rot=0; |
soonerbot | 7:3b2cf7efe5d1 | 14 | |
soonerbot | 7:3b2cf7efe5d1 | 15 | //control system constants |
soonerbot | 4:adc885f4ab75 | 16 | pfac=0.00035; |
soonerbot | 4:adc885f4ab75 | 17 | ifac=0.00000001; |
soonerbot | 4:adc885f4ab75 | 18 | dfac=0.000001; |
soonerbot | 4:adc885f4ab75 | 19 | |
soonerbot | 5:74c8ce39334b | 20 | angfac=0.0000016; |
soonerbot | 1:c28fac16a109 | 21 | } |
soonerbot | 1:c28fac16a109 | 22 | |
soonerbot | 7:3b2cf7efe5d1 | 23 | //this is the main thing that both turns and goes forward |
soonerbot | 8:c23cd84befa2 | 24 | // desangle is a angle in degrees to head towards (this is relative to the direction the robot starts pointing in |
soonerbot | 8:c23cd84befa2 | 25 | // distance is a distance to head in that direction in units of encoder ticks |
soonerbot | 4:adc885f4ab75 | 26 | int robot::driveForward(double desangle, int distance){ |
soonerbot | 1:c28fac16a109 | 27 | bigenc.resetAll(); |
soonerbot | 1:c28fac16a109 | 28 | const int* constbuf = bigenc.getVals(); |
soonerbot | 1:c28fac16a109 | 29 | int prev[4]={0,0,0,0}; |
soonerbot | 1:c28fac16a109 | 30 | int distTraveled=0, i; |
soonerbot | 6:62d498ee97cf | 31 | double maxPow=0.4; |
soonerbot | 4:adc885f4ab75 | 32 | int loopcount=0; |
soonerbot | 4:adc885f4ab75 | 33 | double minmain=0.05; |
soonerbot | 4:adc885f4ab75 | 34 | double minalt=0.05; |
soonerbot | 4:adc885f4ab75 | 35 | |
soonerbot | 7:3b2cf7efe5d1 | 36 | //find a point in front of where we're heading |
soonerbot | 4:adc885f4ab75 | 37 | int targetang = desangle*4050000.0/360.0;//gyro.getZ(); |
soonerbot | 4:adc885f4ab75 | 38 | int startang = targetang; |
soonerbot | 4:adc885f4ab75 | 39 | double angle=double(startang)*2*3.14159/4050000.0; |
soonerbot | 6:62d498ee97cf | 40 | double targx = x + double((distance==0)?10000:distance)*0.0035362*cos(angle)*1.5; |
soonerbot | 6:62d498ee97cf | 41 | double targy = y + double((distance==0)?10000:distance)*0.0035362*sin(angle)*1.5; |
soonerbot | 4:adc885f4ab75 | 42 | int invfactor = 0; |
soonerbot | 7:3b2cf7efe5d1 | 43 | |
soonerbot | 7:3b2cf7efe5d1 | 44 | //if going backwards, point away from the point |
soonerbot | 6:62d498ee97cf | 45 | if(distance<0) { |
soonerbot | 4:adc885f4ab75 | 46 | invfactor = 2025000; |
soonerbot | 4:adc885f4ab75 | 47 | } |
soonerbot | 6:62d498ee97cf | 48 | double realfac=0.1; |
soonerbot | 4:adc885f4ab75 | 49 | |
soonerbot | 4:adc885f4ab75 | 50 | int pmain=distance; |
soonerbot | 4:adc885f4ab75 | 51 | int imain=0; |
soonerbot | 4:adc885f4ab75 | 52 | int dmain=0; |
soonerbot | 4:adc885f4ab75 | 53 | |
soonerbot | 4:adc885f4ab75 | 54 | int dterm=0; |
soonerbot | 4:adc885f4ab75 | 55 | const int ptol = 75; |
soonerbot | 4:adc885f4ab75 | 56 | const int dtol = 10; |
soonerbot | 8:c23cd84befa2 | 57 | while((pmain <= -ptol || pmain >= ptol) || (dmain <= -dtol || dmain >= dtol)|| (realfac <= -0.03 || realfac >= 0.03) /*|| (fmod(rot*180.0/3.14159-desangle+3600000.0,360.0) >= 1 && fmod(rot*180.0/3.14159-desangle+3600000.0,360.0) <= 359)*/){ |
soonerbot | 8:c23cd84befa2 | 58 | |
soonerbot | 4:adc885f4ab75 | 59 | //DBGPRINT("=%d of %d [%f] (%d, %d) \t{%f,\t%f,/t%f}",distTraveled,distance, maxPow, constbuf[0], constbuf[1],x,y,rot*180.0/3.14159); |
soonerbot | 1:c28fac16a109 | 60 | for(i=0;i<4;i++) |
soonerbot | 1:c28fac16a109 | 61 | prev[i]=constbuf[i]; |
soonerbot | 1:c28fac16a109 | 62 | //wait(0.05); |
soonerbot | 1:c28fac16a109 | 63 | constbuf = bigenc.getVals(); |
soonerbot | 4:adc885f4ab75 | 64 | |
soonerbot | 7:3b2cf7efe5d1 | 65 | //control system (Proportional, Derivative, Integral) |
soonerbot | 5:74c8ce39334b | 66 | pmain = distance - (constbuf[0]+constbuf[1])/2; |
soonerbot | 5:74c8ce39334b | 67 | dmain = ((constbuf[0]+constbuf[1]) - (prev[0]+prev[1]))/2; |
soonerbot | 4:adc885f4ab75 | 68 | imain += pmain; |
soonerbot | 4:adc885f4ab75 | 69 | |
soonerbot | 6:62d498ee97cf | 70 | //DBGPRINT("%f like %f [%f] {%d,%d,%f,%f}\n\r", gyro.compZ(invfactor+atan2(targy-y,targx-x)*4050000.0/(2*3.14159))*360.0/4050000.0,angle*180/3.14159,rot,pmain,dmain,fmod(rot*180.0/3.14159-desangle+3600000.0,360.0), realfac);\ |
soonerbot | 5:74c8ce39334b | 71 | |
soonerbot | 7:3b2cf7efe5d1 | 72 | //finds the difference between the angle to the imaginary point we're headed to and the current angle and turns it into a power level |
soonerbot | 5:74c8ce39334b | 73 | realfac = (gyro.compZ(invfactor+atan2(targy-y,targx-x)*4050000.0/(2*3.14159)))*angfac; |
soonerbot | 7:3b2cf7efe5d1 | 74 | realfac = MAX(MIN(realfac,0.3),-0.3); // limits how much the motors can turn to fix the angle |
soonerbot | 4:adc885f4ab75 | 75 | |
soonerbot | 7:3b2cf7efe5d1 | 76 | //uses PID control for the forward/back motions and adds in the angular component |
soonerbot | 7:3b2cf7efe5d1 | 77 | //the forward/back motions is limited to a certain speed |
soonerbot | 5:74c8ce39334b | 78 | double leftpow = MAX(MIN(pfac*pmain+ifac*imain+dfac*dmain,maxPow),-maxPow)-realfac; |
soonerbot | 5:74c8ce39334b | 79 | double rightpow = MAX(MIN(pfac*pmain+ifac*imain+dfac*dmain,maxPow),-maxPow)+realfac; |
soonerbot | 7:3b2cf7efe5d1 | 80 | |
soonerbot | 7:3b2cf7efe5d1 | 81 | //if we haven't settled, but also aren't moving, then speed up until it moves |
soonerbot | 7:3b2cf7efe5d1 | 82 | if((pmain <= -ptol || pmain >= ptol) || (dmain <= -dtol || dmain >= dtol) || (realfac <= -0.02 || realfac >= 0.02) ){ |
soonerbot | 4:adc885f4ab75 | 83 | if (leftpow>0){ |
soonerbot | 4:adc885f4ab75 | 84 | if (leftpow<minalt){ |
soonerbot | 4:adc885f4ab75 | 85 | leftpow=minalt; |
soonerbot | 4:adc885f4ab75 | 86 | } |
soonerbot | 4:adc885f4ab75 | 87 | }else if (leftpow>-minalt){ |
soonerbot | 4:adc885f4ab75 | 88 | leftpow=-minalt; |
soonerbot | 4:adc885f4ab75 | 89 | } |
soonerbot | 4:adc885f4ab75 | 90 | if (rightpow>0){ |
soonerbot | 4:adc885f4ab75 | 91 | if (rightpow<minmain){ |
soonerbot | 4:adc885f4ab75 | 92 | rightpow=minmain; |
soonerbot | 4:adc885f4ab75 | 93 | } |
soonerbot | 4:adc885f4ab75 | 94 | }else if (rightpow>-minmain){ |
soonerbot | 4:adc885f4ab75 | 95 | rightpow=-minmain; |
soonerbot | 4:adc885f4ab75 | 96 | } |
soonerbot | 4:adc885f4ab75 | 97 | } |
soonerbot | 4:adc885f4ab75 | 98 | left.setPower(leftpow); |
soonerbot | 4:adc885f4ab75 | 99 | right.setPower(rightpow); |
soonerbot | 7:3b2cf7efe5d1 | 100 | |
soonerbot | 7:3b2cf7efe5d1 | 101 | //how far we've moved in the last timestep |
soonerbot | 4:adc885f4ab75 | 102 | int deltaTraveled=(constbuf[0]-prev[0]+constbuf[1]-prev[1])/2; |
soonerbot | 4:adc885f4ab75 | 103 | //DBGPRINT("\t %d\r\n",deltaTraveled); |
soonerbot | 7:3b2cf7efe5d1 | 104 | addforward(double(deltaTraveled)*0.0035362); //update our position |
soonerbot | 1:c28fac16a109 | 105 | distTraveled+=deltaTraveled; |
soonerbot | 4:adc885f4ab75 | 106 | loopcount++; |
soonerbot | 7:3b2cf7efe5d1 | 107 | |
soonerbot | 7:3b2cf7efe5d1 | 108 | //increase min speed so that it will actually move |
soonerbot | 4:adc885f4ab75 | 109 | if((dmain<5&&dmain>-5)&&minmain<0.2){ |
soonerbot | 5:74c8ce39334b | 110 | minmain+=0.003; |
soonerbot | 4:adc885f4ab75 | 111 | } else if (minmain>=0.05) { |
soonerbot | 5:74c8ce39334b | 112 | minmain-=0.003; |
soonerbot | 4:adc885f4ab75 | 113 | } |
soonerbot | 4:adc885f4ab75 | 114 | if((dterm<5&&dterm>-5)&&minalt<0.2){ |
soonerbot | 5:74c8ce39334b | 115 | minalt+=0.003; |
soonerbot | 4:adc885f4ab75 | 116 | } else if (minalt>=0.05) { |
soonerbot | 5:74c8ce39334b | 117 | minalt-=0.003; |
soonerbot | 4:adc885f4ab75 | 118 | } |
soonerbot | 1:c28fac16a109 | 119 | } |
soonerbot | 1:c28fac16a109 | 120 | left.brake(); |
soonerbot | 1:c28fac16a109 | 121 | right.brake(); |
soonerbot | 6:62d498ee97cf | 122 | DBGPRINT("Loops: %d\r\n",loopcount); |
soonerbot | 7:3b2cf7efe5d1 | 123 | |
soonerbot | 7:3b2cf7efe5d1 | 124 | //catch the slowdown movement |
soonerbot | 6:62d498ee97cf | 125 | wait(0.2); |
soonerbot | 5:74c8ce39334b | 126 | for(i=0;i<4;i++) |
soonerbot | 5:74c8ce39334b | 127 | prev[i]=constbuf[i]; |
soonerbot | 5:74c8ce39334b | 128 | //wait(0.05); |
soonerbot | 5:74c8ce39334b | 129 | constbuf = bigenc.getVals(); |
soonerbot | 6:62d498ee97cf | 130 | addforward(double(constbuf[0]-prev[0]+constbuf[1]-prev[1])*0.0035362/2.0); |
soonerbot | 5:74c8ce39334b | 131 | DBGPRINT("loss of %d and %d\n\r",constbuf[0]-prev[0],constbuf[1]-prev[1]); |
soonerbot | 1:c28fac16a109 | 132 | return 0; |
soonerbot | 1:c28fac16a109 | 133 | } |
soonerbot | 1:c28fac16a109 | 134 | |
soonerbot | 7:3b2cf7efe5d1 | 135 | //add the motion in the direction that the robot is facing |
soonerbot | 4:adc885f4ab75 | 136 | void robot::addforward(double dist){ |
soonerbot | 4:adc885f4ab75 | 137 | double angle=double(gyro.getZ())*2*3.14159/4050000.0; |
soonerbot | 1:c28fac16a109 | 138 | x+=dist*cos(angle); |
soonerbot | 1:c28fac16a109 | 139 | y+=dist*sin(angle); |
soonerbot | 1:c28fac16a109 | 140 | rot=angle; |
soonerbot | 1:c28fac16a109 | 141 | } |
soonerbot | 1:c28fac16a109 | 142 | |
soonerbot | 7:3b2cf7efe5d1 | 143 | //doesn't work yet |
soonerbot | 1:c28fac16a109 | 144 | int robot::moveTo(double xInches, double yInches){ |
soonerbot | 1:c28fac16a109 | 145 | double power=.2; |
soonerbot | 1:c28fac16a109 | 146 | turntowards(xInches,yInches); |
soonerbot | 1:c28fac16a109 | 147 | double distance=sqrt(pow(xInches-x,2)+pow(yInches-y,2))/0.0035362; |
soonerbot | 1:c28fac16a109 | 148 | double angle=atan2(xInches-x,yInches-y)*180.0/3.14159; |
soonerbot | 4:adc885f4ab75 | 149 | double currangle=double(gyro.getZ())*2*3.14159/4050000.0; |
soonerbot | 1:c28fac16a109 | 150 | bigenc.resetAll(); |
soonerbot | 1:c28fac16a109 | 151 | const int* constbuf = bigenc.getVals(); |
soonerbot | 1:c28fac16a109 | 152 | int prev[4]={0,0,0,0}; |
soonerbot | 1:c28fac16a109 | 153 | int distTraveled=0, i; |
soonerbot | 1:c28fac16a109 | 154 | double maxPow; |
soonerbot | 1:c28fac16a109 | 155 | DBGPRINT("going %f at angle %f from current of %f\r\n",distance,angle,currangle); |
soonerbot | 1:c28fac16a109 | 156 | while(distTraveled<distance){ |
soonerbot | 1:c28fac16a109 | 157 | angle=atan2(xInches-x,yInches-y)*180.0/3.14159; |
soonerbot | 4:adc885f4ab75 | 158 | currangle=double(gyro.getZ())*2*3.14159/4050000.0; |
soonerbot | 1:c28fac16a109 | 159 | maxPow=MAX(double(distance-distTraveled-2000)/15000.0,0.1); |
soonerbot | 1:c28fac16a109 | 160 | if(currangle>angle+2.0){ //too far to the right, brake left |
soonerbot | 1:c28fac16a109 | 161 | left.brake(); |
soonerbot | 1:c28fac16a109 | 162 | } else { |
soonerbot | 1:c28fac16a109 | 163 | left.setPower(MIN(power,maxPow)); |
soonerbot | 1:c28fac16a109 | 164 | } |
soonerbot | 1:c28fac16a109 | 165 | if(currangle<angle-2){ |
soonerbot | 1:c28fac16a109 | 166 | right.brake(); |
soonerbot | 1:c28fac16a109 | 167 | } else { |
soonerbot | 1:c28fac16a109 | 168 | right.setPower(MIN(power,maxPow)); |
soonerbot | 1:c28fac16a109 | 169 | } |
soonerbot | 1:c28fac16a109 | 170 | DBGPRINT("=%d of %d [%f] (%d, %d, %d, %d) \t{%f,\t%f,\t%f}\r\n",distTraveled,distance, maxPow, constbuf[0], constbuf[1], constbuf[2], constbuf[3],x,y,rot*180.0/3.14159); |
soonerbot | 1:c28fac16a109 | 171 | for(i=0;i<4;i++) |
soonerbot | 1:c28fac16a109 | 172 | prev[i]=constbuf[i]; |
soonerbot | 1:c28fac16a109 | 173 | //wait(0.05); |
soonerbot | 1:c28fac16a109 | 174 | constbuf = bigenc.getVals(); |
soonerbot | 1:c28fac16a109 | 175 | int deltaTraveled=MAX((MIN(-constbuf[0]+prev[0],-constbuf[1]+prev[1])+MIN(constbuf[2]-prev[2],constbuf[3]-prev[3]))/2,0); |
soonerbot | 1:c28fac16a109 | 176 | addforward(double(deltaTraveled)*0.0035362); |
soonerbot | 1:c28fac16a109 | 177 | distTraveled+=deltaTraveled; |
soonerbot | 1:c28fac16a109 | 178 | //angle=atan2(xInches-x,yInches-y)*180.0/3.14159; |
soonerbot | 1:c28fac16a109 | 179 | } |
soonerbot | 1:c28fac16a109 | 180 | left.brake(); |
soonerbot | 1:c28fac16a109 | 181 | right.brake(); |
soonerbot | 1:c28fac16a109 | 182 | return 0; |
soonerbot | 1:c28fac16a109 | 183 | |
soonerbot | 1:c28fac16a109 | 184 | } |
soonerbot | 1:c28fac16a109 | 185 | |
soonerbot | 7:3b2cf7efe5d1 | 186 | //also doesn't work |
soonerbot | 1:c28fac16a109 | 187 | int robot::turntowards(double xInches, double yInches){ |
soonerbot | 4:adc885f4ab75 | 188 | double currangle=double(gyro.getZ())*2*3.14159/4050000.0; |
soonerbot | 1:c28fac16a109 | 189 | double angle=atan2(xInches-x,yInches-y)*180.0/3.14159; |
soonerbot | 1:c28fac16a109 | 190 | double finangle=angle; |
soonerbot | 1:c28fac16a109 | 191 | /*if(int(currangle-angle)%360>180){ //needs to turn positive degrees |
soonerbot | 1:c28fac16a109 | 192 | finangle=currangle+double(int(angle-currangle)%360); |
soonerbot | 1:c28fac16a109 | 193 | } else {//negative degrees |
soonerbot | 1:c28fac16a109 | 194 | finangle=currangle-double(int(currangle-angle)%360); |
soonerbot | 1:c28fac16a109 | 195 | }*/ |
soonerbot | 1:c28fac16a109 | 196 | double acc=turn(0.4,finangle); |
soonerbot | 1:c28fac16a109 | 197 | if(acc<-0.75 && acc>0.75){ |
soonerbot | 1:c28fac16a109 | 198 | acc=turn(0.3,finangle); |
soonerbot | 1:c28fac16a109 | 199 | } |
soonerbot | 1:c28fac16a109 | 200 | |
soonerbot | 1:c28fac16a109 | 201 | |
soonerbot | 1:c28fac16a109 | 202 | return 1; |
soonerbot | 1:c28fac16a109 | 203 | } |
soonerbot | 1:c28fac16a109 | 204 | |
soonerbot | 7:3b2cf7efe5d1 | 205 | //still no |
soonerbot | 1:c28fac16a109 | 206 | double robot::turn(double power, double degrees){ |
soonerbot | 1:c28fac16a109 | 207 | bigenc.resetAll(); |
soonerbot | 1:c28fac16a109 | 208 | const int* constbuf = bigenc.getVals(); |
soonerbot | 1:c28fac16a109 | 209 | int prev[4]={0,0,0,0}; |
soonerbot | 1:c28fac16a109 | 210 | int startz; |
soonerbot | 4:adc885f4ab75 | 211 | startz=gyro.getZ(); |
soonerbot | 1:c28fac16a109 | 212 | int gyroticks=(degrees*4050000)/360; |
soonerbot | 1:c28fac16a109 | 213 | double maxPow; |
soonerbot | 1:c28fac16a109 | 214 | int nowz=startz; |
soonerbot | 1:c28fac16a109 | 215 | int dir=0; |
soonerbot | 1:c28fac16a109 | 216 | if(gyroticks>startz){ |
soonerbot | 1:c28fac16a109 | 217 | right.setPower(-power); |
soonerbot | 1:c28fac16a109 | 218 | left.setPower(power); |
soonerbot | 1:c28fac16a109 | 219 | dir=1; |
soonerbot | 1:c28fac16a109 | 220 | } else { |
soonerbot | 1:c28fac16a109 | 221 | right.setPower(power); |
soonerbot | 1:c28fac16a109 | 222 | left.setPower(-power); |
soonerbot | 1:c28fac16a109 | 223 | dir=-1; |
soonerbot | 1:c28fac16a109 | 224 | } |
soonerbot | 1:c28fac16a109 | 225 | while((gyroticks-nowz)*dir>0){ |
soonerbot | 1:c28fac16a109 | 226 | maxPow=MAX(double(abs(gyroticks-nowz))/4050000.0,0.25); |
soonerbot | 1:c28fac16a109 | 227 | if(gyroticks<nowz){ |
soonerbot | 1:c28fac16a109 | 228 | right.setPower(-MIN(power,maxPow)); |
soonerbot | 1:c28fac16a109 | 229 | left.setPower(MIN(power,maxPow)); |
soonerbot | 1:c28fac16a109 | 230 | } else { |
soonerbot | 1:c28fac16a109 | 231 | right.setPower(MIN(power,maxPow)); |
soonerbot | 1:c28fac16a109 | 232 | left.setPower(-MIN(power,maxPow)); |
soonerbot | 1:c28fac16a109 | 233 | } |
soonerbot | 1:c28fac16a109 | 234 | DBGPRINT("_%d of %d {%f, %f, %f}\r\n",(gyroticks-nowz)*dir, gyroticks,x,y,rot*180.0/3.14159); |
soonerbot | 1:c28fac16a109 | 235 | for(int i=0;i<4;i++) |
soonerbot | 1:c28fac16a109 | 236 | prev[i]=constbuf[i]; |
soonerbot | 1:c28fac16a109 | 237 | constbuf = bigenc.getVals(); |
soonerbot | 1:c28fac16a109 | 238 | int deltaTraveled; |
soonerbot | 1:c28fac16a109 | 239 | if(gyroticks<nowz){ |
soonerbot | 1:c28fac16a109 | 240 | deltaTraveled=(MIN(-constbuf[0]+prev[0],-constbuf[1]+prev[1])-MIN(-constbuf[2]+prev[2],-constbuf[3]+prev[3]))/2; |
soonerbot | 1:c28fac16a109 | 241 | } else { |
soonerbot | 1:c28fac16a109 | 242 | deltaTraveled=(-MIN(constbuf[0]-prev[0],constbuf[1]-prev[1])+MIN(constbuf[2]-prev[2],constbuf[3]-prev[3]))/2; |
soonerbot | 1:c28fac16a109 | 243 | } |
soonerbot | 1:c28fac16a109 | 244 | addforward(double(deltaTraveled)*0.0035362); |
soonerbot | 4:adc885f4ab75 | 245 | nowz=gyro.getZ(); |
soonerbot | 1:c28fac16a109 | 246 | } |
soonerbot | 1:c28fac16a109 | 247 | right.brake(); |
soonerbot | 1:c28fac16a109 | 248 | left.brake(); |
soonerbot | 1:c28fac16a109 | 249 | return (gyroticks-nowz)*dir; |
soonerbot | 1:c28fac16a109 | 250 | } |