41 if(num < 0 || num > 3)
44 return dst_sensor[num].
read();
48 if(num < 0 || num > 5)
51 if(bump_sw[num].read() == 0) {
58 if(motorNum == 0 || motorNum == 2)
63 if(motorNum == 1 || motorNum == 2)
72 if(motorNum == 0 || motorNum == 2)
77 if(motorNum == 1 || motorNum == 2)
85 if(motorNum == 0 || motorNum == 2)
90 if(motorNum == 1 || motorNum == 2)
97 if(motorNum == 0 || motorNum == 2)
102 if(motorNum == 1 || motorNum == 2)
110 if(motorNum == 0 || motorNum == 2)
114 }
else if(direction == 1) {
119 if(motorNum == 1 || motorNum == 2)
123 }
else if(direction == 1) {
130 if(motorNum == 0 || motorNum == 2)
135 if(motorNum == 1 || motorNum == 2)
141 void setRawMotorSpeed(uint8_t motorNum, uint8_t speed) {
142 if(motorNum == 0 || motorNum == 2)
147 if(motorNum == 1 || motorNum == 2)
168 uint16_t *sensorMinVal,
169 uint16_t *sensorMaxVal,
177 if(sensorValues[x] > sensorMaxVal[x])
178 calVal[x] = map(sensorValues[x],sensorMaxVal[x],2500,0,1000);
181 if(sensorValues[x] < sensorMinVal[x])
182 calVal[x] = map(sensorValues[x],0,sensorMinVal[x],1000,0);
193 uint32_t _lastPosition;
196 uint16_t value = calVal[i];
201 avg += (uint32_t)value * (i * 1000);
206 _lastPosition = avg / sum;
207 return _lastPosition;
213 if(sensor[x] < sensorMin[x])
215 sensorMin[x] = sensor[x];
217 if(sensor[x] > sensorMax[x])
219 sensorMax[x] = sensor[x];
225 pinMode(btn, INPUT_PULLUP);
229 while(digitalRead(btn) == 1);
230 Serial.println(
"Button pressed");
232 while(digitalRead(btn) == 0);
void setMotorDirection(uint8_t motorNum, uint8_t direction)
Set direction the motor will turn.
#define BP_SW_PIN_5
Value represents Energia number for Launchpad Pin P4.7.
Represents a QTR sensor array.
void directionForward()
Set motor's direction to forward.
void setSpeed(uint8_t speed)
Set motor speed.
#define ENCODER_ERB_PIN
Value represents Energia number for Launchpad Pin P5.0.
void enableMotor()
Enable motor.
#define QTR_0
Value represents Energia number for Launchpad Pin P7.0.
void setEmitterPins(uint8_t oddEmitterPin, uint8_t evenEmitterPin)
Sets separate odd and even emitter control pins for the sensors.
uint16_t readSharpDist(uint8_t num)
Read distance sensor value.
bool isBumpSwitchPressed(uint8_t num)
Return bump switch status.
void resumeMotor()
Resume motor.
#define QTR_EMITTER_PIN_ODD
Value represents Energia number for Launchpad Pin P9.2.
#define QTR_2
Value represents Energia number for Launchpad Pin P7.2.
bool begin(uint8_t pin_num, uint8_t mode=INPUT_PULLDOWN)
Initialize the distance sensor class.
#define QTR_EMITTER_PIN_EVEN
Value represents Energia number for Launchpad Pin P5.3.
bool begin(uint8_t pin_num, uint8_t mode=INPUT_PULLUP)
Initialize the bump switch class.
#define SHRP_DIST_L_PIN
Value represents Energia number for Launchpad Pin P9.1.
#define MOTOR_R_SLP_PIN
Value represents Energia number for Launchpad Pin P3.6.
void setSensorPins(const uint8_t *pins, uint8_t sensorCount)
Sets the sensor pins.
#define QTR_6
Value represents Energia number for Launchpad Pin P7.6.
void setTypeRC()
Specifies that the sensors are RC.
#define ENCODER_ELB_PIN
Value represents Energia number for Launchpad Pin P5.2.
void readLineSensor(uint16_t *sensor)
Read line sensor values.
void clearMinMax(uint16_t *sensorMin, uint16_t *sensorMax)
Provide default values for the sensor's Min and Max arrays.
#define QTR_7
Value represents Energia number for Launchpad Pin P7.7.
#define MOTOR_L_SLP_PIN
Value represents Energia number for Launchpad Pin P3.7.
Class for Pololu's Sharp GP2Y0A21YK0F analog distance sensor.
uint32_t getLinePosition(uint16_t *calVal, uint8_t mode)
Get line position.
#define ENCODER_ERA_PIN
Value represents Energia number for Launchpad Pin P10.4.
#define SHRP_DIST_R_PIN
Value represents Energia number for Launchpad Pin P9.0.
#define BP_SW_PIN_2
Value represents Energia number for Launchpad Pin P4.3.
bool begin(uint8_t islp_pin, uint8_t idir_pin, uint8_t ipwm_pin)
Initialize the motor and configures important pins.
#define BP_SW_PIN_4
Value represents Energia number for Launchpad Pin P4.6.
Represents a single bump switch.
void setupEncoder(uint8_t ela_pin, uint8_t elb_pin, uint8_t era_pin, uint8_t erb_pin)
Initialize the wheel encoder.
void setupRSLK()
Performs a variety of initialization needed for the RSLK.
void directionBackward()
Set motor's direction to backwards.
#define MOTOR_L_DIR_PIN
Value represents Energia number for Launchpad Pin P5.4.
void disableMotor(uint8_t motorNum)
Disable motor (puts the motor to sleep)
void setMotorSpeed(uint8_t motorNum, uint8_t speed)
Set the motor speed.
void setupWaitBtn(uint8_t btn)
Configure pin as a wait to release button.
#define MOTOR_R_PWM_PIN
Value represents Energia number for Launchpad Pin P2.6.
#define QTR_4
Value represents Energia number for Launchpad Pin P7.4.
void resumeMotor(uint8_t motorNum)
Resume motor (take the motor out of sleep and resumes its prior speed)
uint16_t read()
Read the value from distance sensor.
void setSensorMinMax(uint16_t *sensor, uint16_t *sensorMin, uint16_t *sensorMax)
Update line sensor's min and max values array based on current data.
#define BP_SW_PIN_0
Value represents Energia number for Launchpad Pin P4.0.
void pauseMotor()
Pause motor.
#define BP_SW_PIN_3
Value represents Energia number for Launchpad Pin P4.5.
Represents a single motor.
#define QTR_1
Value represents Energia number for Launchpad Pin P7.1.
void read(uint16_t *sensorValues, QTRReadMode mode=QTRReadMode::On)
Reads the raw sensor values into an array.
void disableMotor()
Disable motor.
#define ENCODER_ELA_PIN
Value represents Energia number for Launchpad Pin P10.5.
#define QTR_3
Value represents Energia number for Launchpad Pin P7.3.
#define MOTOR_R_DIR_PIN
Value represents Energia number for Launchpad Pin P5.5.
void waitBtnPressed(uint8_t btn)
Busy wait until user pushes and releases button.
void setRawSpeed(uint8_t speed)
Set motor's raw speed.
#define BP_SW_PIN_1
Value represents Energia number for Launchpad Pin P4.2.
#define SHRP_DIST_C_PIN
Value represents Energia number for Launchpad Pin P6.1.
void pauseMotor(uint8_t motorNum)
Pause motor (put the motor to sleep while saving its speed)
#define LS_NUM_SENSORS
Total number of sensors on QTR line sensor.
void readCalLineSensor(uint16_t *sensor, uint16_t *calVal, uint16_t *sensorMin, uint16_t *sensorMax, uint8_t mode)
Update sensor's min and max values array based on current data.
#define QTR_5
Value represents Energia number for Launchpad Pin P7.5.
#define BOTH_MOTORS
Can be used to reference both motors in the below functions.
void enableMotor(uint8_t motorNum)
Enable motor (take it out of sleep)
#define MOTOR_L_PWM_PIN
Value represents Energia number for Launchpad Pin P2.7.