Merge branch 'crawler-software' of https://kitsunehosting.net/gitea/Kenwood/lewis-crawler into crawler-software
This commit is contained in:
commit
209e15d41f
|
@ -1,33 +1,66 @@
|
||||||
/* Sweep
|
/* Crawler Slave
|
||||||
by BARRAGAN <http://barraganstudio.com>
|
*
|
||||||
This example code is in the public domain.
|
* This code runs on the crawler i2c network
|
||||||
|
* and provides a cleaner, less CPU intensive control over PWM devices.
|
||||||
modified 8 Nov 2013
|
|
||||||
by Scott Fitzgerald
|
|
||||||
http://www.arduino.cc/en/Tutorial/Sweep
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <Wire.h>
|
||||||
#include <Servo.h>
|
#include <Servo.h>
|
||||||
|
|
||||||
Servo myservo; // create servo object to control a servo
|
// This servo is used to wipe and clean the camera lens
|
||||||
// twelve servo objects can be created on most boards
|
Servo windowWiperServo;
|
||||||
|
|
||||||
int pos = 0; // variable to store the servo position
|
// 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;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
myservo.attach(9); // attaches the servo on pin 9 to the servo object
|
// Attach the wiper servo to pin 9
|
||||||
|
windowWiperServo.attach(9);
|
||||||
|
|
||||||
for (pos = 70; pos <= 130; pos += 1) { // goes from 0 degrees to 180 degrees
|
// This is only useful for debugging
|
||||||
// in steps of 1 degree
|
//Serial.begin(9600);
|
||||||
myservo.write(pos); // tell servo to go to position in variable 'pos'
|
|
||||||
delay(15); // waits 15ms for the servo to reach the position
|
// This is the address the pi will speak to us at
|
||||||
}
|
Wire.begin(0x4);
|
||||||
for (pos = 130; pos >= 70; pos -= 1) { // goes from 180 degrees to 0 degrees
|
|
||||||
myservo.write(pos); // tell servo to go to position in variable 'pos'
|
// Call receiveEvent when data received
|
||||||
delay(15); // waits 15ms for the servo to reach the position
|
Wire.onReceive(receiveEvent);
|
||||||
}
|
|
||||||
|
//Serial.println("Finished Setup.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Just loop to keep the running code alive, and wait for events to happen.
|
||||||
void loop() {
|
void loop() {
|
||||||
delay(1000);
|
delay(50);
|
||||||
|
}
|
||||||
|
|
||||||
|
// This method runs when we receive a message
|
||||||
|
void receiveEvent(int n) {
|
||||||
|
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
instruction[i] = Wire.read();
|
||||||
|
instruction[i + 1] = '\0'; //add null after ea. char
|
||||||
|
}
|
||||||
|
|
||||||
|
//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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
[Unit]
|
||||||
|
Description=Crawler service overseer, manages running main crawler software
|
||||||
|
After=multi-user.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
Restart=always
|
||||||
|
ExecStart=/usr/bin/python /srv/crawler/crawler.py
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
Loading…
Reference in New Issue