40 analogReadResolution(14);
50 return dst_sensor[num].
read();
58 return dst_sensor[num].
readMM();
66 return dst_sensor[num].
readIN();
74 if (bump_sw[num].read() == 0) {
84 if (bump_sw[x].read() == 0) {
138 if (direction == 0) {
140 }
else if (direction == 1) {
146 if (direction == 0) {
148 }
else if (direction == 1) {
165void setRawMotorSpeed(uint8_t motorNum, uint8_t speed)
191 uint32_t scanTime = millis() + duration;
198 }
while (millis() < scanTime);
205 sensorMaxValues, lineMode);
210 uint16_t *sensorMinVal,
211 uint16_t *sensorMaxVal,
217 if (sensorValues[x] < sensorMinVal[x])
218 calVal[x] = map(sensorValues[x], 0, sensorMinVal[x], 1000, 0);
221 if (sensorValues[x] > sensorMaxVal[x])
222 calVal[x] = map(sensorValues[x], sensorMaxVal[x], 2500, 0, 1000);
238 uint32_t _lastPosition = 0;
240 uint16_t value = calVal[i-1];
244 avg += (uint32_t)value * (i * 1000);
250 _lastPosition = avg / sum;
251 return _lastPosition;
257 if (sensor[x] < sensorMin[x]) {
258 sensorMin[x] = sensor[x];
260 if (sensor[x] > sensorMax[x]) {
261 sensorMax[x] = sensor[x];
268 pinMode(btn, INPUT_PULLUP);
273 pinMode(ledPin, OUTPUT);
279 uint8_t pinVal = HIGH;
281 if (ledPin > MAX_PIN_NUMBER)
285 digitalWrite(ledPin, pinVal);
286 while (digitalRead(btnPin) == 1) {
293 digitalWrite(ledPin, pinVal);
300 digitalWrite(ledPin, pinVal);
304 while (digitalRead(btnPin) == 0)
#define ENCODER_ERB_PIN
Value represents Energia number for Launchpad Pin P5.0.
#define MOTOR_L_PWM_PIN
Value represents Energia number for Launchpad Pin P2.7.
#define QTR_4
Value represents Energia number for Launchpad Pin P7.4.
#define ENCODER_ELB_PIN
Value represents Energia number for Launchpad Pin P5.2.
#define QTR_2
Value represents Energia number for Launchpad Pin P7.2.
#define QTR_7
Value represents Energia number for Launchpad Pin P7.7.
#define SHRP_DIST_R_PIN
Value represents Energia number for Launchpad Pin P9.0.
#define MOTOR_L_DIR_PIN
Value represents Energia number for Launchpad Pin P5.4.
#define SHRP_DIST_C_PIN
Value represents Energia number for Launchpad Pin P6.1.
#define QTR_1
Value represents Energia number for Launchpad Pin P7.1.
#define BP_SW_PIN_3
Value represents Energia number for Launchpad Pin P4.3.
#define SHRP_DIST_L_PIN
Value represents Energia number for Launchpad Pin P9.1.
#define ENCODER_ELA_PIN
Value represents Energia number for Launchpad Pin P10.5.
#define QTR_EMITTER_PIN_ODD
Value represents Energia number for Launchpad Pin P9.2.
#define ENCODER_ERA_PIN
Value represents Energia number for Launchpad Pin P10.4.
#define MOTOR_R_PWM_PIN
Value represents Energia number for Launchpad Pin P2.6.
#define QTR_6
Value represents Energia number for Launchpad Pin P7.6.
#define MOTOR_R_SLP_PIN
Value represents Energia number for Launchpad Pin P3.6.
#define BP_SW_PIN_2
Value represents Energia number for Launchpad Pin P4.5.
#define BP_SW_PIN_1
Value represents Energia number for Launchpad Pin P4.6.
#define BP_SW_PIN_5
Value represents Energia number for Launchpad Pin P4.0.
#define MOTOR_R_DIR_PIN
Value represents Energia number for Launchpad Pin P5.5.
#define QTR_5
Value represents Energia number for Launchpad Pin P7.5.
#define QTR_3
Value represents Energia number for Launchpad Pin P7.3.
#define BP_SW_PIN_0
Value represents Energia number for Launchpad Pin P4.7.
#define QTR_EMITTER_PIN_EVEN
Value represents Energia number for Launchpad Pin P5.3.
#define QTR_0
Value represents Energia number for Launchpad Pin P7.0.
#define BP_SW_PIN_4
Value represents Energia number for Launchpad Pin P4.2.
#define MOTOR_L_SLP_PIN
Value represents Energia number for Launchpad Pin P3.7.
Represents a single bump switch.
bool begin(uint8_t pin_num, uint8_t mode=INPUT_PULLUP)
Initialize the bump switch class.
Class for Pololu's Sharp GP2Y0A21YK0F analog distance sensor.
int16_t readMM()
Read the distance from the Sharp distance sensor in millimeters.
bool begin(uint8_t pin_num, uint8_t mode=INPUT_PULLDOWN)
Initialize the distance sensor class.
float readIN()
Read the distance from the Sharp distance sensor in inches.
uint16_t read()
Read the value from distance sensor.
Represents a QTR sensor array.
void setTypeRC()
Specifies that the sensors are RC.
void setEmitterPins(uint8_t oddEmitterPin, uint8_t evenEmitterPin)
Sets separate odd and even emitter control pins for the sensors.
void read(uint16_t *sensorValues, QTRReadMode mode=QTRReadMode::On)
Reads the raw sensor values into an array.
void setSensorPins(const uint8_t *pins, uint8_t sensorCount)
Sets the sensor pins.
Represents a single motor.
void disableMotor()
Disable motor.
void directionForward()
Set motor's direction to forward.
void pauseMotor()
Pause motor.
void resumeMotor()
Resume motor.
void setRawSpeed(uint8_t speed)
Set motor's raw speed.
void setSpeed(uint8_t speed)
Set motor speed.
bool begin(uint8_t islp_pin, uint8_t idir_pin, uint8_t ipwm_pin)
Initialize the motor and configures important pins.
void enableMotor()
Enable motor.
void directionBackward()
Set motor's direction to backwards.
#define DARK_LINE
Used to specify that the robot is running on a floor lighter than the line.
uint32_t getLinePosition()
Get line position.
#define TOTAL_BP_SW
Total number of bump switches.
#define DST_NUM_SENSORS
Total number of distance sensors.
void enableMotor(uint8_t motorNum)
Enable motor (take it out of sleep)
float readSharpDistIN(uint8_t num)
Read distance sensor value in inches.
void setMotorSpeed(uint8_t motorNum, uint8_t speed)
Set the motor speed.
bool isBumpSwitchPressed(uint8_t num)
Return bump switch status.
void setupRSLK()
Performs a variety of initialization needed for the RSLK.
void clearMinMax(uint16_t *sensorMin, uint16_t *sensorMax)
Provide default values for the sensor's Min and Max arrays.
#define readLineSensor
Read line sensor values.
void disableMotor(uint8_t motorNum)
Disable motor (puts the motor to sleep)
#define NUM_MOTORS
Total number of motors.
void setMotorDirection(uint8_t motorNum, uint8_t direction)
Set direction the motor will turn.
uint16_t readSharpDist(uint8_t num)
Read distance sensor value.
void readRawLineSensor(uint16_t *sensorValues)
Read raw line sensor values.
uint8_t getBumpSwitchPressed()
Return mask of bump switch states.
#define LEFT_MOTOR
Can be used to reference the left motor in the below functions.
void waitBtnPressed(uint8_t btnPin, int8_t ledPin)
Busy wait until user pushes and releases button.
void setupWaitBtn(uint8_t btn)
Configure pin as a wait to release button.
void pauseMotor(uint8_t motorNum)
Pause motor (put the motor to sleep while saving its speed)
void readCalLineSensor(uint16_t *calVal)
Read calibrated line sensor values. Assumes calibration completed.
void setupLed(uint8_t ledPin)
Configure pin that is connected to an led.
#define LS_NUM_SENSORS
Total number of sensors on QTR line sensor.
void calibrateLineSensor(uint8_t mode, uint32_t duration)
Calibrates line sensor.
#define RIGHT_MOTOR
Can be used to reference the right motor in the below functions.
#define BOTH_MOTORS
Can be used to reference both motors in the below functions.
void resumeMotor(uint8_t motorNum)
Resume motor (take the motor out of sleep and resumes its prior speed)
int16_t readSharpDistMM(uint8_t num)
Read distance sensor value in millimeters.
void setSensorMinMax(uint16_t *sensor, uint16_t *sensorMin, uint16_t *sensorMax)
Update line sensor's min and max values array based on current data.