111

Dependencies:   BufferedSerial FastPWM mbed

Files at this revision

API Documentation at this revision

Comitter:
sbh9428
Date:
Tue Apr 12 06:52:10 2016 +0000
Commit message:
11

Changed in this revision

BufferedSerial.lib Show annotated file Show diff for this revision Revisions of this file
FastPWM.lib Show annotated file Show diff for this revision Revisions of this file
commandt.cpp Show annotated file Show diff for this revision Revisions of this file
commandt.h Show annotated file Show diff for this revision Revisions of this file
controlt.cpp Show annotated file Show diff for this revision Revisions of this file
controlt.h Show annotated file Show diff for this revision Revisions of this file
humsensort.cpp Show annotated file Show diff for this revision Revisions of this file
humsensort.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
pumpt.cpp Show annotated file Show diff for this revision Revisions of this file
pumpt.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/BufferedSerial.lib	Tue Apr 12 06:52:10 2016 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/sam_grove/code/BufferedSerial/#a0d37088b405
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/FastPWM.lib	Tue Apr 12 06:52:10 2016 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/Sissors/code/FastPWM/#87e38b846651
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/commandt.cpp	Tue Apr 12 06:52:10 2016 +0000
@@ -0,0 +1,146 @@
+/*
+ * commandt.cpp
+ *
+ *  Created on: 2016. 2. 19.
+ *      Author: sbh9428
+ */
+
+#include "commandt.h"
+
+command_t::command_t() {
+	// TODO Auto-generated constructor stub
+
+}
+
+command_t::command_t(BufferedSerial* _pc, control_t* _control)
+{
+	time=0;
+	count=0;
+	control=_control;
+	pc=_pc;	
+}
+
+command_t::~command_t() {
+	// TODO Auto-generated destructor stub
+}
+
+void command_t::clear_data()
+{
+	for(int i=0;i<10;i++)
+	{
+		data[i]=0;	
+	}	
+}
+void command_t::parse()
+{
+	switch(data[0])
+	{
+		case 's':
+			switch(data[1])
+			{
+				case 'm':
+					control->setMode(data[2]-'0');
+					printf("set mode %d\n", data[2]-'0');
+				break;
+				case 'p':
+					control->setP(asci_to_bin(data+2));
+					printf("set P %f1.5\n", asci_to_bin(data+2));
+				break;
+				case 'i':
+					control->setI(asci_to_bin(data+2));
+					printf("set I %f\n", asci_to_bin(data+2));
+				break;	
+				case 'd':
+					control->setD(asci_to_bin(data+2));
+					printf("set D %f\n", asci_to_bin(data+2));
+				break;	
+				case 'o':
+					control->setPower(asci_to_bin(data+2));
+					printf("set I value %f\n", asci_to_bin(data+2));
+				break;	
+				case 'a':
+					control->setRatio(asci_to_bin(data+2));
+					printf("set Ratio %f\n", asci_to_bin(data+2));
+				break;	
+			}
+		break;
+		case 'g':
+			switch(data[1])
+			{
+				case 'm':
+					printf("mode is %d\n", control->getMode());
+				break;
+				case 'p':
+					printf("P is %f\n", control->getP());
+				break;
+				case 'i':
+					printf("I is %f\n", control->getI());
+				break;
+				case 'd':	
+					printf("D is %f\n", control->getD());
+				break;
+				case 'o':
+					printf("power is %f\n", control->getPower());
+				break;
+				case 'a':
+					printf("ratio is %f\n", control->getRatio());
+				break;
+			}
+		
+		break;	
+		dafault:
+		pc->printf("command error");
+	}
+	pc->printf("\n");
+	count=0;
+}
+
+void command_t::get_data()
+{
+    data [count]=pc->getc();
+
+    if(data [count]=='f')
+	parse();
+	else
+    count++;
+
+    if(count>9)
+    {
+        count=0;
+         pc->printf("command error\n");
+     }
+}
+
+double command_t::asci_to_bin(int *start)
+{
+	double _data=0;
+	int current=0;
+
+	double nth=1; //�ڸ���
+	int mode=0;
+	int sign=1;
+	
+	if(*start=='-')
+	{
+		current++;	
+		sign=-1;
+	}
+	while(*(start+current)!='f'&&*(start+current)!='.')
+	{
+		_data*=10;
+		_data+=*(start+current)-'0';
+
+		current++;
+	}
+	if(*(start+current)=='.')
+	{
+		current++;
+		while(*(start+current)!='f')
+		{
+			nth/=10;
+			_data+=nth*(*(start+current)-'0');
+			current++;
+		}	
+	}
+	return sign*_data;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/commandt.h	Tue Apr 12 06:52:10 2016 +0000
@@ -0,0 +1,36 @@
+/*
+ * commandt.h
+ *
+ *  Created on: 2016. 2. 19.
+ *      Author: sbh9428
+ */
+
+#ifndef COMMANDT_H_
+#define COMMANDT_H_
+
+#include "BufferedSerial.h"
+#include "controlt.h"
+
+class command_t {
+public:
+	void clear_data();
+	void parse();
+	void get_data();
+	double asci_to_bin(int *start);
+
+	command_t();
+	command_t(BufferedSerial* _pc, control_t* _control);
+	virtual ~command_t();
+private:
+	int count;
+	int data[30];
+	int time;
+
+	BufferedSerial *pc;
+	control_t *control;
+};
+
+
+#endif /* COMMANDT_H_ */
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/controlt.cpp	Tue Apr 12 06:52:10 2016 +0000
@@ -0,0 +1,108 @@
+/*
+ * controlt.cpp
+ *
+ *  Created on: 2016. 2. 19.
+ *      Author: sbh9428
+ */
+
+#include "controlt.h"
+
+control_t::control_t() {
+	// TODO Auto-generated constructor stub
+
+}
+
+control_t::control_t(pump_t *_dry, pump_t *_wet, humSensor_t *humSensor, BufferedSerial *_pc)
+{
+	dry=_dry;
+	wet=_wet;
+	
+	pc=_pc;
+	
+	mode=0;
+}
+
+control_t::~control_t() {
+	// TODO Auto-generated destructor stub
+}
+
+void control_t::setP(float _P)
+{
+	P=_P;
+}
+
+void control_t::setI(float _I)
+{
+	I=_I;
+}
+
+void control_t::setD(float _D)
+{
+	D=_D;
+}
+
+void control_t::setMode(int _mode)
+{
+	mode=_mode;
+}
+
+void control_t::setPower(float _power)
+{
+	power=_power;
+}
+
+void control_t::setRatio(float _ratio)
+{
+	ratio=_ratio;
+}
+
+float control_t::getP()
+{
+	return P;
+}
+
+float control_t::getI()
+{
+	return I;
+}
+
+float control_t::getD()
+{
+	return D;
+}
+
+int control_t::getMode()
+{
+	return D;
+}
+
+float control_t::getPower()
+{
+	return power;
+}
+float control_t::getRatio()
+{
+	return ratio;
+}
+
+void control_t::refreshPWM()
+{
+	humidity=humSensor->getHumidity();
+	switch(mode)
+	{
+	case 0:
+		dry->setPWM(0);
+		wet->setPWM(0);
+		break;
+	case 1:
+		dryValue=power*(1-ratio);
+		wetValue=power*ratio;
+		dry->setPWM(dryValue);
+		wet->setPWM(wetValue);
+		break;
+
+
+	}
+	printf("%d %1.3f %1.3f\n", mode, dryValue, wetValue);
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/controlt.h	Tue Apr 12 06:52:10 2016 +0000
@@ -0,0 +1,70 @@
+/*
+ * controlt.h
+ *
+ *  Created on: 2016. 2. 19.
+ *      Author: sbh9428
+ */
+
+#ifndef CONTROLT_H_
+#define CONTROLT_H_
+
+#include "BufferedSerial.h"
+#include "humsensort.h"
+#include "pumpt.h"
+
+class control_t {
+public:
+	void setP(float _P);
+	void setI(float _I);
+	void setD(float _D);
+
+	void setMode(int _mode);
+
+	void setPower(float _power);
+	void setRatio(float _ratio);
+
+	float getP();
+	float getI();
+	float getD();
+
+	int getMode();
+
+	float getPower();
+	float getRatio();
+
+	void refreshPWM();
+
+	float calculatePID();
+
+	control_t();
+	control_t(pump_t *_dry, pump_t *_wet, humSensor_t *_humSensor, BufferedSerial *_pc);
+	virtual ~control_t();
+private:
+	float P;
+	float I;
+	float D;
+
+	int mode;
+
+	float power;
+	float ratio;
+
+	float humidity;
+	
+	float dryValue;
+	float wetValue;
+
+	humSensor_t *humSensor;
+
+	pump_t *dry;
+	pump_t *wet;
+	
+	Ticker refresh;
+	
+	BufferedSerial *pc;
+};
+
+#endif /* CONTROLT_H_ */
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/humsensort.cpp	Tue Apr 12 06:52:10 2016 +0000
@@ -0,0 +1,28 @@
+/*
+ * tempsensott.cpp
+ *
+ *  Created on: 2016. 2. 19.
+ *      Author: sbh9428
+ */
+
+#include "humsensort.h"
+
+humSensor_t::humSensor_t() {
+	// TODO Auto-generated constructor stub
+
+}
+
+humSensor_t::humSensor_t(AnalogIn* _humiditySensor)
+{
+	humiditySensor=_humiditySensor;
+}
+
+
+humSensor_t::~humSensor_t() {
+	// TODO Auto-generated destructor stub
+}
+
+float humSensor_t::getHumidity()
+{
+	return (double)humiditySensor->read_u16()/1024/64*100;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/humsensort.h	Tue Apr 12 06:52:10 2016 +0000
@@ -0,0 +1,23 @@
+/*
+ * tempsensott.h
+ *
+ *  Created on: 2016. 2. 19.
+ *      Author: sbh9428
+ */
+
+#ifndef TEMPSENSORT_H_
+#define TEMPSENSORT_H_
+
+#include "mbed.h"
+class humSensor_t {
+public:
+	float getHumidity();
+
+	humSensor_t();
+	humSensor_t(AnalogIn* _Humidityensor);
+	virtual ~humSensor_t();
+private:
+	AnalogIn* humiditySensor;
+};
+
+#endif /* TEMPSENSOTT_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Apr 12 06:52:10 2016 +0000
@@ -0,0 +1,45 @@
+#include "mbed.h"
+#include "humsensort.h"
+#include "FastPWM.h"
+#include "controlt.h"
+#include "commandt.h"
+#include "pumpt.h"
+
+BufferedSerial pc(USBTX, USBRX, 2048);
+
+AnalogIn humidityPin(p20);
+
+humSensor_t humSensor(&humidityPin);
+
+FastPWM wetPin(p21);
+FastPWM dryPin(p22);
+
+pump_t wetPump(&wetPin);
+pump_t dryPump(&dryPin);
+
+Ticker sysTick;
+
+control_t control(&dryPump, &wetPump, &humSensor, &pc);
+
+command_t command(&pc, &control);
+
+void refreshPWM();
+
+int main()
+{
+    sysTick.attach(&refreshPWM, 5); 
+    while(1)
+    {
+ 
+        while(pc.readable())
+        {
+            command.get_data();
+
+        }
+    }
+}
+
+void refreshPWM()
+{
+    control.refreshPWM();   
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Apr 12 06:52:10 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/99a22ba036c9
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pumpt.cpp	Tue Apr 12 06:52:10 2016 +0000
@@ -0,0 +1,29 @@
+/*
+ * pumpt.cpp
+ *
+ *  Created on: 2016. 4. 11.
+ *      Author: right
+ */
+
+#include "pumpt.h"
+
+pump_t::pump_t() {
+	// TODO Auto-generated constructor stub
+
+}
+
+pump_t::pump_t(FastPWM *_out)
+{
+	out=_out;
+	out->period_ms(1);
+}
+
+pump_t::~pump_t() {
+	// TODO Auto-generated destructor stub
+}
+
+void pump_t::setPWM(float PWMvalue)
+{
+	out->pulsewidth_us(1000*PWMvalue);
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pumpt.h	Tue Apr 12 06:52:10 2016 +0000
@@ -0,0 +1,25 @@
+/*
+ * pumpt.h
+ *
+ *  Created on: 2016. 4. 11.
+ *      Author: right
+ */
+
+#ifndef PUMPT_H_
+#define PUMPT_H_
+
+#include "FastPWM.h"
+
+class pump_t {
+public:
+	void setPWM(float PWMvlaue);
+
+	pump_t();
+	pump_t(FastPWM *_out);
+	virtual ~pump_t();
+private:
+	FastPWM *out;
+};
+
+#endif /* PUMPT_H_ */
+