Compare commits
8 Commits
b5ba5f6f9e
...
crawler-so
| Author | SHA1 | Date | |
|---|---|---|---|
| 6fbb53b6bd | |||
| f6bb087799 | |||
| 21330c945d | |||
| 32bd0f5b55 | |||
| 13eb27b9c3 | |||
| f34cb81c7a | |||
| 8f7e12ec90 | |||
| 6f1e5af90f |
7
README.md
Normal file
7
README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
# To install on robot
|
||||
|
||||
```
|
||||
git clone <url>
|
||||
cd lewis-crawler/crawler_software/raspberry_pi
|
||||
make install?
|
||||
```
|
||||
@@ -10,27 +10,28 @@
|
||||
// This servo is used to wipe and clean the camera lens
|
||||
Servo windowWiperServo;
|
||||
|
||||
// This is a variable capable of storing up to 4 items
|
||||
char instruction[32] = "";
|
||||
|
||||
// Values for the id, and raw value of an instruction
|
||||
char * id;
|
||||
char * raw_value;
|
||||
// Variables populated over i2c from master
|
||||
int id;
|
||||
int val;
|
||||
|
||||
void setup() {
|
||||
// For debugging
|
||||
//Serial.begin(115200);
|
||||
|
||||
// Attach the wiper servo to pin 9
|
||||
windowWiperServo.attach(9);
|
||||
|
||||
// This is only useful for debugging
|
||||
//Serial.begin(9600);
|
||||
|
||||
// This is the address the pi will speak to us at
|
||||
Wire.begin(0x4);
|
||||
|
||||
// Call receiveEvent when data received
|
||||
Wire.onReceive(receiveEvent);
|
||||
|
||||
//Serial.println("Finished Setup.");
|
||||
// Setup LED
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
//Serial.println("Started");
|
||||
}
|
||||
|
||||
// Just loop to keep the running code alive, and wait for events to happen.
|
||||
@@ -40,27 +41,23 @@ void loop() {
|
||||
|
||||
// This method runs when we receive a message
|
||||
void receiveEvent(int n) {
|
||||
Wire.read(); // Remove smbus trash
|
||||
if (true) { // Dont do anything if this is not true
|
||||
id = Wire.read(); // ID of the servo/device to access
|
||||
val = Wire.read(); // Value to assign
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
instruction[i] = Wire.read();
|
||||
instruction[i + 1] = '\0'; //add null after ea. char
|
||||
//Serial.println(id);
|
||||
//Serial.println(val);
|
||||
|
||||
switch(id) {
|
||||
case 1:
|
||||
windowWiperServo.write(val);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//RPi first byte is cmd byte so shift everything to the left 1 pos so temp contains our string
|
||||
for (int i = 0; i < n; ++i)
|
||||
instruction[i] = instruction[i + 1];
|
||||
|
||||
id = strtok (instruction, "-");
|
||||
raw_value = strtok (NULL, "-");
|
||||
|
||||
int value = atoi(raw_value);
|
||||
|
||||
//Serial.println(id);
|
||||
//Serial.println(value);
|
||||
|
||||
// Switch statements dont work on char *
|
||||
if (strcmp(id,"WIPE") == 0) // if id, and WIPE cancel out
|
||||
{
|
||||
windowWiperServo.write(value);
|
||||
// Prevents a bug where if bytes are left in buffer, arduino crashes.
|
||||
while (Wire.available()) {
|
||||
Wire.read();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user