Compare commits

..

7 Commits

3 changed files with 33 additions and 32 deletions

7
README.md Normal file
View File

@ -0,0 +1,7 @@
# To install on robot
```
git clone <url>
cd lewis-crawler/crawler_software/raspberry_pi
make install?
```

View File

@ -10,27 +10,28 @@
// This servo is used to wipe and clean the camera lens // This servo is used to wipe and clean the camera lens
Servo windowWiperServo; Servo windowWiperServo;
// This is a variable capable of storing up to 4 items // Variables populated over i2c from master
char instruction[32] = ""; int id;
int val;
// Values for the id, and raw value of an instruction
char * id;
char * raw_value;
void setup() { void setup() {
// For debugging
//Serial.begin(115200);
// Attach the wiper servo to pin 9 // Attach the wiper servo to pin 9
windowWiperServo.attach(9); windowWiperServo.attach(9);
// This is only useful for debugging
//Serial.begin(9600);
// This is the address the pi will speak to us at // This is the address the pi will speak to us at
Wire.begin(0x4); Wire.begin(0x4);
// Call receiveEvent when data received // Call receiveEvent when data received
Wire.onReceive(receiveEvent); 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. // Just loop to keep the running code alive, and wait for events to happen.
@ -40,27 +41,20 @@ void loop() {
// This method runs when we receive a message // This method runs when we receive a message
void receiveEvent(int n) { void receiveEvent(int n) {
Wire.read();
digitalWrite(LED_BUILTIN, HIGH);
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++) { //Serial.println(id);
instruction[i] = Wire.read(); //Serial.println(val);
instruction[i + 1] = '\0'; //add null after ea. char
} switch(id) {
case 1:
//RPi first byte is cmd byte so shift everything to the left 1 pos so temp contains our string windowWiperServo.write(val);
for (int i = 0; i < n; ++i) break;
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);
} }
digitalWrite(LED_BUILTIN, LOW);
} }

View File

@ -1,2 +1,2 @@
PySSTV PySSTV
picamera picamera