[chronojump: 3/4] Race Analyzer firmware. Sending in binary mode
- From: Xavier Padullés <xpadulles src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump: 3/4] Race Analyzer firmware. Sending in binary mode
- Date: Tue, 22 Oct 2019 09:12:05 +0000 (UTC)
commit 907d2b7c7145bc767456457caa6fb292244638b0
Author: Xavier Padullés <x padulles gmail com>
Date: Tue Oct 22 10:59:03 2019 +0200
Race Analyzer firmware. Sending in binary mode
arduino/raceAnalyzer/raceAnalyzer.ino | 95 +++++++++++++++++++++--------------
1 file changed, 56 insertions(+), 39 deletions(-)
---
diff --git a/arduino/raceAnalyzer/raceAnalyzer.ino b/arduino/raceAnalyzer/raceAnalyzer.ino
index b4266dc6..f9b533ab 100644
--- a/arduino/raceAnalyzer/raceAnalyzer.ino
+++ b/arduino/raceAnalyzer/raceAnalyzer.ino
@@ -2,9 +2,10 @@
#include <Adafruit_ADS1015.h>
#include <EEPROM.h>
+//TODO: Test the Texas Instrument ADS1256
Adafruit_ADS1115 loadCell;
-int encoderPinA = 3;
+int encoderPinA = 3; //Pin associated with the encoder interruption
int encoderPinB = 4;
volatile int encoderDisplacement = 0;
int lastEncoderDisplacement = 0;
@@ -15,7 +16,7 @@ unsigned long lastSampleTime = micros();
unsigned long sampleTime = 0;
//Version of the firmware
-String version = "Race_Analyzer-0.1";
+String version = "Race_Analyzer-0.2";
int pps = 10; //Pulses Per Sample. How many pulses are needed to get a sample
int ppsAddress = 0; //Where is stored the pps value in the EEPROM
@@ -26,7 +27,7 @@ int offsetAddress = 2;
float calibrationFactor = 0.140142;
int calibrationAddress = 4;
-float metersPerPulse = 0.003003;
+float metersPerPulse = 0.003003; //Value for the manual race encoder
int metersPerPulseAddress = 8;
//Wether the sensor has to capture or not
@@ -39,7 +40,10 @@ boolean procesSample = false;
boolean binaryFormat = false;
//baud rate of the serial communication
-unsigned long baudRate = 1000000;
+unsigned long baudRate = 2000000;
+
+//Number of samples sent. Just for debugging
+int samplesSent = 0;
void setup() {
@@ -79,7 +83,7 @@ void setup() {
//if metersPerPulse is not a number it means that it has never been set. We use the default value
if (isnan(metersPerPulse)){
- metersPerPulse = 0.140142;
+ metersPerPulse = 0.003003;
EEPROM.put(metersPerPulseAddress, metersPerPulse);
}
@@ -91,7 +95,6 @@ void setup() {
}
void loop() {
- //double totalForce = 0;
long int totalForce = 0;
int nReadings = 0;
int offsettedData = 0;
@@ -101,16 +104,15 @@ void loop() {
if (capturing)
{
- //With a diameter is of 160mm, each pulse is 2.513274mm. 4 pulses equals 1.00531cm
+ //TODO: If the value of the force is negative, send a 0
while (!procesSample) {
offsettedData = readOffsettedData(0);
//Serial.println(offsettedData);
totalForce += offsettedData;
- //force = readOffsettedData(0);
- //totalForce += force;
nReadings++;
//If some string comes from Serial process the sample
+ //This makes that the sample after getting the command "end_capture:" has less pulses than pps
if (Serial.available() > 0) {
sampleTime = micros();
lastEncoderDisplacement = encoderDisplacement;
@@ -119,8 +121,6 @@ void loop() {
}
}
- //int lastEncoderDisplacement = encoderDisplacement; //Assigned to another variable for in the case that
encoder displacement changes before printing it
-
//Managing the timer overflow
if (sampleTime > lastSampleTime) //No overflow
{
@@ -134,38 +134,41 @@ void loop() {
lastSampleTime = sampleTime;
//Sending in text mode
- Serial.print(lastEncoderDisplacement);
- Serial.print(";");
- Serial.print(totalTime);
- Serial.print(";");
- Serial.println(totalForce / nReadings);
-
- procesSample = false;
+// Serial.print(lastEncoderDisplacement);
+// Serial.print(";");
+// Serial.print(totalTime);
+// Serial.print(";");
+// Serial.println(totalForce / nReadings);
+
+
+ //Sending in binary mode
+ //sendInt(lastEncoderDisplacement);
+ sendLong(totalTime);
+ //sendInt(offsettedData);
+ sendInt(514);
+
+ //End of the binari sample
+// Serial.write(0xff);
+// Serial.write(0xff);
+// Serial.write(0xff);
+// Serial.write(0xff);
- // //Sending in binary mode
- // sendInt(lastEncoderDisplacement);
- // sendInt(totalTime);
- // sendInt(offsettedData);
- //
- // //End of the binari sample
- // Serial.write(0xff);
- // Serial.write(0xff);
- // Serial.write(0xff);
- // Serial.write(0xff);
+
+ procesSample = false; //Keep acumulating pulses without processing the sample until [pps] samples
is reached
+ samplesSent++;
}
}
void changingA() {
- bool photocellB = digitalRead(encoderPinB);
changingTime = micros();
- if (photocellB == HIGH) {
+ if (digitalRead(encoderPinB) == HIGH) {
encoderDisplacement--;
- //digitalWrite(13, HIGH);
} else {
encoderDisplacement++;
- //digitalWrite(13, LOW);
}
+
+ //Checking if the number of pulses equals the pulses per sample (clockwise or couterclockwise)
if (abs(encoderDisplacement) >= pps) {
lastEncoderDisplacement = encoderDisplacement; //We need to save this value because it can change very
quickly
sampleTime = changingTime; //We need to save this value because it can change very
quickly
@@ -223,18 +226,25 @@ void serialEvent()
void start_capture()
{
- Serial.println("Starting capture...");
+ Serial.print("Starting capture;PPS:");
+ Serial.println(pps);
totalTime = 0;
lastSampleTime = micros();
sampleTime = lastSampleTime + 1;
//First sample with a low speed is mandatory to good detection of the start
- Serial.print(0);
- Serial.print(";");
- Serial.print(1);
- Serial.print(";");
- Serial.println(0);
+
+// Serial.print(0);
+// Serial.print(";");
+// Serial.print(1);
+// Serial.print(";");
+// Serial.println(0);
+
+ //sendInt(0);
+ sendLong(1);
+ sendInt(514); //Fake force. Fixed number for debugging
+
capturing = true;
encoderDisplacement = 0;
}
@@ -242,7 +252,13 @@ void start_capture()
void end_capture()
{
capturing = false;
- Serial.println("Capture ended");
+
+ //sendLong(4294967295);
+ //sendInt(32767);
+ Serial.print("\nCapture ended. Samples sent: ");
+ Serial.println(samplesSent);
+ Serial.print("TotalTime :");
+ Serial.println(totalTime);
}
void get_version()
@@ -421,6 +437,7 @@ void set_baud_rate(String inputString)
Serial.println(baudRate);
}
+//TODO: Write in binary mode
void start_simulation(void)
{
float vmax = 10.0;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]