blob: 17d5e0fd102639cada4ac9ede811b5fbee0486a9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
package com.hackingroomba.roombacomm;
public class RobotType {
// encoder constants
private final double ROOMBA_COUNTS_PER_INCH = 57;
private final double MOBOT_COUNTS_PER_INCH = 250/80; // 205 counts in 80 inches
private final double TANKBOT_COUNTS_PER_INCH = 1800;
public double countsPerInch = ROOMBA_COUNTS_PER_INCH;
// spin tolerance constants
private final int ROOMBA_TOLERANCE = 2;
private final int MOBOT_TOLERANCE = 7;
private final int DEFAULT_TOLERANCE = 10;
public int tolerance = DEFAULT_TOLERANCE;
private final int FAST_ROOMBA_SPINSPEED = 100;
private final int SLOW_ROOMBA_SPINSPEED = 20;
private final int FAST_MOBOT_SPINSPEED = 120;
private final int SLOW_MOBOT_SPINSPEED = 80;
public int fastSpinSpeed;
public int slowSpinSpeed;
// PID constants
double ROOMBA_KP = 2.0;
double ROOMBA_KI = 1.0;
double ROOMBA_KD = 0.0;
double MOBOT_KP = 0.1;
double MOBOT_KI = 0.05;
double MOBOT_KD = 0.1;
double KP;
double KI;
double KD;
// robot types
public enum robotTypes {roomba, frankenRoomba, tankbot, mobot};
robotTypes robotType;
RobotType (robotTypes rt)
{
robotType = rt;
if ((rt == robotTypes.roomba) || (rt == robotTypes.frankenRoomba)) {
countsPerInch = ROOMBA_COUNTS_PER_INCH;
tolerance = ROOMBA_TOLERANCE; // tolerance of angle for spinToHeading
KP = ROOMBA_KP; // roomba PID constants
KI = ROOMBA_KI;
KD = ROOMBA_KD;
fastSpinSpeed = FAST_ROOMBA_SPINSPEED;
slowSpinSpeed = SLOW_ROOMBA_SPINSPEED;
} else if (rt == robotTypes.tankbot) {
countsPerInch = TANKBOT_COUNTS_PER_INCH;
tolerance = DEFAULT_TOLERANCE; // tolerance of angle for spinToHeading
KP = ROOMBA_KP; // tankbot PID constants
KI = ROOMBA_KI;
KD = ROOMBA_KD;
fastSpinSpeed = FAST_ROOMBA_SPINSPEED;
slowSpinSpeed = SLOW_ROOMBA_SPINSPEED;
} else if (rt == robotTypes.mobot) {
countsPerInch = MOBOT_COUNTS_PER_INCH;
tolerance = MOBOT_TOLERANCE; // tolerance of angle for spinToHeading
KP = MOBOT_KP; // Mo'bot PID constants
KI = MOBOT_KI;
KD = MOBOT_KD;
fastSpinSpeed = FAST_MOBOT_SPINSPEED;
slowSpinSpeed = SLOW_MOBOT_SPINSPEED;
}
}
public robotTypes getRobotType() {
return robotType;
}
public void setRobotType(robotTypes robotType) {
this.robotType = robotType;
}
}
|