pixy

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
halusis
Date:
Thu Oct 25 03:57:08 2018 +0000
Commit message:
for pixy

Changed in this revision

Gimbal_PixyTest.cpp Show annotated file Show diff for this revision Revisions of this file
GlobalVariables/GlobalVariables.cpp Show annotated file Show diff for this revision Revisions of this file
GlobalVariables/GlobalVariables.h Show annotated file Show diff for this revision Revisions of this file
PinAssign/PinAssign.cpp Show annotated file Show diff for this revision Revisions of this file
PinAssign/PinAssign.h Show annotated file Show diff for this revision Revisions of this file
PixyData/PixyData.cpp Show annotated file Show diff for this revision Revisions of this file
PixyData/PixyData.h 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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Gimbal_PixyTest.cpp	Thu Oct 25 03:57:08 2018 +0000
@@ -0,0 +1,35 @@
+#include "mbed.h"
+#include "PinAssign.h"
+#include "GlobalVariables.h"
+#include "PixyData.h"
+
+Ticker DebugTimer;
+
+bool fDebugTimer=0;
+
+void DebugTimer_isr(void)
+{
+    fDebugTimer=1;
+}
+
+int main() 
+{
+    pc.baud(115200);
+    pixy.baud(115200);
+    
+    DebugTimer.attach(&DebugTimer_isr,0.5);
+    
+    pc.printf("Start\n");
+    while(1) 
+    {
+        //if(pc.readable()) pixy.putc(pc.getc());
+        //if(pixy.readable()) pc.putc(pixy.getc());
+        
+        if(pixy.readable()) PixyData();
+        if(fDebugTimer==1)
+        {
+           // pc.printf("sigN:%d xObs:%d yObs:%d widthObs:%d heightObs:%d\n",PixyChks, SigNum, XObs, YObs, WidObs, HeiObs);
+            fDebugTimer=0;
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GlobalVariables/GlobalVariables.cpp	Thu Oct 25 03:57:08 2018 +0000
@@ -0,0 +1,4 @@
+#include "mbed.h"
+
+uint8_t PixyCnt, PixyBuf[20], fPixyData;
+uint16_t PixyChks, SigNum, XObs, YObs, WidObs, HeiObs, AngObs;
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GlobalVariables/GlobalVariables.h	Thu Oct 25 03:57:08 2018 +0000
@@ -0,0 +1,7 @@
+#ifndef GLOBALVARIABLES_H
+#define GLOBALVARIABLES_H
+#include "mbed.h"
+
+extern uint8_t PixyCnt, PixyBuf[20], fPixyData;
+extern uint16_t PixyChks, SigNum, XObs, YObs, WidObs, HeiObs, AngObs;
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PinAssign/PinAssign.cpp	Thu Oct 25 03:57:08 2018 +0000
@@ -0,0 +1,4 @@
+#include "PinAssign.h"
+
+Serial      pc(USBTX, USBRX);
+Serial      pixy(p28,p27);
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PinAssign/PinAssign.h	Thu Oct 25 03:57:08 2018 +0000
@@ -0,0 +1,6 @@
+#ifndef PINASSIGN_H
+#define PINASSIGN_H
+#include "mbed.h"
+extern Serial pc;
+extern Serial pixy;
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PixyData/PixyData.cpp	Thu Oct 25 03:57:08 2018 +0000
@@ -0,0 +1,47 @@
+#include "mbed.h"
+#include "PixyData.h"
+#include "GlobalVariables.h"
+#include "PinAssign.h"
+
+void PixyParse(void)
+{
+    SigNum      = PixyBuf[4]|(PixyBuf[5]<<8);
+    XObs        = PixyBuf[6]|(PixyBuf[7]<<8);
+    YObs        = PixyBuf[8]|(PixyBuf[9]<<8);
+    WidObs      = PixyBuf[10]|(PixyBuf[11]<<8);
+    HeiObs      = PixyBuf[12]|(PixyBuf[13]<<8);
+    AngObs      = PixyBuf[14]|(PixyBuf[15]<<8);
+}
+
+void PixyData(void)
+{
+    uint8_t buf;
+    buf = pixy.getc();
+    pc.putc(buf);
+    
+    if(PixyCnt==0&&buf==0x56||PixyCnt==1&&buf==0xaa||PixyCnt>=2&&PixyCnt<=15)
+    {
+        PixyBuf[PixyCnt]=buf;
+        PixyCnt++;
+        
+        //pc.printf("proc\n");
+    }
+    else if(PixyCnt==16)
+    {
+        //pc.printf("chks\n");
+        
+        PixyChks = PixyBuf[2]|(PixyBuf[3]<<8);
+        int chks=0;
+        for(uint8_t i=4;i<=15;i++)
+        {
+            chks+=PixyBuf[i];
+        }
+        if(chks==PixyChks)
+        {
+            PixyParse();
+            //pc.printf("pars\n");
+        }
+        PixyCnt=0;
+    }
+    else PixyCnt=0;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PixyData/PixyData.h	Thu Oct 25 03:57:08 2018 +0000
@@ -0,0 +1,7 @@
+#ifndef PIXYDATA_H
+#define PIXYDATA_H
+#include "mbed.h"
+
+extern void PixyData();
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Oct 25 03:57:08 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/994bdf8177cb
\ No newline at end of file