diff options
-rw-r--r-- | reader/reader.py | 7 | ||||
-rw-r--r-- | sketch_apr09a/sketch_apr09a.ino | 82 |
2 files changed, 73 insertions, 16 deletions
diff --git a/reader/reader.py b/reader/reader.py index 8e4fe2c..5868bcb 100644 --- a/reader/reader.py +++ b/reader/reader.py @@ -24,8 +24,8 @@ def main(): thread.start_new_thread(server_procedure, (server,)) - #with serial.Serial('/dev/ttyACM0', 9600) as ser: - with open('/tmp/fifo') as ser: + with serial.Serial('/dev/ttyACM0', 9600) as ser: + #with open('/tmp/fifo') as ser: while True: line = ser.readline() @@ -43,6 +43,7 @@ def main(): measures['flexion'] = line.split('FLEXION:')[1] elif line.startswith('ANGLE_X:'): measures['angle_x'] = line.split('ANGLE_X:')[1] + server.send_message_to_all(json.dumps(measures)) elif line.startswith('ANGLE_Y:'): measures['angle_y'] = line.split('ANGLE_Y:')[1] elif line.startswith('ANGLE_Z:'): @@ -50,8 +51,6 @@ def main(): else: print(line) - server.send_message_to_all(json.dumps(measures)) - if __name__ == '__main__': diff --git a/sketch_apr09a/sketch_apr09a.ino b/sketch_apr09a/sketch_apr09a.ino index 284a2a1..249ee1c 100644 --- a/sketch_apr09a/sketch_apr09a.ino +++ b/sketch_apr09a/sketch_apr09a.ino @@ -1,6 +1,35 @@ +#include <NAxisMotion.h> +#include <Wire.h> #include "Belt.h" #include "logs.h" +// Belt sensors +int PhotoSenspin1 = 0; // premier photo sensor +int PhotoSensReading1; //premier photo sensor +int PhotoSenspin2 = 1; // deuxieme photo sensor +int PhotoSensReading2; //deuxieme photo sensor + +//Object that for the sensor +NAxisMotion mySensor; + +//Flag to indicate if an interrupt was detected +bool intDetected = false; + +//At a Range of 4g, the threshold +//is set at 39.05mg or 0.3830m/s2. +//This Range is the default for NDOF Mode +int threshold = 5; + +//At a filter Bandwidth of 62.5Hz, +//the duration is 8ms. +//This Bandwidth is the default for NDOF Mode +int duration = 1; +bool anyMotion = true; + +//To store the last streamed time stamp +unsigned long lastStreamTime = 0; +const int streamPeriod = 500; + Belt::Belt() { _pin_pressure_bottom = 0; @@ -38,11 +67,6 @@ void Belt::read_angle_z() static Belt belt; -void setup() -{ - Serial.begin(9600); -} - static void send_pressure_bottom(int pressure) { serial_printf("PRESSURE_BOTTOM:%d\n", pressure); @@ -68,9 +92,27 @@ static void send_angle_z(int angle) serial_printf("ANGLE_Z:%d\n", angle); } +void setup() +{ + Serial.begin(115200); //Initialize the Serial Port to view information on the Serial Monitor + I2C.begin(); //Initialize I2C communication to the let the library communicate with the sensor. + mySensor.initSensor(); //The I2C Address can be changed here inside this function in the library + mySensor.setOperationMode(OPERATION_MODE_NDOF); //Can be configured to other operation modes as desired + mySensor.setUpdateMode(MANUAL); //The default is AUTO. Changing to MANUAL requires calling the relevant update functions prior to calling the read functions + //Setting to MANUAL requires fewer reads to the sensor +} + void loop() { - delay(500); + if ((millis() - lastStreamTime) < streamPeriod) { + return; + } + + lastStreamTime = millis(); + mySensor.updateEuler(); //Update the Euler data into the structure of the object + mySensor.updateCalibStatus(); //Update the Calibration Status + PhotoSensReading1 = analogRead(PhotoSenspin1); + PhotoSensReading2 = analogRead(PhotoSenspin2); /* fetch the values from the sensors */ belt.read_pressure_bottom(); @@ -80,10 +122,26 @@ void loop() belt.read_angle_y(); belt.read_angle_z(); - serial_printf("PRESSURE_BOTTOM: bottom:%d\n", belt.get_pressure_bottom()); - serial_printf("PRESSURE_TOP:%d\n", belt.get_pressure_top()); - serial_printf("FLEXION:%d\n", belt.get_flexion()); - serial_printf("ANGLE_X:%d\n", belt.get_angle_x()); - serial_printf("ANGLE_Y:%d\n", belt.get_angle_y()); - serial_printf("ANGLE_Z:%d\n", belt.get_angle_z()); + int heading = mySensor.readEulerHeading(); + int pitch = mySensor.readEulerPitch(); + int roll = mySensor.readEulerRoll(); + + serial_printf("pitch: [%d]\n", pitch); + //pitch = map(pitch, 1, 1023, 90, 270); + serial_printf("pitch_mapped: [%d]\n", pitch); + serial_puts("-------"); + serial_printf("roll: [%d]\n", roll); + //roll = map(roll, 1, 1023, 90, 270); + serial_printf("roll_mapped: [%d]\n", roll); + serial_puts("-------"); + serial_printf("heading: [%d]\n", heading); + //heading = map(heading, 1, 1023, 90, 270); + serial_printf("heading_mapped: [%d]\n", heading); + + serial_printf("ANGLE_X:%d\n", pitch); + serial_printf("ANGLE_Y:%d\n", roll); + serial_printf("ANGLE_Z:%d\n", heading); + + serial_printf("PRESSURE_TOP:%d\n", PhotoSenspin1); + serial_printf("PRESSURE_BOTTOM:%d\n", PhotoSenspin1); } |