[chronojump] Signal Generator. Control from console
- From: Xavier Padullés <xpadulles src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] Signal Generator. Control from console
- Date: Tue, 24 Apr 2018 16:28:51 +0000 (UTC)
commit 060ac98fcd9932141d53a8b8a23073f9bb677443
Author: Xavier Padullés <x padulles gmail com>
Date: Mon Apr 23 14:06:41 2018 +0200
Signal Generator. Control from console
arduino/signalGenerator/signalGenerator.ino | 82 ++++++++++++++++++---------
r-scripts/sprintEncoder.R | 4 +-
2 files changed, 56 insertions(+), 30 deletions(-)
---
diff --git a/arduino/signalGenerator/signalGenerator.ino b/arduino/signalGenerator/signalGenerator.ino
index 6e2fdcd..2542f66 100644
--- a/arduino/signalGenerator/signalGenerator.ino
+++ b/arduino/signalGenerator/signalGenerator.ino
@@ -1,22 +1,22 @@
/*
-signalGenerator: Generates a digital signal following different sequences defined in sequences[]
-
- Copyright (C) 2018 Xavier de Blas xaviblas gmail com
- Copyright (C) 2018 Xavier Padullés support chronojump org
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
+ signalGenerator: Generates a digital signal following different sequences defined in sequences[]
+
+ Copyright (C) 2018 Xavier de Blas xaviblas gmail com
+ Copyright (C) 2018 Xavier Padullés support chronojump org
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
#define signalPin 2
#define ledPin 13
@@ -28,7 +28,8 @@ signalGenerator: Generates a digital signal following different sequences define
// 1 read sequence 1
// ...
//TODO: assign mode by serial port
-const int mode = -1;
+int mode = -1;
+bool generateSignal = false;
//this can be quite real data promoting a bit double contacts
const int randomTCMin = 4;
const int randomTCMax = 500;
@@ -36,10 +37,10 @@ const int randomTFMin = 40;
const int randomTFMax = 1200;
//first num is the last element position
-//2nd param is start mode
+//2nd param is start mode. IN = ON, OUT = OFF
//values are in milliseconds
const String sequences [] = {
- "7;IN;750;100;400;380;50;70",
+ "7;IN;30;25;15;1000;25;40;19;60;24;800,30",
"5;IN;100;1500;200;5000",
"6;OUT;1100;40;1200;30;8000"
};
@@ -48,17 +49,19 @@ const String sequences [] = {
void setup() {
pinMode(signalPin, OUTPUT);
Serial.begin(9600);
- if(mode == -1)
+ if (mode == -1)
{
randomSeed(analogRead(0));
}
}
- void loop() {
- //signalOn(500);
- //signalOff(100);
+void loop() {
+ //signalOn(500);
+ //signalOff(100);
- if(mode >= 0)
+ while (generateSignal)
+ {
+ if (mode >= 0)
{
processString(mode);
}
@@ -68,6 +71,7 @@ void setup() {
signalOff(random(randomTFMin, randomTFMax));
}
}
+}
void processString(int n)
{
@@ -85,7 +89,7 @@ void processString(int n)
signalOff(duration);
//invert status
- if(currentStatus == "IN")
+ if (currentStatus == "IN")
currentStatus = "OUT";
else
currentStatus = "IN";
@@ -97,7 +101,8 @@ String getValue(String data, char separator, int index)
{
int found = 0;
int strIndex[] = {
- 0, -1 };
+ 0, -1
+ };
int maxIndex = data.length() - 1;
for (int i = 0; i <= maxIndex && found <= index; i++) {
@@ -128,3 +133,24 @@ void signalOff(int duration) {
digitalWrite(ledPin, LOW);
delay(duration);
}
+
+void serialEvent()
+{
+ String inputString = Serial.readString();
+ inputString = inputString.substring(0, inputString.lastIndexOf(";"));
+ if (inputString == "start")
+ {
+ Serial.println("Starting signal");
+ generateSignal = true;
+ } else if (inputString == "stop")
+ {
+ generateSignal = false;
+ Serial.println("Stoping signal");
+ } else
+ {
+ Serial.println("mode = " + inputString);
+ mode = inputString.toInt();
+ }
+
+}
+
diff --git a/r-scripts/sprintEncoder.R b/r-scripts/sprintEncoder.R
index ce70298..69e474e 100644
--- a/r-scripts/sprintEncoder.R
+++ b/r-scripts/sprintEncoder.R
@@ -104,8 +104,8 @@ getSprintFromEncoder <- function(filename, testLength, Mass, Temperature = 25, H
}
plotSprintFromEncoder <- function(sprintRawDynamics, sprintFittedDynamics, title = "Test graph",
- plotRawSpeed = TRUE, plotRawAccel = TRUE, plotRawForce = FALSE,
plotRawPower = FALSE,
- plotFittedSpeed = TRUE, plotFittedAccel = FALSE, plotFittedForce = FALSE,
plotFittedPower = FALSE)
+ plotRawSpeed = TRUE, plotRawAccel = TRUE, plotRawForce = TRUE,
plotRawPower = FALSE,
+ plotFittedSpeed = TRUE, plotFittedAccel = FALSE, plotFittedForce = TRUE,
plotFittedPower = FALSE)
{
#Plotting position
# plot(sprintRawDynamics$time[sprintRawDynamics$startSample:sprintRawDynamics$endSample],
sprintRawDynamics$rawPosition[sprintRawDynamics$startSample:sprintRawDynamics$endSample],
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]