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
Diff: robot.cpp
- Revision:
- 11:967469d7e01c
- Parent:
- 10:926f142f16a3
- Child:
- 12:925f52da3ba9
--- a/robot.cpp Wed Feb 12 05:38:52 2014 +0000 +++ b/robot.cpp Wed Feb 12 06:00:07 2014 +0000 @@ -8,10 +8,14 @@ robot::robot() : spi(PTD2, PTD3, PTD1), bigenc(spi,PTD0), gyro(PTE0, PTE1), right(bigenc,0,1,PTA5), left(bigenc,2,3,PTA4), motors(spi,PTD0) { - bigenc.setDirections(1,-1,1,1); + //bigenc.setDirections(1,-1,1,1); left.setReversed(1); x=y=rot=0; + //set our set point in memory to match the current set point of the encoders + const int *referenceCounts = bigenc.getReferences(); + motors.setSetPoint(referenceCounts[0],referenceCounts[1]); + //control system constants pfac=0.00035; ifac=0.00000001; @@ -23,6 +27,11 @@ //driveforward, but set up so that int robot::absDriveForward(double desangle, int distance){ Timer tim; + int dir=1; + if(distance < 0){ + dir = -1; + distance = -distance; + } int i,move; int maxSpeed=41; int stepsPerInc=3; @@ -59,8 +68,8 @@ move--; } totalMove+=move; - motors.moveForward(move); - DBGPRINT("%d: %d\t%d\r\n",i,move,totalMove); + motors.moveForward(move*dir); + //DBGPRINT("%d: %d\t%d\r\n",i,move,totalMove); while(tim.read_ms()<10); } return totalMove;