![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
ICRS Eurobot 2013
Dependencies: mbed mbed-rtos Servo QEI
main.cpp@14:c638d4b9ee94, 2013-04-06 (annotated)
- Committer:
- madcowswe
- Date:
- Sat Apr 06 15:43:47 2013 +0000
- Revision:
- 14:c638d4b9ee94
- Parent:
- 12:d4b5851742a3
- Parent:
- 13:76c9915db820
- Child:
- 15:9c5aaeda36dc
merged
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
twighk | 8:69bdf20cb525 | 1 | //#pragma Otime // Compiler Optimisations |
twighk | 0:200635fa1b08 | 2 | |
twighk | 0:200635fa1b08 | 3 | // Eurobot13 main.cpp |
twighk | 0:200635fa1b08 | 4 | |
madcowswe | 6:995b3679155f | 5 | |
madcowswe | 6:995b3679155f | 6 | |
madcowswe | 6:995b3679155f | 7 | /* |
madcowswe | 6:995b3679155f | 8 | PINOUT Sensors |
madcowswe | 6:995b3679155f | 9 | 5: RF:SDI |
madcowswe | 6:995b3679155f | 10 | 6 SDO |
madcowswe | 6:995b3679155f | 11 | 7 SCK |
madcowswe | 6:995b3679155f | 12 | 8 NCS |
madcowswe | 6:995b3679155f | 13 | 9 NIRQ |
madcowswe | 6:995b3679155f | 14 | 10-15 6 echo pins |
madcowswe | 6:995b3679155f | 15 | 16 trig |
madcowswe | 6:995b3679155f | 16 | 17 IRin |
madcowswe | 6:995b3679155f | 17 | 18-20 unused |
madcowswe | 6:995b3679155f | 18 | 21 stepper step |
madcowswe | 6:995b3679155f | 19 | 22-27 unused |
madcowswe | 6:995b3679155f | 20 | 28 Serial TX |
madcowswe | 6:995b3679155f | 21 | 29-30 unused |
madcowswe | 6:995b3679155f | 22 | |
madcowswe | 6:995b3679155f | 23 | |
madcowswe | 6:995b3679155f | 24 | PINOUT Main |
madcowswe | 6:995b3679155f | 25 | 5: Lower arm servo |
madcowswe | 6:995b3679155f | 26 | 6: Upper arm servo |
madcowswe | 6:995b3679155f | 27 | |
madcowswe | 6:995b3679155f | 28 | 14: Serial RX |
madcowswe | 6:995b3679155f | 29 | 15: Distance sensor |
madcowswe | 6:995b3679155f | 30 | |
madcowswe | 6:995b3679155f | 31 | 20: color sensor in |
madcowswe | 6:995b3679155f | 32 | 21-24: Motors PWM IN 1-4 |
madcowswe | 6:995b3679155f | 33 | 25-26: Encoders |
madcowswe | 6:995b3679155f | 34 | 27-28: Encoders |
madcowswe | 6:995b3679155f | 35 | 29: Color sensor RED LED |
madcowswe | 6:995b3679155f | 36 | 30: Color sensor BLUE LED |
madcowswe | 6:995b3679155f | 37 | |
madcowswe | 6:995b3679155f | 38 | */ |
twighk | 0:200635fa1b08 | 39 | #include "mbed.h" |
twighk | 12:d4b5851742a3 | 40 | #include "rtos.h" |
twighk | 3:717de74f6ebd | 41 | Serial pc(USBTX, USBRX); |
twighk | 0:200635fa1b08 | 42 | |
twighk | 11:bbddc908c78c | 43 | const PinName P_SERVO_LOWER_ARM = p5; |
twighk | 11:bbddc908c78c | 44 | const PinName P_SERVO_UPPER_ARM = p6; |
twighk | 11:bbddc908c78c | 45 | |
twighk | 11:bbddc908c78c | 46 | const PinName P_SERIAL_RX = p14; |
twighk | 11:bbddc908c78c | 47 | const PinName P_DISTANCE_SENSOR = p15; |
twighk | 11:bbddc908c78c | 48 | |
twighk | 11:bbddc908c78c | 49 | const PinName P_COLOR_SENSOR_IN = p20; |
twighk | 11:bbddc908c78c | 50 | |
twighk | 11:bbddc908c78c | 51 | const PinName P_MOT_RIGHT_A = p21; |
twighk | 11:bbddc908c78c | 52 | const PinName P_MOT_RIGHT_B = p22; |
twighk | 11:bbddc908c78c | 53 | const PinName P_MOT_LEFT_A = p23; |
twighk | 11:bbddc908c78c | 54 | const PinName P_MOT_LEFT_B = p24; |
twighk | 11:bbddc908c78c | 55 | |
twighk | 11:bbddc908c78c | 56 | const PinName P_ENC_RIGHT_A = p28; |
twighk | 11:bbddc908c78c | 57 | const PinName P_ENC_RIGHT_B = p27; |
twighk | 11:bbddc908c78c | 58 | const PinName P_ENC_LEFT_A = p25; |
twighk | 11:bbddc908c78c | 59 | const PinName P_ENC_LEFT_B = p26; |
twighk | 11:bbddc908c78c | 60 | |
twighk | 11:bbddc908c78c | 61 | const PinName P_COLOR_SENSOR_RED = p29; |
twighk | 11:bbddc908c78c | 62 | const PinName P_COLOR_SENSOR_BLUE = p30; |
twighk | 11:bbddc908c78c | 63 | |
twighk | 4:1be0f6c6ceae | 64 | #include "Actuators/Arms/Arm.h" |
twighk | 1:8119211eae14 | 65 | #include "Actuators/MainMotors/MainMotor.h" |
twighk | 1:8119211eae14 | 66 | #include "Sensors/Encoders/Encoder.h" |
twighk | 4:1be0f6c6ceae | 67 | #include "Sensors/Colour/Colour.h" |
twighk | 8:69bdf20cb525 | 68 | #include "Sensors/CakeSensor/CakeSensor.h" |
twighk | 12:d4b5851742a3 | 69 | #include "Processes/Printing/Printing.h" |
madcowswe | 13:76c9915db820 | 70 | #include <algorithm> |
twighk | 0:200635fa1b08 | 71 | |
twighk | 0:200635fa1b08 | 72 | void motortest(); |
twighk | 0:200635fa1b08 | 73 | void encodertest(); |
twighk | 0:200635fa1b08 | 74 | void motorencodetest(); |
twighk | 0:200635fa1b08 | 75 | void motorencodetestline(); |
twighk | 0:200635fa1b08 | 76 | void motorsandservostest(); |
twighk | 1:8119211eae14 | 77 | void armtest(); |
twighk | 2:45da48fab346 | 78 | void motortestline(); |
twighk | 3:717de74f6ebd | 79 | void ledtest(); |
twighk | 3:717de74f6ebd | 80 | void phototransistortest(); |
twighk | 3:717de74f6ebd | 81 | void ledphototransistortest(); |
twighk | 3:717de74f6ebd | 82 | void colourtest(); |
twighk | 8:69bdf20cb525 | 83 | void cakesensortest(); |
twighk | 12:d4b5851742a3 | 84 | void printingtestthread(void const*); |
twighk | 12:d4b5851742a3 | 85 | void printingtestthread2(void const*); |
madcowswe | 13:76c9915db820 | 86 | void feedbacktest(); |
twighk | 0:200635fa1b08 | 87 | |
twighk | 0:200635fa1b08 | 88 | int main() { |
twighk | 2:45da48fab346 | 89 | |
twighk | 3:717de74f6ebd | 90 | /***************** |
twighk | 3:717de74f6ebd | 91 | * Test Code * |
twighk | 3:717de74f6ebd | 92 | *****************/ |
twighk | 0:200635fa1b08 | 93 | //motortest(); |
twighk | 0:200635fa1b08 | 94 | //encodertest(); |
twighk | 8:69bdf20cb525 | 95 | //motorencodetest(); |
twighk | 1:8119211eae14 | 96 | //motorencodetestline(); |
twighk | 0:200635fa1b08 | 97 | //motorsandservostest(); |
twighk | 3:717de74f6ebd | 98 | //armtest(); |
twighk | 2:45da48fab346 | 99 | //motortestline(); |
twighk | 11:bbddc908c78c | 100 | //ledtest(); |
twighk | 3:717de74f6ebd | 101 | //phototransistortest(); |
madcowswe | 13:76c9915db820 | 102 | //ledphototransistortest(); |
madcowswe | 5:56a5fdd373c9 | 103 | //colourtest(); // Red SnR too low |
madcowswe | 13:76c9915db820 | 104 | //cakesensortest(); |
madcowswe | 13:76c9915db820 | 105 | //feedbacktest(); |
twighk | 12:d4b5851742a3 | 106 | DigitalOut l1(LED1); |
twighk | 12:d4b5851742a3 | 107 | Thread p(printingThread, NULL, osPriorityNormal, 2048); |
twighk | 12:d4b5851742a3 | 108 | l1=1; |
twighk | 12:d4b5851742a3 | 109 | Thread a(printingtestthread, NULL, osPriorityNormal, 1024); |
twighk | 12:d4b5851742a3 | 110 | Thread b(printingtestthread2, NULL, osPriorityNormal, 1024); |
twighk | 12:d4b5851742a3 | 111 | Thread::wait(osWaitForever); |
madcowswe | 13:76c9915db820 | 112 | } |
madcowswe | 13:76c9915db820 | 113 | |
twighk | 12:d4b5851742a3 | 114 | #include <cstdlib> |
twighk | 12:d4b5851742a3 | 115 | using namespace std; |
twighk | 12:d4b5851742a3 | 116 | |
twighk | 12:d4b5851742a3 | 117 | void printingtestthread(void const*){ |
twighk | 12:d4b5851742a3 | 118 | const char ID = 1; |
twighk | 12:d4b5851742a3 | 119 | float buffer[3] = {ID}; |
twighk | 12:d4b5851742a3 | 120 | registerID(ID,sizeof(buffer)/sizeof(buffer[0])); |
twighk | 12:d4b5851742a3 | 121 | while (true){ |
twighk | 12:d4b5851742a3 | 122 | for(size_t i = 1; i != sizeof(buffer)/sizeof(buffer[0]); ++i){ |
twighk | 12:d4b5851742a3 | 123 | buffer[i] =ID ; |
twighk | 12:d4b5851742a3 | 124 | } |
twighk | 12:d4b5851742a3 | 125 | updateval(ID, buffer, sizeof(buffer)/sizeof(buffer[0])); |
twighk | 12:d4b5851742a3 | 126 | Thread::wait(200); |
twighk | 12:d4b5851742a3 | 127 | } |
twighk | 12:d4b5851742a3 | 128 | } |
madcowswe | 14:c638d4b9ee94 | 129 | |
twighk | 12:d4b5851742a3 | 130 | void printingtestthread2(void const*){ |
twighk | 12:d4b5851742a3 | 131 | const char ID = 2; |
twighk | 12:d4b5851742a3 | 132 | float buffer[5] = {ID}; |
twighk | 12:d4b5851742a3 | 133 | registerID(ID,sizeof(buffer)/sizeof(buffer[0])); |
twighk | 12:d4b5851742a3 | 134 | while (true){ |
twighk | 12:d4b5851742a3 | 135 | for(size_t i = 1; i != sizeof(buffer)/sizeof(buffer[0]); ++i){ |
twighk | 12:d4b5851742a3 | 136 | buffer[i] = ID; |
twighk | 12:d4b5851742a3 | 137 | } |
twighk | 12:d4b5851742a3 | 138 | updateval(ID, buffer, sizeof(buffer)/sizeof(buffer[0])); |
twighk | 12:d4b5851742a3 | 139 | Thread::wait(500); |
twighk | 12:d4b5851742a3 | 140 | } |
twighk | 8:69bdf20cb525 | 141 | } |
twighk | 8:69bdf20cb525 | 142 | |
madcowswe | 14:c638d4b9ee94 | 143 | |
madcowswe | 13:76c9915db820 | 144 | void feedbacktest(){ |
madcowswe | 13:76c9915db820 | 145 | Encoder Eright(P_ENC_RIGHT_A, P_ENC_RIGHT_B), Eleft(P_ENC_LEFT_A, P_ENC_LEFT_B); |
madcowswe | 13:76c9915db820 | 146 | MainMotor mright(P_MOT_RIGHT_A, P_MOT_RIGHT_B), mleft(P_MOT_LEFT_A, P_MOT_LEFT_B); |
madcowswe | 13:76c9915db820 | 147 | |
madcowswe | 13:76c9915db820 | 148 | float Pgain = -0.002; |
madcowswe | 13:76c9915db820 | 149 | float fwdspeed = -200/3.0f; |
madcowswe | 13:76c9915db820 | 150 | Timer timer; |
madcowswe | 13:76c9915db820 | 151 | timer.start(); |
madcowswe | 13:76c9915db820 | 152 | |
madcowswe | 13:76c9915db820 | 153 | while(true){ |
madcowswe | 13:76c9915db820 | 154 | float expecdist = fwdspeed * timer.read(); |
madcowswe | 13:76c9915db820 | 155 | float errleft = Eleft.getPoint() - (expecdist*1.07f); |
madcowswe | 13:76c9915db820 | 156 | float errright = Eright.getPoint() - expecdist; |
madcowswe | 13:76c9915db820 | 157 | |
madcowswe | 13:76c9915db820 | 158 | mleft(max(min(errleft*Pgain, 0.4f), -0.4f)); |
madcowswe | 13:76c9915db820 | 159 | mright(max(min(errright*Pgain, 0.4f), -0.4f)); |
madcowswe | 13:76c9915db820 | 160 | } |
twighk | 8:69bdf20cb525 | 161 | } |
twighk | 8:69bdf20cb525 | 162 | |
twighk | 8:69bdf20cb525 | 163 | void cakesensortest(){ |
twighk | 8:69bdf20cb525 | 164 | wait(1); |
twighk | 8:69bdf20cb525 | 165 | pc.printf("cakesensortest"); |
twighk | 8:69bdf20cb525 | 166 | |
twighk | 11:bbddc908c78c | 167 | CakeSensor cs(P_COLOR_SENSOR_IN); |
twighk | 8:69bdf20cb525 | 168 | while(true){ |
twighk | 8:69bdf20cb525 | 169 | wait(0.1); |
twighk | 8:69bdf20cb525 | 170 | pc.printf("distance: %f\t %f\r\n", cs.Distance(),cs.Distanceincm()); |
twighk | 8:69bdf20cb525 | 171 | } |
twighk | 3:717de74f6ebd | 172 | } |
twighk | 3:717de74f6ebd | 173 | |
twighk | 3:717de74f6ebd | 174 | void colourtest(){ |
madcowswe | 7:4340355261f9 | 175 | Colour c(P_COLOR_SENSOR_BLUE, P_COLOR_SENSOR_RED, P_COLOR_SENSOR_IN); |
twighk | 3:717de74f6ebd | 176 | c.Calibrate(); |
twighk | 3:717de74f6ebd | 177 | while(true){ |
twighk | 3:717de74f6ebd | 178 | wait(0.1); |
twighk | 3:717de74f6ebd | 179 | ColourEnum ce = c.getColour(); |
twighk | 3:717de74f6ebd | 180 | switch(ce){ |
twighk | 3:717de74f6ebd | 181 | case BLUE : |
twighk | 3:717de74f6ebd | 182 | pc.printf("BLUE\n\r"); |
twighk | 3:717de74f6ebd | 183 | break; |
twighk | 3:717de74f6ebd | 184 | case RED: |
twighk | 3:717de74f6ebd | 185 | pc.printf("RED\n\r"); |
twighk | 3:717de74f6ebd | 186 | break; |
twighk | 3:717de74f6ebd | 187 | case WHITE: |
twighk | 3:717de74f6ebd | 188 | pc.printf("WHITE\n\r"); |
twighk | 3:717de74f6ebd | 189 | break; |
twighk | 3:717de74f6ebd | 190 | case INCONCLUSIVE: |
twighk | 3:717de74f6ebd | 191 | pc.printf("INCONCLUSIVE\n\r"); |
twighk | 3:717de74f6ebd | 192 | break; |
twighk | 3:717de74f6ebd | 193 | default: |
twighk | 3:717de74f6ebd | 194 | pc.printf("BUG\n\r"); |
twighk | 3:717de74f6ebd | 195 | } |
twighk | 2:45da48fab346 | 196 | } |
twighk | 0:200635fa1b08 | 197 | |
twighk | 3:717de74f6ebd | 198 | } |
twighk | 3:717de74f6ebd | 199 | |
twighk | 3:717de74f6ebd | 200 | |
twighk | 3:717de74f6ebd | 201 | void ledphototransistortest(){ |
madcowswe | 7:4340355261f9 | 202 | DigitalOut blue(P_COLOR_SENSOR_BLUE), red(P_COLOR_SENSOR_RED); |
madcowswe | 7:4340355261f9 | 203 | AnalogIn pt(P_COLOR_SENSOR_IN); |
twighk | 3:717de74f6ebd | 204 | Serial pc(USBTX, USBRX); |
twighk | 3:717de74f6ebd | 205 | |
twighk | 3:717de74f6ebd | 206 | while(true){ |
twighk | 11:bbddc908c78c | 207 | blue = 0; red = 0; |
twighk | 11:bbddc908c78c | 208 | for(int i = 0; i != 5; i++){ |
twighk | 11:bbddc908c78c | 209 | wait(0.1); |
twighk | 11:bbddc908c78c | 210 | pc.printf("Phototransistor Analog is (none): %f \n\r", pt.read()); |
twighk | 11:bbddc908c78c | 211 | } |
twighk | 11:bbddc908c78c | 212 | |
madcowswe | 7:4340355261f9 | 213 | blue = 1; red = 0; |
twighk | 3:717de74f6ebd | 214 | for(int i = 0; i != 5; i++){ |
twighk | 3:717de74f6ebd | 215 | wait(0.1); |
twighk | 3:717de74f6ebd | 216 | pc.printf("Phototransistor Analog is (blue): %f \n\r", pt.read()); |
twighk | 3:717de74f6ebd | 217 | } |
madcowswe | 7:4340355261f9 | 218 | blue = 0; red = 1; |
twighk | 3:717de74f6ebd | 219 | for(int i = 0; i != 5; i++){ |
twighk | 3:717de74f6ebd | 220 | wait(0.1); |
twighk | 3:717de74f6ebd | 221 | pc.printf("Phototransistor Analog is (red ): %f \n\r", pt.read()); |
twighk | 3:717de74f6ebd | 222 | } |
twighk | 11:bbddc908c78c | 223 | blue = 1; red = 1; |
twighk | 11:bbddc908c78c | 224 | for(int i = 0; i != 5; i++){ |
twighk | 11:bbddc908c78c | 225 | wait(0.1); |
twighk | 11:bbddc908c78c | 226 | pc.printf("Phototransistor Analog is (both): %f \n\r", pt.read()); |
twighk | 11:bbddc908c78c | 227 | } |
twighk | 3:717de74f6ebd | 228 | } |
twighk | 3:717de74f6ebd | 229 | } |
twighk | 3:717de74f6ebd | 230 | |
twighk | 3:717de74f6ebd | 231 | void phototransistortest(){ |
madcowswe | 7:4340355261f9 | 232 | AnalogIn pt(P_COLOR_SENSOR_IN); |
twighk | 3:717de74f6ebd | 233 | while(true){ |
twighk | 3:717de74f6ebd | 234 | wait(0.1); |
twighk | 3:717de74f6ebd | 235 | pc.printf("Phototransistor Analog is: %f \n\r", pt.read()); |
twighk | 3:717de74f6ebd | 236 | } |
twighk | 3:717de74f6ebd | 237 | |
twighk | 3:717de74f6ebd | 238 | } |
twighk | 3:717de74f6ebd | 239 | |
twighk | 3:717de74f6ebd | 240 | void ledtest(){ |
madcowswe | 7:4340355261f9 | 241 | DigitalOut blue(P_COLOR_SENSOR_BLUE), red(P_COLOR_SENSOR_RED); |
twighk | 3:717de74f6ebd | 242 | while(true){ |
madcowswe | 7:4340355261f9 | 243 | blue = 1; red = 0; |
twighk | 3:717de74f6ebd | 244 | wait(0.2); |
madcowswe | 7:4340355261f9 | 245 | blue = 0; red = 1; |
twighk | 3:717de74f6ebd | 246 | wait(0.2); |
twighk | 3:717de74f6ebd | 247 | |
twighk | 3:717de74f6ebd | 248 | } |
twighk | 3:717de74f6ebd | 249 | } |
twighk | 3:717de74f6ebd | 250 | |
twighk | 1:8119211eae14 | 251 | void armtest(){ |
twighk | 3:717de74f6ebd | 252 | Arm white(p26), black(p25, false, 0.0005, 180); |
twighk | 3:717de74f6ebd | 253 | while(true){ |
twighk | 1:8119211eae14 | 254 | white(0); |
twighk | 1:8119211eae14 | 255 | black(0); |
twighk | 1:8119211eae14 | 256 | wait(1); |
twighk | 1:8119211eae14 | 257 | white(1); |
twighk | 1:8119211eae14 | 258 | black(1); |
twighk | 1:8119211eae14 | 259 | wait(1); |
twighk | 1:8119211eae14 | 260 | } |
twighk | 1:8119211eae14 | 261 | } |
twighk | 1:8119211eae14 | 262 | |
twighk | 1:8119211eae14 | 263 | |
twighk | 0:200635fa1b08 | 264 | void motorsandservostest(){ |
twighk | 0:200635fa1b08 | 265 | Encoder Eleft(p27, p28), Eright(p30, p29); |
twighk | 0:200635fa1b08 | 266 | MainMotor mleft(p24,p23), mright(p21,p22); |
twighk | 1:8119211eae14 | 267 | Arm sTop(p25), sBottom(p26); |
twighk | 4:1be0f6c6ceae | 268 | //Serial pc(USBTX, USBRX); |
twighk | 0:200635fa1b08 | 269 | const float speed = 0.0; |
twighk | 0:200635fa1b08 | 270 | const float dspeed = 0.0; |
twighk | 0:200635fa1b08 | 271 | |
twighk | 0:200635fa1b08 | 272 | Timer servoTimer; |
twighk | 0:200635fa1b08 | 273 | mleft(speed); mright(speed); |
twighk | 0:200635fa1b08 | 274 | servoTimer.start(); |
twighk | 0:200635fa1b08 | 275 | while (true){ |
twighk | 0:200635fa1b08 | 276 | pc.printf("Position is: %i \t %i \n\r", Eleft.getPoint(), Eright.getPoint()); |
twighk | 0:200635fa1b08 | 277 | if (Eleft.getPoint() < Eright.getPoint()){ |
twighk | 0:200635fa1b08 | 278 | mleft(speed); |
twighk | 0:200635fa1b08 | 279 | mright(speed - dspeed); |
twighk | 0:200635fa1b08 | 280 | } else { |
twighk | 0:200635fa1b08 | 281 | mright(speed); |
twighk | 0:200635fa1b08 | 282 | mleft(speed - dspeed); |
twighk | 0:200635fa1b08 | 283 | } |
twighk | 0:200635fa1b08 | 284 | if (servoTimer.read() < 1){ |
twighk | 0:200635fa1b08 | 285 | sTop.clockwise(); |
twighk | 0:200635fa1b08 | 286 | } else if (servoTimer.read() < 4) { |
twighk | 2:45da48fab346 | 287 | sTop.halt(); |
twighk | 0:200635fa1b08 | 288 | } else if (servoTimer.read() < 5) { |
twighk | 0:200635fa1b08 | 289 | sBottom.anticlockwise(); |
twighk | 0:200635fa1b08 | 290 | //Led=1; |
twighk | 0:200635fa1b08 | 291 | } else if (servoTimer.read() < 6) { |
twighk | 0:200635fa1b08 | 292 | sBottom.clockwise(); |
twighk | 0:200635fa1b08 | 293 | //Led=0; |
twighk | 0:200635fa1b08 | 294 | } else if (servoTimer.read() < 7) { |
twighk | 2:45da48fab346 | 295 | sBottom.halt(); |
twighk | 0:200635fa1b08 | 296 | }else { |
twighk | 0:200635fa1b08 | 297 | sTop.anticlockwise(); |
twighk | 0:200635fa1b08 | 298 | } |
twighk | 0:200635fa1b08 | 299 | if (servoTimer.read() >= 9) servoTimer.reset(); |
twighk | 0:200635fa1b08 | 300 | } |
twighk | 0:200635fa1b08 | 301 | } |
twighk | 0:200635fa1b08 | 302 | |
twighk | 2:45da48fab346 | 303 | void motortestline(){ |
twighk | 2:45da48fab346 | 304 | MainMotor mleft(p24,p23), mright(p21,p22); |
twighk | 2:45da48fab346 | 305 | const float speed = 0.2; |
twighk | 2:45da48fab346 | 306 | mleft(speed); mright(speed); |
twighk | 2:45da48fab346 | 307 | while(true) wait(1); |
twighk | 2:45da48fab346 | 308 | } |
twighk | 2:45da48fab346 | 309 | |
twighk | 0:200635fa1b08 | 310 | void motorencodetestline(){ |
madcowswe | 13:76c9915db820 | 311 | Encoder Eright(P_ENC_RIGHT_A, P_ENC_RIGHT_B), Eleft(P_ENC_LEFT_A, P_ENC_LEFT_B); |
madcowswe | 13:76c9915db820 | 312 | MainMotor mright(P_MOT_RIGHT_A, P_MOT_RIGHT_B), mleft(P_MOT_LEFT_A, P_MOT_LEFT_B); |
twighk | 4:1be0f6c6ceae | 313 | //Serial pc(USBTX, USBRX); |
twighk | 0:200635fa1b08 | 314 | const float speed = 0.2; |
twighk | 0:200635fa1b08 | 315 | const float dspeed = 0.1; |
twighk | 0:200635fa1b08 | 316 | |
twighk | 0:200635fa1b08 | 317 | mleft(speed); mright(speed); |
twighk | 0:200635fa1b08 | 318 | while (true){ |
twighk | 0:200635fa1b08 | 319 | //left 27 cm = 113 -> 0.239 cm/pulse |
twighk | 0:200635fa1b08 | 320 | //right 27 cm = 72 -> 0.375 cm/pulse |
twighk | 0:200635fa1b08 | 321 | pc.printf("Position is: %i \t %i \n\r", (int)(Eleft.getPoint()*0.239), (int)(Eright.getPoint()*0.375)); |
twighk | 0:200635fa1b08 | 322 | if (Eleft.getPoint()*0.239 < Eright.getPoint()*0.375){ |
twighk | 0:200635fa1b08 | 323 | mright(speed - dspeed); |
twighk | 0:200635fa1b08 | 324 | } else { |
twighk | 0:200635fa1b08 | 325 | mright(speed + dspeed); |
twighk | 0:200635fa1b08 | 326 | } |
twighk | 0:200635fa1b08 | 327 | } |
twighk | 0:200635fa1b08 | 328 | |
twighk | 0:200635fa1b08 | 329 | } |
twighk | 0:200635fa1b08 | 330 | |
twighk | 0:200635fa1b08 | 331 | void motorencodetest(){ |
madcowswe | 7:4340355261f9 | 332 | Encoder Eright(P_ENC_RIGHT_A, P_ENC_RIGHT_B), Eleft(P_ENC_LEFT_A, P_ENC_LEFT_B); |
madcowswe | 7:4340355261f9 | 333 | MainMotor mright(P_MOT_RIGHT_A, P_MOT_RIGHT_B), mleft(P_MOT_LEFT_A, P_MOT_LEFT_B); |
twighk | 0:200635fa1b08 | 334 | Serial pc(USBTX, USBRX); |
twighk | 0:200635fa1b08 | 335 | |
twighk | 0:200635fa1b08 | 336 | const float speed = -0.3; |
twighk | 0:200635fa1b08 | 337 | const int enc = -38; |
twighk | 0:200635fa1b08 | 338 | while(true){ |
twighk | 0:200635fa1b08 | 339 | mleft(speed); mright(0); |
twighk | 0:200635fa1b08 | 340 | while(Eleft.getPoint()>enc){ |
twighk | 0:200635fa1b08 | 341 | pc.printf("Position is: %i \t %i \n\r", Eleft.getPoint(), Eright.getPoint()); |
twighk | 0:200635fa1b08 | 342 | } |
twighk | 0:200635fa1b08 | 343 | Eleft.reset(); Eright.reset(); |
twighk | 0:200635fa1b08 | 344 | mleft(0); mright(speed); |
twighk | 0:200635fa1b08 | 345 | while(Eright.getPoint()>enc){ |
twighk | 0:200635fa1b08 | 346 | pc.printf("Position is: %i \t %i \n\r", Eleft.getPoint(), Eright.getPoint()); |
twighk | 0:200635fa1b08 | 347 | } |
twighk | 0:200635fa1b08 | 348 | Eleft.reset(); Eright.reset(); |
twighk | 0:200635fa1b08 | 349 | } |
twighk | 0:200635fa1b08 | 350 | } |
twighk | 0:200635fa1b08 | 351 | |
twighk | 0:200635fa1b08 | 352 | void encodertest(){ |
twighk | 0:200635fa1b08 | 353 | Encoder E1(p28, p27); |
twighk | 0:200635fa1b08 | 354 | Encoder E2(p29, p30); |
twighk | 0:200635fa1b08 | 355 | Serial pc(USBTX, USBRX); |
twighk | 3:717de74f6ebd | 356 | while(true){ |
twighk | 0:200635fa1b08 | 357 | wait(0.1); |
twighk | 0:200635fa1b08 | 358 | pc.printf("Position is: %i \t %i \n\r", E1.getPoint(), E2.getPoint()); |
twighk | 0:200635fa1b08 | 359 | } |
twighk | 0:200635fa1b08 | 360 | |
twighk | 0:200635fa1b08 | 361 | } |
twighk | 0:200635fa1b08 | 362 | void motortest(){ |
twighk | 0:200635fa1b08 | 363 | MainMotor mright(p22,p21), mleft(p23,p24); |
twighk | 3:717de74f6ebd | 364 | while(true) { |
twighk | 0:200635fa1b08 | 365 | wait(1); |
twighk | 0:200635fa1b08 | 366 | mleft(0.8); mright(0.8); |
twighk | 0:200635fa1b08 | 367 | wait(1); |
twighk | 0:200635fa1b08 | 368 | mleft(-0.2); mright(0.2); |
twighk | 0:200635fa1b08 | 369 | wait(1); |
twighk | 0:200635fa1b08 | 370 | mleft(0); mright(0); |
twighk | 0:200635fa1b08 | 371 | } |
twighk | 0:200635fa1b08 | 372 | } |