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 0:a0e9db1628f1, committed 2020-11-16
- Comitter:
- yeongsookim
- Date:
- Mon Nov 16 22:37:13 2020 +0000
- Commit message:
- Init commit
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Sensor/LaneSensor.cpp Mon Nov 16 22:37:13 2020 +0000
@@ -0,0 +1,61 @@
+#include "LaneSensor.h"
+
+LaneSensor::LaneSensor(PinName lll,PinName ll,PinName l,PinName m,PinName r,PinName rr,PinName rrr)
+ : sensorsIn_(lll,ll,l,m,r,rr,rrr)
+{
+ error_=0.0;
+ prevError_=0.0;
+ //sensorsIn_.mode(PullNode);
+}
+float LaneSensor::getError()
+{
+ float errorSum=0;
+ int errorCount=0;
+ float errorConstant =22.86;
+
+ int sensorIn=sensorsIn_ & sensorsIn_.mask();
+ if((sensorIn&0x1)==0x0) {
+ errorSum+=errorConstant*3.0;
+ errorCount++;
+ }
+ if((sensorIn&0x2)==0x0) {
+ errorSum+=errorConstant*2.0;
+ errorCount++;
+ }
+ if((sensorIn&0x4)==0x0) {
+ errorSum+=errorConstant*0.7;
+ errorCount++;
+ }
+ if((sensorIn&0x8)==0x0) {
+ errorSum+=0.0;
+ errorCount++;
+ }
+ if((sensorIn&0x10)==0x0) {
+ errorSum+=errorConstant*-0.7;
+ errorCount++;
+ }
+ if((sensorIn&0x20)==0x0) {
+ errorSum+=errorConstant*-2.0;
+ errorCount++;
+ }
+ if((sensorIn&0x40)==0x0) {
+ errorSum+=errorConstant*-3.0;
+ errorCount++;
+ }
+
+
+ if(errorCount==0) {
+ error_=prevError_;
+ } else {
+ error_=errorSum/((float)errorCount);
+ }
+ prevError_=error_;
+
+ return error_;
+}
+
+int LaneSensor::getData()
+{
+
+ return sensorsIn_ & sensorsIn_.mask();;
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Sensor/LaneSensor.h Mon Nov 16 22:37:13 2020 +0000
@@ -0,0 +1,21 @@
+#ifndef MBED_LANESENSOR_H
+#define MBED_LANESENSOR_H
+
+#include "mbed.h"
+
+
+
+
+class LaneSensor
+{
+public:
+ LaneSensor(PinName lll,PinName ll,PinName l,PinName m,PinName r,PinName rr,PinName rrr);
+ float getError();
+ int getData();
+
+protected:
+ float error_,prevError_;
+ BusIn sensorsIn_;
+};
+
+#endif //MBED_DISTANCESENSOR_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Mon Nov 16 22:37:13 2020 +0000
@@ -0,0 +1,40 @@
+#include "mbed.h"
+#include "LaneSensor.h"
+
+//To plot with usb, set as below.
+Serial pc(USBTX,USBRX); // Tx, Rx Pin
+
+//Set each gpio to see the output of the hall sensor as a led
+LaneSensor laneSensor(p11,p12,p13,p14,p15,p16,p17);
+
+//Interrupt is generated every 1ms and count is increased by 1
+unsigned int uiFlag_1ms = 0;
+unsigned int uiFlag_50ms = 0;
+
+void counter_1ms ()
+{
+ uiFlag_1ms++;
+ uiFlag_50ms++;
+}
+
+int main()
+{
+ wait(1);
+
+ ////Set the 1ms thicker.
+ Ticker ticker_1ms;
+ ticker_1ms.attach(&counter_1ms, 0.001);
+
+
+ while(1)
+ {
+ // Every 50 ms,
+ if(uiFlag_50ms >= 50) {
+ uiFlag_50ms = 0;
+
+ int data = laneSensor.getData();
+ float error = laneSensor.getError();
+ pc.printf ("data: %d, error: %f \r\n", data, error);
+ }
+ }
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Nov 16 22:37:13 2020 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file