Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 2:4dd54b3934a5, committed 2015-08-06
- Comitter:
- ADAMSTRUTT
- Date:
- Thu Aug 06 14:49:27 2015 +0000
- Parent:
- 0:efdae9d24ee1
- Commit message:
- .;
Changed in this revision
--- a/Calculate.cpp Wed Jul 22 13:12:14 2015 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,74 +0,0 @@
-//#include "mbed.h"
-//#include <time.h>
-//#include <string>
-//#include <iostream>
-//#include "Distance.h"
-//
-//void printArray(double array[20], int timesArray[20], int NoOfPins);
-//void data(int sensor_number, int time, double speed);
-//
-// //mbed pins
-//extern Serial pc;
-//DigitalIn sensor[20] = {p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,p16,p17,p18,p19,p20,p21,p22,p23,p24};//array of sensors.
-//
-//
-////c++ variables
-//time_t sensor_time ; //time at which sensor is broken
-//int timeDiff; //time between 2 sensors
-//float speed;
-//int times[20]; //array the size of #pins
-//double speeds[20]; //array of speeds
-//
-//
-////Speed Calculations
-//int calculate(double distance, int noOfPins)
-//{
-//
-// pc.printf("new program \n"); //alert user of initialisation
-//
-// int i = 0, i1 = 0;
-//
-// while( i < noOfPins)
-// {
-// while(!sensor[i])
-// {
-// if(sensor[i + 1]) { //checks if there is an error in the first sensor
-// sensor_time = time(NULL);
-// pc.printf ("Error with sensor: %d", i);
-// i++;
-// }
-// if(sensor[i + 2]) { //checks if there is an error in the second sensor after
-// sensor_time = time(NULL);
-// pc.printf ("Error with sensors: %d, %d", i,i1 = i + 1);
-// i = i + 2;
-// }
-// }
-// sensor_time = time(NULL); //gets current time
-// pc.printf("\n sensor %d : %d \t", i, sensor_time);
-// times[i] = sensor_time; //adds sensor times to array for logging.
-// if ( i > 0) { //to ensure it is not the first one
-// timeDiff = difftime(times[i], times[i-1]); //calculates the time difference
-// pc.printf(" timediff: %d s \t", timeDiff);
-// speed = distance / timeDiff;
-// pc.printf(" speed : %f m/s ", speed);
-// speeds[i] = speed;
-// }
-// i++;
-// }
-// pc.printf(" \n Calculate completed \n"); //alert to let user know it completed
-// printArray(speeds, times, noOfPins);
-//
-//}
-//
-//void printArray(double array[23], int timesArray[23], int noOfPins)
-// {
-// for (int i = 0; i < noOfPins ; i++) //printing module for array
-// {
-// pc.printf(" Sensor : %d Time %d Speed %f \n", i, times[i], speeds[i]);// pc.printf(" %d : %d \t", i,times[i]);
-// }
-// for (int i = 0; i < noOfPins ; i++) //printing to Datalog
-// {
-// data( i,times[i],speeds[i]);
-// }
-//
-// }
--- a/Calculate.h Wed Jul 22 13:12:14 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,7 +0,0 @@ -//#ifndef CALCULATE_H -//#define CALCULATE_H -// -//int calculate(double distance, int noOfPins); -//void printArray(double array[3], int timesArray[3],int noOfPins); -// -////#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Data.cpp Thu Aug 06 14:49:27 2015 +0000
@@ -0,0 +1,29 @@
+#include "Data.h"
+#include "UserInput.h"
+#include "mbed.h"
+#include <string>
+
+extern LocalFileSystem local;
+UserInput userInput;
+
+//sets up the excel file inputing the
+void Data::initialise()
+{
+ FILE *fdata = fopen("/local/Datalog.xls", "w");
+ fprintf(fdata, "Company\t%sPipename\t%s", userInput.company(), userInput.pipeName());
+ fclose (fdata);
+}
+
+void Data::counter(int count)
+{
+ FILE *f1data = fopen("/local/Datalog.xls", "a");
+ fprintf(f1data, "Round %d of bending\nSensor number\tTime\tSpeed\n", count);
+ fclose(f1data);
+}
+
+void Data::logSpeed(int *sensor_number, float *time, float *speed)
+{
+ FILE *f2data = fopen("/local/Datalog.xls", "a");
+ fprintf(f2data, "%d\t %f\t %f \n", *sensor_number, *time, *speed);
+ fclose(f2data);
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Data.h Thu Aug 06 14:49:27 2015 +0000
@@ -0,0 +1,17 @@
+#ifndef DATA_H
+#define DATA_H
+
+#include "UserInput.h"
+#include "mbed.h"
+#include <string>
+
+extern LocalFileSystem local;
+
+class Data{
+ public:
+ void initialise();
+ void counter(int count);
+ void logSpeed(int *sensor_number, float *time, float *speed);
+//void averageData();
+};
+#endif
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/SpeedCalculate.cpp Thu Aug 06 14:49:27 2015 +0000
@@ -0,0 +1,58 @@
+#include "SpeedCalculate.h"
+#include "mbed.h"
+#include "Data.h"
+#include <time.h>
+#include <string>
+
+
+extern Serial pc;
+
+//c++ variables
+Timer t; //time at which sensor is broken
+float timeDiff; //time between 2 sensors
+float speed; //array of speeds
+
+
+//Speed Calculations
+//it takes the distance and number of sensor and gives the speed (m/s)
+void SpeedCalculate::calculate(float distance, int noOfSensors)
+{
+ Data data;
+
+ int count = 0;
+
+ //array of sensors
+ DigitalIn sensor[18] = {p5, p6, p7, p8, p11, p12, p13, p14, p15, p16, p17, p18, p19, p20, p21, p22, p23, p24};
+
+ while(true){
+ int i=0;
+ t.start();
+ data.counter(count);
+ while( i < noOfSensors) //loops round until all the sensors have been used
+ {
+ if (i == 0){
+ data.logSpeed(0,0,0);
+ }
+ while(!sensor[i])
+ {
+ if(sensor[i + 1]) { //checks if there is an error in the first sensor
+ i++;
+ }
+ if(sensor[i + 2]) { //checks if there is an error in the second sensor after
+ i = i + 2;
+ }
+ }
+ timeDiff = t.read(); //gets current time
+ t.reset();
+ pc.printf("%f\n%f\n", i, timeDiff);
+ if ( i > 0) { //to ensure it is not the first one
+ speed = 60*(distance / timeDiff);
+ pc.printf("%f\n", speed);
+ data.logSpeed(&i, &timeDiff, &speed); //logs data
+ }
+ i++;
+ }
+ t.stop();
+ count++;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/SpeedCalculate.h Thu Aug 06 14:49:27 2015 +0000
@@ -0,0 +1,14 @@
+#ifndef CALCULATE_H
+#define CALCULATE_H
+
+#include "mbed.h"
+
+extern Serial pc;
+
+class SpeedCalculate{
+ public:
+ void calculate(float distance, int noOfSensors);
+//void printArray(double array[3], int timesArray[3],int noOfPins);
+};
+
+#endif
\ No newline at end of file
--- a/UserInput.cpp Wed Jul 22 13:12:14 2015 +0000
+++ b/UserInput.cpp Thu Aug 06 14:49:27 2015 +0000
@@ -1,83 +1,136 @@
+#include "UserInput.h"
#include "mbed.h"
#include "stdio.h"
+#include <stdlib.h>
#include <string>
+
extern Serial pc;
-extern Serial mbed2;
-
-LocalFileSystem local("local");
-
-char company [100], pipe [100];
-//noOfSensor: is the number of sensors of the former
-//distance: is the distance between the sensors in 'mm'
-//S: straiting
-//B: bending
-int noOfSensorS, distanceS, noOfSensorB;
+extern LocalFileSystem local;
-void inputNoOfPins(){
- FILE *pFile = fopen ("/local/details.txt" , "r");
- if (pFile == NULL){
+//this class pulls variables that the user has inputed
+
+//Companys name
+//there name is on the 1st line of details.txt
+//it returns an string
+string UserInput::company(){
+
+ char Company[100];
+
+ FILE *p1UI = fopen ("/local/details.txt" , "r");
+ if (p1UI == NULL){
pc.printf("Error opening file");
}else {
- if ( fgets (company, 100 , pFile) != NULL ){
- pc.printf ("%s\n", company);
- }
- if ( fgets (pipe, 100 , pFile) != NULL ){
- pc.printf ("%s\n", pipe);
- fclose (pFile);
- }
+ fgets (Company, 100 , p1UI);
+ fclose (p1UI);
}
+ return Company;
}
-int UI_NumberOfSensorsB(){
+
+//the name of the companys pipe
+//the name is on the 2rd line of details.txt
+//it returns string
+string UserInput::pipeName(){
- FILE *p1File = fopen ("/local/details.txt" , "r");
- if (p1File == NULL){
+ char PipeName[100];
+
+ FILE *p2UI = fopen ("/local/details.txt" , "r");
+ if (p2UI == NULL){
pc.printf("Error opening file");
}else {
- pc.printf ("%d\n", noOfSensorB = fgetc (p1File));
- fclose (p1File);
+ for(int i = 0; i < 2; i++){
+ fgets (PipeName, 100 , p2UI);
+ }
+ fclose (p2UI);
}
+ return PipeName;
}
-int UI_DistanceB(){
-
- int distanceB;
+//number of sensors for bending
+//the value for the number of sensors is on the 3rd line of details.txt
+//it returns int
+int UserInput::numberOfSensorsB(){
- pc.printf("UI_DistanceB");
- FILE *p2File = fopen ("/local/details.txt" , "r");
- if (p2File == NULL){
+ char NoOfSensorB_S[100];
+ int NoOfSensorB;
+
+ FILE *p3UI = fopen ("/local/details.txt" , "r");
+ if (p3UI == NULL){
pc.printf("Error opening file");
}else {
for(int i = 0; i < 3; i++){
- pc.printf("inside");
- distanceB = atoi (fgets (p2File).c_str());
+ fgets (NoOfSensorB_S, 100 , p3UI);
+ NoOfSensorB = atoi(NoOfSensorB_S);
}
- distanceB = atoi (fgets (p2File));
- pc.printf ("%i\n", distanceB);
- fclose (p2File);
+ fclose (p3UI);
}
+ return NoOfSensorB;
+}
+
+
+//distance between sensors for bending
+//the value for the distance is on the 4th line of details.txt
+//it returns the value at a floating point number
+float UserInput::distanceB(){
+
+ char DistanceB_S[100];
+ double DistanceB;
+
+ FILE *p4UI = fopen ("/local/details.txt" , "r");
+ if (p4UI == NULL){
+ pc.printf("Error openingfile");
+ }else {
+ for(int i = 0; i < 4; i++){
+ fgets (DistanceB_S, 100 , p4UI);
+ DistanceB = atof(DistanceB_S);
+ }
+ fclose (p4UI);
+ }
+ return DistanceB;
}
-int UI_NumberOfSensorsS(){
+
+//number of sensors for straiting
+//the value for the number of sensors is on the 5th line of details.txt
+//it returns the int
+int UserInput::numberOfSensorsS(){
- FILE *p3File = fopen ("/local/details.txt" , "r");
- if (p3File == NULL){
+ char NoOfSensorS_S[100];
+ int NoOfSensorS;
+
+ FILE *p5UI = fopen ("/local/details.txt" , "r");
+ if (p5UI == NULL){
pc.printf("Error opening file");
}else {
- pc.printf ("%d\n", noOfSensorB = fgetc (p3File));
- fclose (p3File);
+ for(int i = 0; i < 5; i++){
+ fgets (NoOfSensorS_S, 100 , p5UI);
+ NoOfSensorS = atoi(NoOfSensorS_S);
+ }
+ fclose (p5UI);
}
+ return NoOfSensorS;
}
+
-int UI_DistanceS(){
+//distance between sensors for straiting
+//the valuse for the distance in on the 6th line of details.txt
+//it returns the value at a floating point number
+float UserInput::distanceS(){
- FILE *p4File = fopen ("/local/details.txt" , "r");
- if (p4File == NULL){
+ char DistanceS_S[100];
+ double DistanceS;
+
+ FILE *p6UI = fopen ("/local/details.txt" , "r");
+ if (p6UI == NULL){
pc.printf("Error opening file");
}else {
- pc.printf ("%d\n", distanceS= fgetc (p4File));
- fclose (p4File);
+ for(int i = 0; i < 6; i++){
+ fgets (DistanceS_S, 100 , p6UI);
+ DistanceS = atof(DistanceS_S);
+ }
+ fclose (p6UI);
}
+ return DistanceS;
}
\ No newline at end of file
--- a/UserInput.h Wed Jul 22 13:12:14 2015 +0000
+++ b/UserInput.h Thu Aug 06 14:49:27 2015 +0000
@@ -1,11 +1,20 @@
-#ifndef USERINPUT.H
-#define USERINPUT.H
+#ifndef USERINPUT_H
+#define USERINPUT_H
+#include "mbed.h"
+#include <string>
+
+extern Serial pc;
+extern LocalFileSystem local;
-void inputNoOfPins();
-int UI_NumberOfSensorsB();
-int UI_DistanceB();
-int UI_NumberOfSensorsS();
-int UI_DistanceS();
+class UserInput{
+ public:
+ string company();
+ string pipeName();
+ int numberOfSensorsB();
+ float distanceB();
+ int numberOfSensorsS();
+ float distanceS();
+};
#endif
\ No newline at end of file
--- a/main.cpp Wed Jul 22 13:12:14 2015 +0000
+++ b/main.cpp Thu Aug 06 14:49:27 2015 +0000
@@ -1,13 +1,56 @@
#include "mbed.h"
-//#include "Calculate.h"
-//#include "Distance.h"
-//#include "Data.h"
+#include <string.h>
+#include "rtos.h"
+#include "SpeedCalculate.h"
+#include "Data.h"
#include "UserInput.h"
-//#include "Counter.h
+
+LocalFileSystem local("local");
+
+Serial pc(USBTX, USBRX); //conection to PC
+Serial mbed2(p9,p10); //conection to mbed2
+DigitalOut led_indactor(LED1);
+
+Data data;
+
+void speed_thread(void const *args)
+{
+ SpeedCalculate speed;
+
+ speed.calculate(1,4);
+}
-Serial pc(USBTX, USBRX); // tx, rx
-Serial mbed2(p9,p10); //tx, rx
+void handShake()
+{
+ unsigned char input;
+ pc.printf("a\n");
+
+ while(true)
+ {
+ input = pc.getc();
+ if (input == 'a')
+ {
+ led_indactor = 1;
+ break;
+ }
+ }
+}
-int main(){
- UI_DistanceB();
-}
\ No newline at end of file
+int main()
+{
+ int number = 2;
+ //handShake();
+// data.initialise();
+// while(!(pc.readable() && pc.getc() == 'b')){
+// //run
+// }
+// Thread sThread(speed_thread);
+// while(!(pc.readable() && pc.getc() == 's')){
+// //run
+// }
+// sThread.terminate();
+ mbed2.printf("%d", number);
+ while(!mbed2.readable()){}
+ mbed2.scanf("%d", &number);
+ pc.printf("%d", number);
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Thu Aug 06 14:49:27 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed-rtos/#5aed8bae1001
--- a/mbed.bld Wed Jul 22 13:12:14 2015 +0000 +++ b/mbed.bld Thu Aug 06 14:49:27 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/cbbeb26dbd92 \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/bad568076d81 \ No newline at end of file