00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "PhysicalTiltSensor.h"
00013 #include "utils/Time.h"
00014 #include <fstream.h>
00015
00016 PhysicalTiltSensor::PhysicalTiltSensor()
00017 {
00018 m_fd = -1;
00019 }
00020
00021 PhysicalTiltSensor::~PhysicalTiltSensor()
00022 {
00023 close(m_fd);
00024 }
00025
00026 int PhysicalTiltSensor::Initialize()
00027 {
00028 if (m_fd < 0) {
00029 char *stringPort;
00030 stringPort = new char[80];
00031 sprintf(stringPort,"/dev/tty%s",m_Port.c_str());
00032
00033 init_serial(stringPort,B9600,&m_fd);
00034 cout << stringPort << " fd: " << m_fd << endl;
00035
00036 char *testCommand;
00037 testCommand = new char[80];
00038 sprintf(testCommand, "R");
00039 say(m_fd, testCommand);
00040 usleep(500000);
00041 hear(m_fd, testCommand, 15, 0, 10000, '\r');
00042 cout << "Reset Returned: " << testCommand << endl;
00043
00044 }
00045
00046 return 0;
00047 }
00048
00049 Vector PhysicalTiltSensor::GetSensorToBodyQuaternion()
00050 {
00051 Vector qwe(3);
00052 return qwe;
00053 }
00054
00055 void PhysicalTiltSensor::GetAngles(double& pitch, double& roll, double& t)
00056 {
00057 char *testCommand;
00058 testCommand = new char[80];
00059 sprintf(testCommand, "G");
00060 say(m_fd, testCommand);
00061
00062 t = Now();
00063 usleep(1000000);
00064 char *Results= new char[80];
00065
00066 int errval;
00067 errval = hear(m_fd, Results, 15, 6, 100000, '\r');
00068
00069
00070 pitch = ((int)256*(int) Results[1] + (int) Results[2])*0.00275415;
00071 pitch = pitch*3.14159265/180.0;
00072 roll = ((int)256*Results[3] + (int) Results[4])*0.00275415;
00073 roll = roll*3.14159265/180.0;
00074
00075 if(pitch > 1.30900){
00076 pitch = 9999;
00077 }
00078 if(roll > 1.30900){
00079 roll = 9999;
00080 }
00081
00082 return;
00083 }
00084
00085 int PhysicalTiltSensor::GetFD()
00086 {
00087 return m_fd;
00088 }
00089
00090 void PhysicalTiltSensor::SetPort(string Port)
00091 {
00092 m_Port = Port;
00093 }
00094
00095 Measurement PhysicalTiltSensor::GetMeasurement()
00096 {
00097 Measurement M;
00098 return M;
00099 }