NT-ARSV1 Simple code(not completed)

http://ntrexlab.tistory.com/15

http://backup.ntrex.co.kr/mart7/mall.php?cat=049029000&query=view&no=41925

Files at this revision

API Documentation at this revision

Comitter:
SWteamofAREC
Date:
Sat Mar 14 02:45:00 2015 +0000
Commit message:
NT-ARSV1

Changed in this revision

ARS.cpp Show annotated file Show diff for this revision Revisions of this file
ARS.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 609146aec0da ARS.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ARS.cpp	Sat Mar 14 02:45:00 2015 +0000
@@ -0,0 +1,94 @@
+#include "ARS.h"
+
+
+ARS::ARS(PinName tx,PinName rx) : _ARS(tx,rx)
+{
+    rollAngle=0;
+    pitchAngle=0;
+    rollVel=0;
+    pitchVel=0;
+} //생성자
+
+void ARS::set(int baudRate=115200)
+{
+    _ARS.baud(baudRate);
+    _ARS.printf("<CAH>");
+}
+
+void ARS::getdata() //데이터를 한줄만 받는다.
+{
+    char incomingByte=0;
+    int resultValues=0;
+    int consideringMinusSign=1;
+    int selectingValuesFromARS=0;
+
+
+    while(true) {
+
+        incomingByte=_ARS.getc();
+
+        // Operation minus sign.
+        if(incomingByte == '-') {
+            consideringMinusSign = -1;
+        }
+
+        //Operation number type
+        if(incomingByte >= '0' && incomingByte <= '9') {
+            resultValues = resultValues*10 + incomingByte - '0';
+        }
+
+        //Operation end of data
+        if(incomingByte == ',' || incomingByte == '>') {
+            resultValues = resultValues * consideringMinusSign;
+            consideringMinusSign = 1; //next calculation, using plus sign
+            selectingValuesFromARS += 1;  //increase the var.
+
+            switch(selectingValuesFromARS) {
+                case 1 : // getting roll angle as degree
+                    rollAngle = resultValues * scaleFactorOfARS * rad2degree;
+                    break;
+                case 2 : // getting pitch angle as degree
+                    pitchAngle = resultValues * scaleFactorOfARS * rad2degree;
+                    break;
+                case 3 : // getting roll anglular velocity as degree
+                    rollVel = resultValues * scaleFactorOfARS * rad2degree;
+                    break;
+
+                case 4 : // getting pitch anglular velocity as degree
+                    pitchVel = resultValues * scaleFactorOfARS * rad2degree;
+                    break;
+            }
+            resultValues = 0; //initializing the number.
+        }
+        if (incomingByte == '>') {
+            selectingValuesFromARS +=1;
+        }
+        if (selectingValuesFromARS == 5) {
+            selectingValuesFromARS=0;
+            break;
+        }
+
+    }
+}
+
+
+
+float ARS::getrollangle()
+{
+    return rollAngle;
+}
+
+float ARS::getpitchangle()
+{
+    return pitchAngle;
+}
+
+float ARS::getrollvel()
+{
+    return rollVel;
+}
+
+float ARS::getpitchvel()
+{
+    return pitchVel;
+}
diff -r 000000000000 -r 609146aec0da ARS.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ARS.h	Sat Mar 14 02:45:00 2015 +0000
@@ -0,0 +1,34 @@
+#ifndef MBED_ARSv1_H
+#define MBED_ARSv1_H
+#include "mbed.h"
+#include <iostream>
+#define READBUFFERSIZE (32)
+#define rad2degree (57.29579143)
+#define scaleFactorOfARS (0.001)// The output values of NT-ARSv1 are 1000 times in radians
+using namespace std;
+    
+
+class ARS
+{
+    public:
+    ARS(PinName tx,PinName rx);
+    //생성자 
+    float getrollangle();
+    float getpitchangle();
+    float getrollvel();
+    float getpitchvel();
+    void getdata();
+    void set(int baudRate);
+    
+    
+    protected:
+    Serial _ARS;
+
+    float rollAngle;
+    float pitchAngle;
+    float rollVel;
+    float pitchVel; 
+
+};
+
+#endif