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.
Dependencies: mbed
MurphyBat.cpp
00001 /* 00002 * MurphyBat.cpp 00003 * 00004 * Created on: 5 Aug 2017 00005 * Author: ciscer01 00006 */ 00007 00008 #include <MurphyBat.hpp> 00009 #include <mbed.h> 00010 00011 MurphyBat::MurphyBat(PinName Ir1, PinName Ir2, PinName Ir3, PinName Ir4, PinName Actuator): 00012 mIr1(Ir1), 00013 mIr2(Ir2), 00014 mIr3(Ir3), 00015 mIr4(Ir4), 00016 BatI(0), 00017 batActuator(Actuator), 00018 batActuratorTimout(), 00019 Fired(false) { 00020 00021 BatIrIn[0] = &mIr1; 00022 BatIrIn[1] = &mIr2; 00023 BatIrIn[2] = &mIr3; 00024 BatIrIn[3] = &mIr4; 00025 //BatIrTh[0] = 0.5; 0.5, 0.5, 0.5), 00026 for (unsigned int i = 0; i < 4; i++){ 00027 for (unsigned int j = 0; j < avg_size; j++) { 00028 BatIrVal[i][j] = 0; 00029 } 00030 00031 } 00032 BatIrTh[0] = 0.4f - 0.05f; 00033 BatIrTh[1] = 0.3f - 0.05f; 00034 BatIrTh[2] = 0.4f - 0.05f; 00035 BatIrTh[3] = 0.3f - 0.05f; 00036 batActuator.write(0); 00037 } 00038 00039 void MurphyBat::update() { 00040 bool fire = false; 00041 float BatIrAvg[4]; 00042 for (unsigned int i = 0; (i < 4) && (fire == false); i++) { 00043 //Read the Ir value 00044 BatIrVal[i][BatI] = BatIrIn[i]->read(); 00045 //start the avarage computation 00046 BatIrAvg[i] = BatIrVal[i][0]; 00047 for (unsigned int j = 1; j < avg_size; j++) { 00048 BatIrAvg[i] += BatIrVal[i][j]; 00049 } 00050 //Compute avarage 00051 BatIrAvg[i] = BatIrAvg[i] / avg_size; 00052 if (BatIrVal[i][BatI] > BatIrTh[i]) { 00053 fire = true; 00054 } 00055 } 00056 BatI = (BatI + 1) % avg_size; 00057 if (fire) { 00058 Fire(); 00059 } 00060 } 00061 00062 void MurphyBat::FireCb(MurphyBat *mb){ 00063 mb->Fire(); 00064 } 00065 00066 void MurphyBat::Fire(void) { 00067 if (Fired == false) { 00068 Fired = true; 00069 batActuator.write(1); 00070 batActuratorTimout.attach_us(this,MurphyBat::FireCb, 200000); 00071 } else { 00072 Fired = false; 00073 batActuator.write(0); 00074 batActuratorTimout.detach(); 00075 } 00076 }
Generated on Thu Jul 14 2022 01:42:13 by
1.7.2