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.
Sensor/LaneSensor.cpp@0:a0e9db1628f1, 2020-11-16 (annotated)
- Committer:
- yeongsookim
- Date:
- Mon Nov 16 22:37:13 2020 +0000
- Revision:
- 0:a0e9db1628f1
Init commit
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| yeongsookim | 0:a0e9db1628f1 | 1 | #include "LaneSensor.h" |
| yeongsookim | 0:a0e9db1628f1 | 2 | |
| yeongsookim | 0:a0e9db1628f1 | 3 | LaneSensor::LaneSensor(PinName lll,PinName ll,PinName l,PinName m,PinName r,PinName rr,PinName rrr) |
| yeongsookim | 0:a0e9db1628f1 | 4 | : sensorsIn_(lll,ll,l,m,r,rr,rrr) |
| yeongsookim | 0:a0e9db1628f1 | 5 | { |
| yeongsookim | 0:a0e9db1628f1 | 6 | error_=0.0; |
| yeongsookim | 0:a0e9db1628f1 | 7 | prevError_=0.0; |
| yeongsookim | 0:a0e9db1628f1 | 8 | //sensorsIn_.mode(PullNode); |
| yeongsookim | 0:a0e9db1628f1 | 9 | } |
| yeongsookim | 0:a0e9db1628f1 | 10 | float LaneSensor::getError() |
| yeongsookim | 0:a0e9db1628f1 | 11 | { |
| yeongsookim | 0:a0e9db1628f1 | 12 | float errorSum=0; |
| yeongsookim | 0:a0e9db1628f1 | 13 | int errorCount=0; |
| yeongsookim | 0:a0e9db1628f1 | 14 | float errorConstant =22.86; |
| yeongsookim | 0:a0e9db1628f1 | 15 | |
| yeongsookim | 0:a0e9db1628f1 | 16 | int sensorIn=sensorsIn_ & sensorsIn_.mask(); |
| yeongsookim | 0:a0e9db1628f1 | 17 | if((sensorIn&0x1)==0x0) { |
| yeongsookim | 0:a0e9db1628f1 | 18 | errorSum+=errorConstant*3.0; |
| yeongsookim | 0:a0e9db1628f1 | 19 | errorCount++; |
| yeongsookim | 0:a0e9db1628f1 | 20 | } |
| yeongsookim | 0:a0e9db1628f1 | 21 | if((sensorIn&0x2)==0x0) { |
| yeongsookim | 0:a0e9db1628f1 | 22 | errorSum+=errorConstant*2.0; |
| yeongsookim | 0:a0e9db1628f1 | 23 | errorCount++; |
| yeongsookim | 0:a0e9db1628f1 | 24 | } |
| yeongsookim | 0:a0e9db1628f1 | 25 | if((sensorIn&0x4)==0x0) { |
| yeongsookim | 0:a0e9db1628f1 | 26 | errorSum+=errorConstant*0.7; |
| yeongsookim | 0:a0e9db1628f1 | 27 | errorCount++; |
| yeongsookim | 0:a0e9db1628f1 | 28 | } |
| yeongsookim | 0:a0e9db1628f1 | 29 | if((sensorIn&0x8)==0x0) { |
| yeongsookim | 0:a0e9db1628f1 | 30 | errorSum+=0.0; |
| yeongsookim | 0:a0e9db1628f1 | 31 | errorCount++; |
| yeongsookim | 0:a0e9db1628f1 | 32 | } |
| yeongsookim | 0:a0e9db1628f1 | 33 | if((sensorIn&0x10)==0x0) { |
| yeongsookim | 0:a0e9db1628f1 | 34 | errorSum+=errorConstant*-0.7; |
| yeongsookim | 0:a0e9db1628f1 | 35 | errorCount++; |
| yeongsookim | 0:a0e9db1628f1 | 36 | } |
| yeongsookim | 0:a0e9db1628f1 | 37 | if((sensorIn&0x20)==0x0) { |
| yeongsookim | 0:a0e9db1628f1 | 38 | errorSum+=errorConstant*-2.0; |
| yeongsookim | 0:a0e9db1628f1 | 39 | errorCount++; |
| yeongsookim | 0:a0e9db1628f1 | 40 | } |
| yeongsookim | 0:a0e9db1628f1 | 41 | if((sensorIn&0x40)==0x0) { |
| yeongsookim | 0:a0e9db1628f1 | 42 | errorSum+=errorConstant*-3.0; |
| yeongsookim | 0:a0e9db1628f1 | 43 | errorCount++; |
| yeongsookim | 0:a0e9db1628f1 | 44 | } |
| yeongsookim | 0:a0e9db1628f1 | 45 | |
| yeongsookim | 0:a0e9db1628f1 | 46 | |
| yeongsookim | 0:a0e9db1628f1 | 47 | if(errorCount==0) { |
| yeongsookim | 0:a0e9db1628f1 | 48 | error_=prevError_; |
| yeongsookim | 0:a0e9db1628f1 | 49 | } else { |
| yeongsookim | 0:a0e9db1628f1 | 50 | error_=errorSum/((float)errorCount); |
| yeongsookim | 0:a0e9db1628f1 | 51 | } |
| yeongsookim | 0:a0e9db1628f1 | 52 | prevError_=error_; |
| yeongsookim | 0:a0e9db1628f1 | 53 | |
| yeongsookim | 0:a0e9db1628f1 | 54 | return error_; |
| yeongsookim | 0:a0e9db1628f1 | 55 | } |
| yeongsookim | 0:a0e9db1628f1 | 56 | |
| yeongsookim | 0:a0e9db1628f1 | 57 | int LaneSensor::getData() |
| yeongsookim | 0:a0e9db1628f1 | 58 | { |
| yeongsookim | 0:a0e9db1628f1 | 59 | |
| yeongsookim | 0:a0e9db1628f1 | 60 | return sensorsIn_ & sensorsIn_.mask();; |
| yeongsookim | 0:a0e9db1628f1 | 61 | } |