repo_name
stringlengths
5
122
path
stringlengths
3
232
text
stringlengths
6
1.05M
structai/AsyncTelegram2
src/AsyncTelegram2.h
#ifndef ASYNCTELEGRAMV2 #define ASYNCTELEGRAMV2 // for using int_64 data #define ARDUINOJSON_USE_LONG_LONG 1 #define ARDUINOJSON_DECODE_UNICODE 1 #include <ArduinoJson.h> #if defined(ESP32) || defined(ESP8266) #define FS_SUPPORT true #include <FS.h> #include <WiFiClientSecure.h> #else #define FS_SUPPORT false #endif #ifndef LED_BUILTIN #define LED_BUILTIN 2 #endif #include "Client.h" #include "time.h" #ifndef DEBUG_ENABLE #define DEBUG_ENABLE 1 #endif #if DEBUG_ENABLE #define debugJson(X, Y) { log_debug(); Serial.println(); serializeJsonPretty(X, Y); Serial.println();} #define errorJson(E) { log_error(); Serial.println(); Serial.println(E);} #else #define debugJson(X, Y) #define errorJson(E) #endif /* This affect only inline keyboard with at least one callback function defined. If you need more than MAX_INLINEKYB_CB distinct keybords with callback functions associated to buttons increase this value */ #define MAX_INLINEKYB_CB 30 #define SERVER_TIMEOUT 10000 #define MIN_UPDATE_TIME 500 #define BLOCK_SIZE 1436 //2872 // 2 * TCP_MSS #include "DataStructures.h" #include "InlineKeyboard.h" #include "ReplyKeyboard.h" #include "serial_log.h" #define TELEGRAM_HOST "api.telegram.org" #define TELEGRAM_IP "172.16.31.10" #define TELEGRAM_PORT 443 /* This is used with ESP8266 platform only */ static const char telegram_cert[] PROGMEM = R"EOF( -----BEGIN CER<KEY> -----END CERTIFICATE----- )EOF"; class AsyncTelegram2 { using SentCallback = std::function<void(bool sent)>; public: // default constructor AsyncTelegram2(Client &client, uint32_t bufferSize = BUFFER_BIG); // default destructor ~AsyncTelegram2(); // test the connection between ESP8266 and the telegram server // returns // true if no error occurred bool begin(void); // reset the connection between ESP8266 and the telegram server (ex. when connection was lost) // returns // true if no error occurred bool reset(void); // set the telegram token // params // token: the telegram token inline void setTelegramToken(const char* token) { m_token = (char*) token; } // set the interval in milliseconds for polling // in order to Avoid query Telegram server to much often (ms) // params: // pollingTime: interval time in milliseconds void setUpdateTime(uint32_t pollingTime) { m_minUpdateTime = pollingTime;} // Get file link and size by unique document ID // params // doc : document structure // returns // true if no error bool getFile(TBDocument &doc); // get the first unread message from the queue (text and query from inline keyboard). // This is a destructive operation: once read, the message will be marked as read // so a new getMessage will read the next message (if any). // params // message: the data structure that will contains the data retrieved // returns // MessageNoData: an error has occurred // MessageText : the received message is a text // MessageQuery : the received message is a query (from inline keyboards) MessageType getNewMessage(TBMessage &message); // send a message to the specified telegram user ID // params // msg : the TBMessage telegram recipient with user ID // message : the message to send // keyboard: the inline/reply keyboard (optional) // (in json format or using the inlineKeyboard/ReplyKeyboard class helper) // wait: true if method must be blocking bool sendMessage(const TBMessage &msg, const char* message, const char* keyboard = nullptr, bool wait = false); // sendMessage function overloads inline bool sendMessage(const TBMessage &msg, const String &message, String keyboard = "") { return sendMessage(msg, message.c_str(), keyboard.c_str()); } inline bool sendMessage(const TBMessage &msg, const char* message, InlineKeyboard &keyboard) { return sendMessage(msg, message, keyboard.getJSON().c_str()); } inline bool sendMessage(const TBMessage &msg, const char* message, ReplyKeyboard &keyboard) { return sendMessage(msg, message, keyboard.getJSON().c_str()); } // Forward a specific message to user or chat bool forwardMessage(const TBMessage &msg, const int64_t to_chatid); // Send message to a channel. This bot must be in the admin group bool sendToChannel(const char* channel, const char* message, bool silent) ; inline bool sendToChannel(const String& channel, const String& message, bool silent) { return sendToChannel(channel.c_str(), message.c_str(), silent) ; } // Send message to a specific user. In order to work properly two conditions is needed: // - You have to find the userid (for example using the bot @JsonBumpBot https://t.me/JsonDumpBot) // - User has to start your bot in it's own client. For example send a message with @<your bot name> inline bool sendTo(const int64_t userid, const char* message, const char* keyboard = nullptr) { TBMessage msg; msg.chatId = userid; return sendMessage(msg, message, keyboard); } inline bool sendTo(const int64_t userid, const String &message, String keyboard = "") { return sendTo(userid, message.c_str(), keyboard.c_str() ); } // Send a document passing a stream object enum DocumentType { ZIP, PDF, PHOTO, ANIMATION, AUDIO, VOICE, VIDEO}; bool sendDocument(int64_t chat_id, Stream &stream, size_t size, DocumentType doc); inline bool sendDocument(const TBMessage &msg, Stream &stream, size_t size, DocumentType doc) { return sendDocument(msg.chatId, stream, size, doc); } // Send a picture passing the url bool sendPhotoByUrl(const int64_t& chat_id, const char* url, const char* caption); inline bool sendPhoto(const int64_t& chat_id, const char* url, const char* caption){ return sendPhotoByUrl(chat_id, url, caption); } inline bool sendPhoto(const int64_t& chat_id, const String& url, const String& caption){ return sendPhotoByUrl(chat_id, url.c_str(), caption.c_str()); } inline bool sendPhoto(const TBMessage &msg, const String& url, const String& caption){ return sendPhotoByUrl(msg.chatId, url.c_str(), caption.c_str()); } // Send a picture passing a stream object inline bool sendPhoto(int64_t chat_id, Stream &stream, size_t size) { return sendStream(chat_id, "sendPhoto", "image/jpeg", "photo", stream, size); } inline bool sendPhoto(const TBMessage &msg, Stream &stream, size_t size) { return sendStream(msg.chatId, "sendPhoto", "image/jpeg", "photo", stream, size); } inline bool sendText(const TBMessage &msg, Stream &stream, size_t size) { return sendStream(msg.chatId, "sendDocument", "text/txt", "document", stream, size); } #if FS_SUPPORT == true // #support for <FS.h> is needed // Send a picture passing a file and relative filesystem inline bool sendPhoto(int64_t chat_id, const char* filename, fs::FS &fs) { File file = fs.open(filename, "r"); bool res = sendStream(chat_id, "sendPhoto", "image/jpeg", "photo", file, file.size()); file.close(); return res; } inline bool sendPhoto(const TBMessage &msg, const char* filename, fs::FS &fs) { File file = fs.open(filename, "r"); bool res = sendStream(msg.chatId, "sendPhoto", "image/jpeg", "photo", file, file.size()); file.close(); return res; } #endif // Send a picture passing a raw buffer inline bool sendPhoto(int64_t chat_id, uint8_t *data, size_t size) { return sendBuffer(chat_id, "sendPhoto", "image/jpeg", "photo", data, size); } inline bool sendPhoto(const TBMessage &msg, uint8_t *data, size_t size) { return sendBuffer(msg.chatId, "sendPhoto", "image/jpeg", "photo", data, size); } /////////////////////////////// Backward compatibility /////////////////////////////////////// inline bool sendPhotoByUrl(const int64_t& chat_id, const String& url, const String& caption){ return sendPhotoByUrl(chat_id, url.c_str(), caption.c_str()); } inline bool sendPhotoByUrl(const TBMessage &msg, const String& url, const String& caption){ return sendPhotoByUrl(msg.chatId, url.c_str(), caption.c_str()); } inline bool sendPhotoByFile(int64_t chat_id, Stream *stream, size_t size) { return sendStream(chat_id,"sendPhoto", "image/jpeg", "photo", *stream, size); } #if FS_SUPPORT == true // #support for <FS.h> is needed inline bool sendPhotoByFile(int64_t chat_id, const char* filename, fs::FS &fs) { File file = fs.open(filename, "r"); Serial.println(file.size()); bool res = sendStream(chat_id,"sendPhoto", "image/jpeg", "photo", file, file.size()); file.close(); return res; } #endif ///////////////////////////////////////////////////////////////////////////////////////////// // terminate a query started by pressing an inlineKeyboard button. The steps are: // 1) send a message with an inline keyboard // 2) wait for a <message> (getNewMessage) of type MessageQuery // 3) handle the query and then call endQuery with <message>.callbackQueryID // params // msg : the TBMessage telegram recipient with unique query ID (retrieved with getNewMessage method) // message : an optional message // alertMode: false -> a simply popup message // true --> an alert message with ok button bool endQuery(const TBMessage &msg, const char* message, bool alertMode = false); // remove an active reply keyboard for a selected user, sending a message // params: // msg : the TBMessage telegram recipient with the telegram user ID // message : the message to be show to the selected user ID // selective: enable selective mode (hide the keyboard for specific users only) // Targets: 1) users that are @mentioned in the text of the Message object; // 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message // return: // true if no error occurred bool removeReplyKeyboard(const TBMessage &msg, const char* message, bool selective = false); // Get the current bot name // return: // the bot name inline const char* getBotName() { return m_botusername.c_str(); } // Check for no new pending message // (to be sure all messages was parsed, before doing something) // Example: OTA sketch // return: // true if no message bool noNewMessage(); // If bot is a member of a group, return the id of group (negative number) // In order to be sure library is able to catch the id, // add bot to group while it is running, so the joining message can be parsed inline int64_t getGroupId(const TBMessage &msg) { if(msg.chatId < 0) return msg.chatId; return 0; } // keep track of defined inline keybaord in order to call cb function // params: pointer to inline keyboard inline void addInlineKeyboard(InlineKeyboard* keyb) { m_keyboards[m_keyboardCount++] = keyb; } // set custom commands for bot // params // command: Text of the command, 1-32 characters. Can contain only lowercase English letters, digits and underscores. // description: Description of the command, 3-256 characters. // return: // true if success bool setMyCommands(const String &cmd, const String &desc); // get list of custom commands defined for bot // params: // A string that will contains a JSON-serialized list of bot commands void getMyCommands(String &cmdList); // clear list of custom commands defined for bot // return: // true if success bool deleteMyCommands(); // Edit a previous sent message // params: // chat_id: the iD of chat // message_id: the message ID to be edited // txt: the new text // keyboard: the new inline keyboard (if present) // return: // true if success bool editMessage(int32_t chat_id, int32_t message_id, const String& txt, const String &keyboard); inline bool editMessage(const TBMessage &msg, const String& txt, const String &keyboard) { return editMessage(msg.chatId, msg.messageID, txt, keyboard); } inline bool editMessage(int32_t chat_id, int32_t message_id, const String& txt, InlineKeyboard &keyboard) { return editMessage(chat_id, message_id, txt, keyboard.getJSON()); } inline bool editMessage(const TBMessage &msg, const String& txt, InlineKeyboard &keyboard) { return editMessage(msg.chatId, msg.messageID, txt, keyboard.getJSON()); } // check if connection with server is active // returns // true on connected bool checkConnection(); // This callback function will be executed once the message was delivered succesfully inline void addSentCallback(SentCallback sentcb, uint32_t timeout = 1000) { if(sentcb != nullptr) { m_sentCallback = sentcb; m_sentTimeout = timeout; } } private: Client* telegramClient; const char* m_token; String m_rxbuffer; String m_botusername; // Store only botname, instead TBUser struct int32_t m_lastUpdateId = 0; uint32_t m_lastUpdateTime; uint32_t m_minUpdateTime = MIN_UPDATE_TIME; uint32_t m_lastmsg_timestamp; bool m_waitingReply; InlineKeyboard* m_keyboards[10]; uint8_t m_keyboardCount = 0; void setformData(int64_t chat_id, const char* cmd, const char* type, const char* propName, size_t size, String &formData, String& request); bool sendStream( int64_t chat_id, const char* command, const char* contentType, const char* binaryPropertyName, Stream& stream, size_t size); bool sendBuffer(int64_t chat_id, const char* cmd, const char* type, const char* propName, uint8_t *data, size_t size); SentCallback m_sentCallback = nullptr; bool m_waitSent = false; uint32_t m_sentTimeout; uint32_t m_lastSentTime; uint32_t m_lastSentMsgId; uint32_t testReconnectTime; protected: // send commands to the telegram server. For info about commands, check the telegram api https://core.telegram.org/bots/api // params // command : the command to send, i.e. getMe // parameters: optional parameters // returns // an empty string if error // a string containing the Telegram JSON response bool sendCommand(const char* command, const char* payload, bool blocking = false); // query server for new incoming messages // returns // http response payload if no error occurred //bool getUpdates(JsonDocument &doc); bool getUpdates(); // get some information about the bot // params // user: the data structure that will contains the data retreived // returns // true if no error occurred bool getMe(); }; #endif
structai/AsyncTelegram2
src/DataStructures.h
<gh_stars>1-10 #ifndef DATA_STRUCTURES #define DATA_STRUCTURES #define BUFFER_BIG 2048 // json parser buffer size (ArduinoJson v6) #define BUFFER_MEDIUM 1028 // json parser buffer size (ArduinoJson v6) #define BUFFER_SMALL 512 // json parser buffer size (ArduinoJson v6) enum MessageType { MessageNoData = 0, MessageText = 1, MessageQuery = 2, MessageLocation = 3, MessageContact = 4, MessageDocument = 5, MessageReply = 6, MessageNewMember = 7, MessageLeftMember =8, MessageForwarded = 9 }; struct TBUser { bool isBot; int64_t id = 0; String firstName; String lastName; String username; }; struct TBLocation{ float longitude; float latitude; }; struct TBContact { int64_t id; String phoneNumber; String firstName; String lastName; String vCard; }; struct TBDocument { bool file_exists; int32_t file_size; String file_id; String file_name; String file_path; }; struct TBMessage { MessageType messageType; bool isHTMLenabled = true; bool isMarkdownEnabled = false; bool disable_notification = false; bool force_reply = false; int32_t date; int32_t chatInstance; int64_t chatId; int32_t messageID; TBUser sender; TBUser member; // A user enter or leave a group TBLocation location; TBContact contact; TBDocument document; int64_t callbackQueryID; String callbackQueryData; String text; }; #endif
pmeenan/powermon
PowerStats.h
#ifdef WIN32 #include <Windows.h> #endif #include <stdio.h> #include <string.h> #include <string> #ifdef WIN32 #include "lib/intel/IntelPowerGadgetLib.h" #endif class PowerStats { public: PowerStats(); ~PowerStats(); std::string Start(); std::string Measure(); bool ok; private: std::string GetCPUTime(); std::string GetPowerData(); std::string GetElapsedTime(); std::string DoubleToString(double num); #ifdef WIN32 LARGE_INTEGER start_time; ULARGE_INTEGER start_cpu_time; void GetWinCPUTime(ULARGE_INTEGER &cpu_time); CIntelPowerGadgetLib intel; #else uint64_t start_time; uint64_t start_cpu_time; uint64_t GetMacCPUTime(); #endif // Wrappers around the Intel API's bool Intel_ReadSample(); bool Intel_GetTimeInterval(double &interval); bool Intel_GetNumNodes(int &count); bool Intel_GetNumMsrs(int &count); bool Intel_GetMsrName(int iMsr, std::string &name); bool Intel_GetMsrFunc(int iMsr, int &funcID); bool Intel_GetPowerData(int iNode, int iMSR, double *pResult, int *nResult); };
devdawei/DVVCoding
DVVCoding/DVVCoding/DVVCoding.h
// // DVVCoding.h // DVVCoding <https://github.com/devdawei/DVVCoding.git> // // Created by 大威 on 2016/11/21. // Copyright © 2016年 devdawei. All rights reserved. // #import <Foundation/Foundation.h> @protocol DVVCodingDelegate <NSObject> @optional /** 如果有不想缓存的属性,通过此代理方法返回就可以了 */ + (NSArray *)dvv_codingIgnoreProperties; @end @interface NSObject (DVVCoding) /** * 解码(从文件解析对象) */ - (void)dvv_decode:(NSCoder *)decoder; /** * 编码(将对象写入文件) */ - (void)dvv_encode:(NSCoder *)encoder; /** * 属性归档的实现 */ #define DVVCodingImplementation \ - (instancetype)initWithCoder:(NSCoder *)aDecoder \ { \ self = [super init]; \ if (self) { \ [self dvv_decode:aDecoder]; \ } \ return self; \ } \ \ - (void)encodeWithCoder:(NSCoder *)coder \ { \ [self dvv_encode:coder]; \ } @end
sergesyrota/sewer-monitor
Arduino/LaserSensing.h
<reponame>sergesyrota/sewer-monitor #ifndef LaserSensing_h #define LaserSensing_h #define LASER_SENSING_NUMBER_READINGS 50 class LaserSensing { public: LaserSensing(int max_valid, int min_valid); // Constructor void reading(int data); // Records a reading, and does necessary processing int getValue(); // Gets currently assumed valid value int percentValid(); // Gets ratio of invalid readings in the current data set private: int readings[LASER_SENSING_NUMBER_READINGS]; // Array with raw readings unsigned char reading_pointer; // Pointer to the next reading to be overwritten int max_valid; // Anything above this will be considered invalid int min_valid; // Anything below this will be considered invalid bool isValid(int data); // Checks if data point is valid }; #endif
sergesyrota/sewer-monitor
cppunit/TestLaserSensing.h
<gh_stars>0 /* * TestLin2dSolver.cpp * * Created on: Feb 16, 2013 * Author: <NAME> */ #include <iostream> #include <cppunit/TestFixture.h> #include <cppunit/TestAssert.h> #include <cppunit/TestCaller.h> #include <cppunit/TestSuite.h> #include <cppunit/TestCase.h> #include "../Arduino/LaserSensing.h" using namespace std; class TestLaserSensing : public CppUnit::TestFixture { private: LaserSensing *testCounter; public: static CppUnit::Test *suite() { CppUnit::TestSuite *suiteOfTests = new CppUnit::TestSuite("Test averaging valid results"); suiteOfTests->addTest(new CppUnit::TestCaller<TestLaserSensing>("One initial reading with all invalid", &TestLaserSensing::testOneReading )); suiteOfTests->addTest(new CppUnit::TestCaller<TestLaserSensing>("All invalid", &TestLaserSensing::testAllInvalid )); suiteOfTests->addTest(new CppUnit::TestCaller<TestLaserSensing>("Mix of valid and invalid", &TestLaserSensing::testMix )); suiteOfTests->addTest(new CppUnit::TestCaller<TestLaserSensing>("Random readings", &TestLaserSensing::testRandomReadings )); suiteOfTests->addTest(new CppUnit::TestCaller<TestLaserSensing>("Same reading filling up the array", &TestLaserSensing::testSameReadings )); suiteOfTests->addTest(new CppUnit::TestCaller<TestLaserSensing>("Rollover by 1", &TestLaserSensing::testRollover )); return suiteOfTests; } /// Setup method void setUp() { testCounter = new LaserSensing(5000,1); // zero-out all data for (int i = 0; i < LASER_SENSING_NUMBER_READINGS; i++) { testCounter->reading(0); } } /// Teardown method void tearDown() { } protected: void addReadings(const int size, const int data[]) { //int size = sizeof(data) / sizeof(data[0]); for (int i=0; i<size; i++) { testCounter->reading(data[i]); } } void testOneReading() { addReadings(1, (int[]){500}); CPPUNIT_ASSERT_EQUAL( 500, testCounter->getValue() ); CPPUNIT_ASSERT_EQUAL( (int)100/LASER_SENSING_NUMBER_READINGS, testCounter->percentValid() ); } void testAllInvalid() { addReadings(10, (int[]){-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}); CPPUNIT_ASSERT_EQUAL( 0, testCounter->getValue() ); CPPUNIT_ASSERT_EQUAL( 0, testCounter->percentValid() ); } void testMix() { addReadings(10, (int[]){-1,-10,300,8096,300,300,20000,300,300}); CPPUNIT_ASSERT_EQUAL( 300, testCounter->getValue() ); CPPUNIT_ASSERT_EQUAL( (int)5*100/LASER_SENSING_NUMBER_READINGS, testCounter->percentValid() ); } void testRandomReadings() { addReadings(10, (int[]){526,528,536,538,524,539,521,539,522,549}); CPPUNIT_ASSERT_EQUAL( 532, testCounter->getValue() ); CPPUNIT_ASSERT_EQUAL( (int)10*100/LASER_SENSING_NUMBER_READINGS, testCounter->percentValid() ); } void testSameReadings() { testCounter->reading(500); testCounter->reading(500); testCounter->reading(500); testCounter->reading(500); testCounter->reading(500); testCounter->reading(500); testCounter->reading(500); testCounter->reading(500); testCounter->reading(500); testCounter->reading(500); CPPUNIT_ASSERT_EQUAL( 500, testCounter->getValue() ); CPPUNIT_ASSERT_EQUAL( (int)10*100/LASER_SENSING_NUMBER_READINGS, testCounter->percentValid() ); } void testRollover() { testCounter->reading(500); for (int i = 0; i < LASER_SENSING_NUMBER_READINGS; i++) { testCounter->reading(600); } CPPUNIT_ASSERT_EQUAL( 600, testCounter->getValue() ); CPPUNIT_ASSERT_EQUAL( 100, testCounter->percentValid() ); } };
sergesyrota/sewer-monitor
Arduino/config.h
<gh_stars>0 //#define DEBUG // Config version #define CONFIG_VERSION "SM1" // SyrotaAutomation parameters #define RS485_CONTROL_PIN 2 #define NET_ADDRESS "SewerMonitor" struct configuration_t { char checkVersion[4]; // This is for detection if we have right settings or not unsigned long baudRate; // Serial/RS-485 rate: 9600, 14400, 19200, 28800, 38400, 57600, or unsigned int laserReadInterval; // How often to read laser sensor (milliseconds) };
Changliu52/UnicornTeensyDrone
libraries_teensy3.2/ros_lib/mavros/OverrideRCIn.h
<reponame>Changliu52/UnicornTeensyDrone #ifndef _ROS_mavros_OverrideRCIn_h #define _ROS_mavros_OverrideRCIn_h #include <stdint.h> #include <string.h> #include <stdlib.h> #include "ros/msg.h" namespace mavros { class OverrideRCIn : public ros::Msg { public: uint16_t channels[8]; enum { CHAN_RELEASE = 0 }; enum { CHAN_NOCHANGE = 65535 }; OverrideRCIn(): channels() { } virtual int serialize(unsigned char *outbuffer) const { int offset = 0; for( uint8_t i = 0; i < 8; i++){ *(outbuffer + offset + 0) = (this->channels[i] >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (this->channels[i] >> (8 * 1)) & 0xFF; offset += sizeof(this->channels[i]); } return offset; } virtual int deserialize(unsigned char *inbuffer) { int offset = 0; for( uint8_t i = 0; i < 8; i++){ this->channels[i] = ((uint16_t) (*(inbuffer + offset))); this->channels[i] |= ((uint16_t) (*(inbuffer + offset + 1))) << (8 * 1); offset += sizeof(this->channels[i]); } return offset; } const char * getType(){ return "mavros/OverrideRCIn"; }; const char * getMD5(){ return "73b27a463a40a3eda1f9fbb1fc86d6f3"; }; }; } #endif
Changliu52/UnicornTeensyDrone
unicorn/odroidListener.h
//©2016 <NAME> // // transform_listener.h // // // Created by <NAME> on 28/01/2015. // // #ifndef ROS_ODROIDLISTENER_H_ #define ROS_ODROIDLISTENER_H_ #include <vi_ekf/teensyPilot.h> #include "PositionManageSVO.h" namespace vi_ekf { class odroidListener { public: // Constructor odroidListener() : Subscriber_("ekf/output", &messageCb) {} // Initialisation function void init(ros::NodeHandle &nh) { nh.subscribe(Subscriber_); } private: // core variables vi_ekf::teensyPilot internal_msg; ros::Subscriber<vi_ekf::teensyPilot> Subscriber_; // Callback function when message arrives static void messageCb(const vi_ekf::teensyPilot& internal_msg) // we get this message with 10ms latency! { qVision[0] = internal_msg.qw; qVision[1] = internal_msg.qx; qVision[2] = internal_msg.qy; qVision[3] = internal_msg.qz; pVision[0] = internal_msg.px; pVision[1] = internal_msg.py; pVision[2] = internal_msg.pz; vVision[0] = internal_msg.vx; vVision[1] = internal_msg.vy; vVision[2] = internal_msg.vz; VIbias_accel[0] = internal_msg.bx; VIbias_accel[1] = internal_msg.by; VIbias_accel[2] = internal_msg.bz; lambdaVision = internal_msg.lambda;//(float)(nh.now().toSec()-946688000.0)- internal_msg.lambda; // vision_available_ = internal_msg.status; vision_new_measurment_ = 1; // for debugging vVision_raw[0] = vVision[0]; vVision_raw[1] = vVision[1]; vVision_raw[2] = vVision[2]; // compensate velocity delay compensate_visionVelocity(vVision); } }; } #endif
Changliu52/UnicornTeensyDrone
unicorn/myFreeIMU.h
<reponame>Changliu52/UnicornTeensyDrone<filename>unicorn/myFreeIMU.h<gh_stars>1-10 //©2016 <NAME> #ifndef __MYFREEIMU_H__ #define __MYFREEIMU_H__ #include <Arduino.h> #include "COM.h" // Shift mean filter for accel in world frame //_____________________________ void filterAcce(float* acce, float* acceNew) { float bufferSize = 20.0; //40 for (int i=0; i<3; i++){ acceNew[i] = ((bufferSize-1)/bufferSize)*acceNew[i] + acce[i]/bufferSize; } } // Mean FreeIMU reading function //_________________________________ void read_IMU(float timeChange) { // for COM Debug£££££££££ /*if(((qVision[0] != 0.0f) || (qVision[1] != 0.0f) || (qVision[2] != 0.0f) || (qVision[3] != 0.0f)) && vision_available_ == 1) { STATUS.v.qD[0] = qVision[0];//pVision[0];//SVOposition_w[1];// STATUS.v.qD[1] = qVision[1];//pVision[1];//SVOposition_w[2];// STATUS.v.qD[2] = qVision[2];//pVision[2];//SVOposition_w[3];// STATUS.v.qD[3] = qVision[3];//1.0;//accelD_smt[2]; }*/ // Get NED angles my3IMU.getEuler_EarthAccel_EstAlt_gyro_vis(q, acce, AltiOutput, Omega, qVision, XBeeSerial, vision_available_, VIbias_accel); // reset qVision qVision[0] = 0.0; qVision[1] = 0.0; qVision[2] = 0.0; qVision[3] = 0.0; // reset vision orientation buffer // Compute R float _2qxqx = 2*q[1]*q[1]; float _2qyqy = 2*q[2]*q[2]; float _2qzqz = 2*q[3]*q[3]; float _2qxqy = 2*q[1]*q[2]; float _2qxqz = 2*q[1]*q[3]; float _2qxqw = 2*q[1]*q[0]; float _2qyqz = 2*q[2]*q[3]; float _2qyqw = 2*q[2]*q[0]; float _2qzqw = 2*q[3]*q[0]; R[0][0] = 1 - _2qyqy - _2qzqz; R[0][1] = _2qxqy - _2qzqw; R[0][2] = _2qxqz + _2qyqw; R[1][0] = _2qxqy + _2qzqw; R[1][1] = 1 - _2qxqx - _2qzqz; R[1][2] = _2qyqz - _2qxqw; R[2][0] = _2qxqz - _2qyqw; R[2][1] = _2qyqz + _2qxqw; R[2][2] = 1 - _2qxqx - _2qyqy; // smooth acceleration filterAcce(acce+1, acceSmt); } #endif
Changliu52/UnicornTeensyDrone
libraries_teensy3.2/ros_lib/mavros/ParamSet.h
#ifndef _ROS_SERVICE_ParamSet_h #define _ROS_SERVICE_ParamSet_h #include <stdint.h> #include <string.h> #include <stdlib.h> #include "ros/msg.h" namespace mavros { static const char PARAMSET[] = "mavros/ParamSet"; class ParamSetRequest : public ros::Msg { public: const char* param_id; int64_t integer; float real; ParamSetRequest(): param_id(""), integer(0), real(0) { } virtual int serialize(unsigned char *outbuffer) const { int offset = 0; uint32_t length_param_id = strlen(this->param_id); memcpy(outbuffer + offset, &length_param_id, sizeof(uint32_t)); offset += 4; memcpy(outbuffer + offset, this->param_id, length_param_id); offset += length_param_id; union { int64_t real; uint64_t base; } u_integer; u_integer.real = this->integer; *(outbuffer + offset + 0) = (u_integer.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_integer.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_integer.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_integer.base >> (8 * 3)) & 0xFF; *(outbuffer + offset + 4) = (u_integer.base >> (8 * 4)) & 0xFF; *(outbuffer + offset + 5) = (u_integer.base >> (8 * 5)) & 0xFF; *(outbuffer + offset + 6) = (u_integer.base >> (8 * 6)) & 0xFF; *(outbuffer + offset + 7) = (u_integer.base >> (8 * 7)) & 0xFF; offset += sizeof(this->integer); offset += serializeAvrFloat64(outbuffer + offset, this->real); return offset; } virtual int deserialize(unsigned char *inbuffer) { int offset = 0; uint32_t length_param_id; memcpy(&length_param_id, (inbuffer + offset), sizeof(uint32_t)); offset += 4; for(unsigned int k= offset; k< offset+length_param_id; ++k){ inbuffer[k-1]=inbuffer[k]; } inbuffer[offset+length_param_id-1]=0; this->param_id = (char *)(inbuffer + offset-1); offset += length_param_id; union { int64_t real; uint64_t base; } u_integer; u_integer.base = 0; u_integer.base |= ((uint64_t) (*(inbuffer + offset + 0))) << (8 * 0); u_integer.base |= ((uint64_t) (*(inbuffer + offset + 1))) << (8 * 1); u_integer.base |= ((uint64_t) (*(inbuffer + offset + 2))) << (8 * 2); u_integer.base |= ((uint64_t) (*(inbuffer + offset + 3))) << (8 * 3); u_integer.base |= ((uint64_t) (*(inbuffer + offset + 4))) << (8 * 4); u_integer.base |= ((uint64_t) (*(inbuffer + offset + 5))) << (8 * 5); u_integer.base |= ((uint64_t) (*(inbuffer + offset + 6))) << (8 * 6); u_integer.base |= ((uint64_t) (*(inbuffer + offset + 7))) << (8 * 7); this->integer = u_integer.real; offset += sizeof(this->integer); offset += deserializeAvrFloat64(inbuffer + offset, &(this->real)); return offset; } const char * getType(){ return PARAMSET; }; const char * getMD5(){ return "ea705c97d21e1fbcbf5e474d576723e3"; }; }; class ParamSetResponse : public ros::Msg { public: bool success; int64_t integer; float real; ParamSetResponse(): success(0), integer(0), real(0) { } virtual int serialize(unsigned char *outbuffer) const { int offset = 0; union { bool real; uint8_t base; } u_success; u_success.real = this->success; *(outbuffer + offset + 0) = (u_success.base >> (8 * 0)) & 0xFF; offset += sizeof(this->success); union { int64_t real; uint64_t base; } u_integer; u_integer.real = this->integer; *(outbuffer + offset + 0) = (u_integer.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_integer.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_integer.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_integer.base >> (8 * 3)) & 0xFF; *(outbuffer + offset + 4) = (u_integer.base >> (8 * 4)) & 0xFF; *(outbuffer + offset + 5) = (u_integer.base >> (8 * 5)) & 0xFF; *(outbuffer + offset + 6) = (u_integer.base >> (8 * 6)) & 0xFF; *(outbuffer + offset + 7) = (u_integer.base >> (8 * 7)) & 0xFF; offset += sizeof(this->integer); offset += serializeAvrFloat64(outbuffer + offset, this->real); return offset; } virtual int deserialize(unsigned char *inbuffer) { int offset = 0; union { bool real; uint8_t base; } u_success; u_success.base = 0; u_success.base |= ((uint8_t) (*(inbuffer + offset + 0))) << (8 * 0); this->success = u_success.real; offset += sizeof(this->success); union { int64_t real; uint64_t base; } u_integer; u_integer.base = 0; u_integer.base |= ((uint64_t) (*(inbuffer + offset + 0))) << (8 * 0); u_integer.base |= ((uint64_t) (*(inbuffer + offset + 1))) << (8 * 1); u_integer.base |= ((uint64_t) (*(inbuffer + offset + 2))) << (8 * 2); u_integer.base |= ((uint64_t) (*(inbuffer + offset + 3))) << (8 * 3); u_integer.base |= ((uint64_t) (*(inbuffer + offset + 4))) << (8 * 4); u_integer.base |= ((uint64_t) (*(inbuffer + offset + 5))) << (8 * 5); u_integer.base |= ((uint64_t) (*(inbuffer + offset + 6))) << (8 * 6); u_integer.base |= ((uint64_t) (*(inbuffer + offset + 7))) << (8 * 7); this->integer = u_integer.real; offset += sizeof(this->integer); offset += deserializeAvrFloat64(inbuffer + offset, &(this->real)); return offset; } const char * getType(){ return PARAMSET; }; const char * getMD5(){ return "033326784a68a941a49106c3d258742e"; }; }; class ParamSet { public: typedef ParamSetRequest Request; typedef ParamSetResponse Response; }; } #endif
Changliu52/UnicornTeensyDrone
unicorn/spektrumSatil.h
<gh_stars>1-10 //©2016 <NAME> #ifndef __SATIL_H__ #define __SATIL_H__ #include <Arduino.h> #include "MyMatMath.h" #define Start_byte 0x01 #define Stop_byte 0x03 #define chnNum 7 int chns[chnNum] = {0,0,0,0,0,0,0}; int chnsChange; int chnsOld[chnNum] = {0,0,0,0,0,0,0}; // This function is coupled with spectrum DSM2 satellite receiver template <class USerial> boolean update_receiver(USerial *s) { if (s->available() >= 16) { // Check Start Bytes if (s->read() != Start_byte) return 0; // Read channels for (int i = 0; i < chnNum; i ++){ // update buffer chns[i] = (s->read() << 8) + s->read(); } // Check Stop Bytes if (s->read() != Stop_byte) return 0; return 1; } return 0; } //_______________________ // Read Manual template <class USerial> boolean read_receiver(USerial *s) { // Get Control From Receiver if (update_receiver(s)) { Serial.println(chns[4]); // Set Flags (Finite State Machine) if (chns[4] == 6315) {armed = 1;} else {armed = 0;} if (chns[5] >= 200 && chns[5] <= 854) {onAir = 1;} else {onAir = 0;} if (chns[2] == 4266) {enableControl = 1;} else {enableControl = 0;} // Throttle throttleLevel_raw = min(400.00, max(0, ((float)chns[5] - 175.00) * 400.00 / (848.00 - 175.00))); // throttle level rescaled to bottom:0 ~ 400:top // Yaw float yawChange = 0.5 * ((3237.00 - (float)chns[6]) / (3925.00 - 3237.00) + 0.49); if (yawChange > 0.04 || yawChange < -0.04) desireAttitude_raw[2] = desireAttitude_raw[2] - (0.3*yawChange); // Roll & Pitch (value follows front-left-up bodyframe) desireAttitude_raw[0] = min(pi/4.00, max(-pi/4.00, ((float)chns[0]-1195.0)*(pi/2.00)/(1195.0-1876.0) + (pi/4.00))); // angle around x-axis left:-45 ~ 45:right desireAttitude_raw[1] = -min(pi/4.00, max(-pi/4.00, ((float)chns[3]-2221.0)*(pi/2.00)/(2221.0-2895.0) + (pi/4.00))); // angle around y-axis down:-45 ~ 45:up return true; } return false; } //____________________ // Function used to compute Rd as desired rotation matrix void computeRd_RC() { // Compute Bd_z (z-axis of the desired body frame) float Bd_z_w[3]; Bd_z_w[0] = sin(desireAttitude[1]); Bd_z_w[1] = -sin(desireAttitude[0]) * cos(desireAttitude[1]); Bd_z_w[2] = cos(desireAttitude[0]) * cos(desireAttitude[1]); float YawRot[3][3]; YawRot[0][0] = cos(desireAttitude[2]); YawRot[0][1] = -sin(desireAttitude[2]); YawRot[0][2] = 0; YawRot[1][0] = sin(desireAttitude[2]); YawRot[1][1] = cos(desireAttitude[2]); YawRot[1][2] = 0; YawRot[2][0] = 0; YawRot[2][1] = 0; YawRot[2][2] = 1; float Bd_z[3]; multiply3(YawRot, Bd_z_w, Bd_z); // Compute inital Bd_x (x-axis of the desired body frame in world xy plane) float W_x[3] = {1,0,0}; float Bd_x[3]; multiply3(YawRot, W_x, Bd_x); // Compute Bd_y = (Bd_z X Bd_x)/||Bd_z X Bd_x|| (y-axis of the desired body frame) float Bd_y[3]; cross3(Bd_z, Bd_x, Bd_y); float Bd_yNorm = norm3(Bd_y); if(Bd_yNorm > 0.001){ // Make sure Bd_y is not parallel with Bd_z!! scale3(Bd_y, 1/norm3(Bd_y)); // Compute real Bd_x = Bd_y X Bd_z (project it to the plane normal to Bd_z) cross3(Bd_y, Bd_z, Bd_x); //----> Compute Rd Rd[0][0] = Bd_x[0]; Rd[0][1] = Bd_y[0]; Rd[0][2] = Bd_z[0]; Rd[1][0] = Bd_x[1]; Rd[1][1] = Bd_y[1]; Rd[1][2] = Bd_z[1]; Rd[2][0] = Bd_x[2]; Rd[2][1] = Bd_y[2]; Rd[2][2] = Bd_z[2]; //----> Compute DotRd = (Rd - RdOld)/dt float timenow = micros(); float dt = timenow - Rd_timer_last; Rd_timer_last = timenow; if (dt > 0.0) { if (dt > 40000.0) dt = 20000.0; // smooth transation (assmue 50 hz) subtract3(Rd, RdOld, DotRd); scale3(DotRd, 1000000.00f/dt); // sin(Rad)/s ~= Rad/s } copy3(Rd, RdOld); } } //________________ // Acceleration void convert_RC_accel() { // desired acceleration in world frame (front-left-up) accel_user[0] = 5.00*desireAttitude[1]*4.00/pi; //-5 ~ 5 m/s/s front x accel_user[1] = -5.00*desireAttitude[0]*4.00/pi; //-5 ~ 5 m/s/s left y accel_user[2] = 4.00*(throttleLevel-200.00)/200.00; //-4 ~ 4 m/s/s up z // Yaw rotate to body frame float YawRot[3][3]; YawRot[0][0] = cos(desireAttitude[2]); YawRot[0][1] = -sin(desireAttitude[2]); YawRot[0][2] = 0; YawRot[1][0] = sin(desireAttitude[2]); YawRot[1][1] = cos(desireAttitude[2]); YawRot[1][2] = 0; YawRot[2][0] = 0; YawRot[2][1] = 0; YawRot[2][2] = 1; float temp[3]; multiply3(YawRot, accel_user, temp); copy3(temp, accel_user); } //________________ // Acceleration Altitude void convert_RC_accel_alt() { // desired acceleration in world frame (front-left-up) accelD[0] = 5.00*desireAttitude[1]*4.00/pi; //-5 ~ 5 m/s/s front x accelD[1] = -5.00*desireAttitude[0]*4.00/pi; //-5 ~ 5 m/s/s left y veloD[2] = -1.00+3.00*(throttleLevel)/400.00; //-1 ~ 2 m up altitude // Yaw rotate to body frame float YawRot[3][3]; YawRot[0][0] = cos(desireAttitude[2]); YawRot[0][1] = -sin(desireAttitude[2]); YawRot[0][2] = 0; YawRot[1][0] = sin(desireAttitude[2]); YawRot[1][1] = cos(desireAttitude[2]); YawRot[1][2] = 0; YawRot[2][0] = 0; YawRot[2][1] = 0; YawRot[2][2] = 1; float temp[3]; multiply3(YawRot, accelD, temp); copy3(temp, accelD); } //_____________ // Velocity void convert_RC_velo() { // desired velocity in body frame (front-left-up) veloD[0] = 1.00*desireAttitude[1]*4.00/pi; //-1.0 ~ 1.0 m/s front x veloD[1] = -1.00*desireAttitude[0]*4.00/pi; //-1.0 ~ 1.0 m/s left y veloD[2] = -1.00+3.00*(throttleLevel)/400.00; //-1 ~ 2 m up altitude // avoid remote control drift if (veloD[0] > -0.05 && veloD[0] < 0.05) veloD[0] = 0.0; if (veloD[1] > -0.05 && veloD[1] < 0.05) veloD[1] = 0.0; // Yaw rotate to world frame float YawRot[3][3]; YawRot[0][0] = cos(desireAttitude[2]); YawRot[0][1] = -sin(desireAttitude[2]); YawRot[0][2] = 0; YawRot[1][0] = sin(desireAttitude[2]); YawRot[1][1] = cos(desireAttitude[2]); YawRot[1][2] = 0; YawRot[2][0] = 0; YawRot[2][1] = 0; YawRot[2][2] = 1; float temp[3]; multiply3(YawRot, veloD, temp); copy3(temp, veloD); } //______________ // Position void compute_velo2posi(float dt) // dt in sec { // velocity to position if (veloD[0]*veloD[0] > 0.0001) posiD[0] += veloD[0]*dt; if (veloD[1]*veloD[1] > 0.0001) posiD[1] += veloD[1]*dt; posiD[2] = veloD[2] + posAltiOffset; // velo[2] is altitude already } // Shift mean filter for RC remote in world frame //_____________________________ void filter_value(float* raw, float* outputBuffer, float bufferSize) { outputBuffer[0] = ((bufferSize-1)/bufferSize)*outputBuffer[0] + raw[0]/bufferSize; } //____________________ // Function to filter RC controller void filterRC() { filter_value(&throttleLevel_raw, &throttleLevel, 10.0); for (int i=0; i<2; i++){ filter_value(desireAttitude_raw+i, desireAttitude+i, 10.0); } filter_value(desireAttitude_raw+2, desireAttitude+2, 30.0); } #endif
Changliu52/UnicornTeensyDrone
libraries_teensy3.2/ros_lib/mavros/WaypointGOTO.h
#ifndef _ROS_SERVICE_WaypointGOTO_h #define _ROS_SERVICE_WaypointGOTO_h #include <stdint.h> #include <string.h> #include <stdlib.h> #include "ros/msg.h" #include "mavros/Waypoint.h" namespace mavros { static const char WAYPOINTGOTO[] = "mavros/WaypointGOTO"; class WaypointGOTORequest : public ros::Msg { public: mavros::Waypoint waypoint; WaypointGOTORequest(): waypoint() { } virtual int serialize(unsigned char *outbuffer) const { int offset = 0; offset += this->waypoint.serialize(outbuffer + offset); return offset; } virtual int deserialize(unsigned char *inbuffer) { int offset = 0; offset += this->waypoint.deserialize(inbuffer + offset); return offset; } const char * getType(){ return WAYPOINTGOTO; }; const char * getMD5(){ return "aeb81a83418666b5948fe3f24d59594e"; }; }; class WaypointGOTOResponse : public ros::Msg { public: bool success; WaypointGOTOResponse(): success(0) { } virtual int serialize(unsigned char *outbuffer) const { int offset = 0; union { bool real; uint8_t base; } u_success; u_success.real = this->success; *(outbuffer + offset + 0) = (u_success.base >> (8 * 0)) & 0xFF; offset += sizeof(this->success); return offset; } virtual int deserialize(unsigned char *inbuffer) { int offset = 0; union { bool real; uint8_t base; } u_success; u_success.base = 0; u_success.base |= ((uint8_t) (*(inbuffer + offset + 0))) << (8 * 0); this->success = u_success.real; offset += sizeof(this->success); return offset; } const char * getType(){ return WAYPOINTGOTO; }; const char * getMD5(){ return "358e233cde0c8a8bcfea4ce193f8fc15"; }; }; class WaypointGOTO { public: typedef WaypointGOTORequest Request; typedef WaypointGOTOResponse Response; }; } #endif
Changliu52/UnicornTeensyDrone
unicorn/AttitudeController.h
<filename>unicorn/AttitudeController.h<gh_stars>1-10 //©2016 <NAME> #ifndef __Attitude_Controller_H__ #define __Attitude_Controller_H__ #include <Arduino.h> #include "ESC_PWM.h" // Enable attitude controller //_____________________________________ void attach_attitude_controller(float dt) { // ---------> // Compute RdT and RT float RdT[3][3]; transpose3(Rd, RdT); float RT[3][3]; transpose3(R, RT); // Compute RdT_R and RT_Rd float RdT_R[3][3]; multiply3(RdT, R, RdT_R); float RT_Rd[3][3]; multiply3(RT, Rd, RT_Rd); // ErrorR = 0.5 * (Rd' * R - R' * Rd)V; float RdT_R_RT_Td[3][3]; subtract3(RdT_R, RT_Rd, RdT_R_RT_Td); float ErrorR[3]; veeSkew3(RdT_R_RT_Td, ErrorR); scale3(ErrorR, 0.50); // ---------> // Compute OmegaD = (RdT * DotRd)V float RdT_DotRd[3][3]; multiply3(RdT, DotRd, RdT_DotRd); float OmegaD[3]; veeSkew3(RdT_DotRd, OmegaD); // Compute RT_Rd_OmegaD float RT_Rd_OmegaD[3]; multiply3(RT_Rd, OmegaD, RT_Rd_OmegaD); // #### // scale RT_Rd_OmegaD for better hover stability /*float commandLevel = accelD_smt[0]+position_integ[0]; // used to find the maximum acceleration axis (without integral) commandLevel *= commandLevel; for (int i=1; i<3; i++) { float commandProbe = accelD_smt[i]+position_integ[i]; commandProbe *= commandProbe; if (commandProbe > commandLevel) commandLevel = commandProbe; } // computer omega supression factor float OmegaSupressor = 0.9; // -0.5 -0.3 0 0.3 0.5 -> 1 0.5 0.5 1 commandLevel = sqrt(commandLevel); if (commandLevel <= 0.7) OmegaSupressor = 0.7; else if (commandLevel < 0.9) OmegaSupressor = commandLevel; */ // apply suppression //scale3(RT_Rd_OmegaD, 0.8); // #### // ErrorOmega = Omega - RT_Rd_OmegaD float ErrorOmega[3]; subtract3(Omega, RT_Rd_OmegaD, ErrorOmega); for (int i=0; i<3; i++){ if (ErrorOmega[i]> 50.0) ErrorOmega[i] = 30.0;//50.0 else if (ErrorOmega[i]<-50.0) ErrorOmega[i] =-30.0; } // ---------> PID HERE // Desired Angular accleration should applied as output from controller for (int i=0; i<3; i++){ IErrorR[i] += ErrorR[i]*dt/1000000.0; if (IErrorR[i] > I_cut) IErrorR[i] = I_cut; if (IErrorR[1] <-I_cut) IErrorR[i] =-I_cut; } AngularAccelD[0] = - kp[0]*ErrorR[0] - ki[0]*IErrorR[0] - kd[0]*ErrorOmega[0]; AngularAccelD[1] = - kp[1]*ErrorR[1] - ki[1]*IErrorR[1] - kd[1]*ErrorOmega[1]; AngularAccelD[2] = - kp[2]*ErrorR[2] - ki[2]*IErrorR[2] - kd[2]*ErrorOmega[2]; } // Disable attitude controller //_____________________________________ void detach_attitude_controller() { // Reset Yaw desireAttitude[2] = atan2(R[1][0], R[0][0]); desireAttitude_raw[2] = desireAttitude[2]; // Reset attitude integral for(int i=0; i<3; i++){ IErrorR[i] = 0.0; } } // apply quadrotor inertia //________________________________________ void apply_body_inertia() { float J[3][3] = {{1000*Jx, 0, 0}, {0, 1000*Jy, 0}, { 0, 0, 1000*Jz}}; multiply3(J, AngularAccelD, Moment); } // Use RC throttle directly //__________________________________________________ void directRC_thrust() { averageThrust = throttleLevel; } //____________________ // For smooth take off //____________________ void smooth_takeoff_throttle() { if ((throttleDamp <=1.00 && armed) && onAir){ throttleDamp = throttleDamp+0.02; // takes 2 seconds to reach 1.00, at 50Hz } else if (!armed || !onAir) { throttleDamp = 0.00; } } //__________________________________________ // Map the controller outputs to motor commands (NED convention) //-><- //<--> void CommandQuad250() { // Body dimension matrix convertion B^(-1), float quadMat[3][3] = {{sqrt(2)/ARM_LENGTH, 0, 0}, {0, sqrt(2)/ARM_LENGTH, 0}, {0, 0, 1}}; // assume CQ=1 multiply3(quadMat, Moment, DeltaT); // Thrust Ramp Limit //averageThrust = averageThrust*throttleDamp; // Compute thrust for each axis in grams (for the sake of implicity, I did not divid it by 4 as proper inverse.) // Z y x thrust[0] = min(max_thurst, min(2.00*averageThrust, max(20.0, ( DeltaT[2] - DeltaT[1] + DeltaT[0] + averageThrust)))); thrust[1] = min(max_thurst, min(2.00*averageThrust, max(20.0, (-DeltaT[2] - DeltaT[1] - DeltaT[0] + averageThrust)))); thrust[2] = min(max_thurst, min(2.00*averageThrust, max(20.0, ( DeltaT[2] + DeltaT[1] - DeltaT[0] + averageThrust)))); thrust[3] = min(max_thurst, min(2.00*averageThrust, max(20.0, (-DeltaT[2] + DeltaT[1] + DeltaT[0] + averageThrust)))); // Convert it to arduino servo throttle thrust2throttle250_PWM_CLOSELoop(thrust, throttle); //note here 'throttle' is in pwm% // Output PWM to ESCs moveServo(throttle);//note here 'throttle' is in pwm% } #endif
Changliu52/UnicornTeensyDrone
libraries_teensy3.2/ros_lib/mavros/RadioStatus.h
#ifndef _ROS_mavros_RadioStatus_h #define _ROS_mavros_RadioStatus_h #include <stdint.h> #include <string.h> #include <stdlib.h> #include "ros/msg.h" #include "std_msgs/Header.h" namespace mavros { class RadioStatus : public ros::Msg { public: std_msgs::Header header; uint8_t rssi; uint8_t remrssi; uint8_t txbuf; uint8_t noise; uint8_t remnoise; uint16_t rxerrors; uint16_t fixed; RadioStatus(): header(), rssi(0), remrssi(0), txbuf(0), noise(0), remnoise(0), rxerrors(0), fixed(0) { } virtual int serialize(unsigned char *outbuffer) const { int offset = 0; offset += this->header.serialize(outbuffer + offset); *(outbuffer + offset + 0) = (this->rssi >> (8 * 0)) & 0xFF; offset += sizeof(this->rssi); *(outbuffer + offset + 0) = (this->remrssi >> (8 * 0)) & 0xFF; offset += sizeof(this->remrssi); *(outbuffer + offset + 0) = (this->txbuf >> (8 * 0)) & 0xFF; offset += sizeof(this->txbuf); *(outbuffer + offset + 0) = (this->noise >> (8 * 0)) & 0xFF; offset += sizeof(this->noise); *(outbuffer + offset + 0) = (this->remnoise >> (8 * 0)) & 0xFF; offset += sizeof(this->remnoise); *(outbuffer + offset + 0) = (this->rxerrors >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (this->rxerrors >> (8 * 1)) & 0xFF; offset += sizeof(this->rxerrors); *(outbuffer + offset + 0) = (this->fixed >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (this->fixed >> (8 * 1)) & 0xFF; offset += sizeof(this->fixed); return offset; } virtual int deserialize(unsigned char *inbuffer) { int offset = 0; offset += this->header.deserialize(inbuffer + offset); this->rssi = ((uint8_t) (*(inbuffer + offset))); offset += sizeof(this->rssi); this->remrssi = ((uint8_t) (*(inbuffer + offset))); offset += sizeof(this->remrssi); this->txbuf = ((uint8_t) (*(inbuffer + offset))); offset += sizeof(this->txbuf); this->noise = ((uint8_t) (*(inbuffer + offset))); offset += sizeof(this->noise); this->remnoise = ((uint8_t) (*(inbuffer + offset))); offset += sizeof(this->remnoise); this->rxerrors = ((uint16_t) (*(inbuffer + offset))); this->rxerrors |= ((uint16_t) (*(inbuffer + offset + 1))) << (8 * 1); offset += sizeof(this->rxerrors); this->fixed = ((uint16_t) (*(inbuffer + offset))); this->fixed |= ((uint16_t) (*(inbuffer + offset + 1))) << (8 * 1); offset += sizeof(this->fixed); return offset; } const char * getType(){ return "mavros/RadioStatus"; }; const char * getMD5(){ return "6f756e25cbec426b98a822e4ecb53638"; }; }; } #endif
Changliu52/UnicornTeensyDrone
libraries_teensy3.2/FreeIMU/Calibration Files/calibrationUNICON2.h
/** * FreeIMU calibration header. Automatically generated by FreeIMU_GUI. * Do not edit manually unless you know what you are doing. */ #define CALIBRATION_H const int acc_off_x = 322; const int acc_off_y = 216; const int acc_off_z = 1596; const float acc_scale_x = 16467.400206; const float acc_scale_y = 16412.632323; const float acc_scale_z = 16834.362970; const int magn_off_x = 0; const int magn_off_y = -53; const int magn_off_z = -8; const float magn_scale_x = 548.914102; const float magn_scale_y = 520.401566; const float magn_scale_z = 491.259836;
Changliu52/UnicornTeensyDrone
libraries_teensy3.2/ros_lib/mavros/CommandLong.h
<gh_stars>1-10 #ifndef _ROS_SERVICE_CommandLong_h #define _ROS_SERVICE_CommandLong_h #include <stdint.h> #include <string.h> #include <stdlib.h> #include "ros/msg.h" namespace mavros { static const char COMMANDLONG[] = "mavros/CommandLong"; class CommandLongRequest : public ros::Msg { public: uint16_t command; uint8_t confirmation; float param1; float param2; float param3; float param4; float param5; float param6; float param7; enum { CMD_DO_SET_MODE = 176 }; enum { CMD_DO_JUMP = 177 }; enum { CMD_DO_CHANGE_SPEED = 178 }; enum { CMD_DO_SET_HOME = 179 }; enum { CMD_DO_SET_RELAY = 181 }; enum { CMD_DO_REPEAT_RELAY = 182 }; enum { CMD_DO_SET_SERVO = 183 }; enum { CMD_DO_REPEAT_SERVO = 184 }; enum { CMD_DO_CONTROL_VIDEO = 200 }; enum { CMD_DO_SET_ROI = 201 }; enum { CMD_DO_MOUNT_CONTROL = 205 }; enum { CMD_DO_SET_CAM_TRIGG_DIST = 206 }; enum { CMD_DO_FENCE_ENABLE = 207 }; enum { CMD_DO_PARACHUTE = 208 }; enum { CMD_DO_INVERTED_FLOGHT = 210 }; enum { CMD_DO_MOUNT_CONTROL_QUAT = 220 }; enum { CMD_PREFLIGHT_CALIBRATION = 241 }; enum { CMD_MISSION_START = 300 }; enum { CMD_COMPONENT_ARM_DISARM = 400 }; enum { CMD_START_RX_PAIR = 500 }; CommandLongRequest(): command(0), confirmation(0), param1(0), param2(0), param3(0), param4(0), param5(0), param6(0), param7(0) { } virtual int serialize(unsigned char *outbuffer) const { int offset = 0; *(outbuffer + offset + 0) = (this->command >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (this->command >> (8 * 1)) & 0xFF; offset += sizeof(this->command); *(outbuffer + offset + 0) = (this->confirmation >> (8 * 0)) & 0xFF; offset += sizeof(this->confirmation); union { float real; uint32_t base; } u_param1; u_param1.real = this->param1; *(outbuffer + offset + 0) = (u_param1.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_param1.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_param1.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_param1.base >> (8 * 3)) & 0xFF; offset += sizeof(this->param1); union { float real; uint32_t base; } u_param2; u_param2.real = this->param2; *(outbuffer + offset + 0) = (u_param2.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_param2.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_param2.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_param2.base >> (8 * 3)) & 0xFF; offset += sizeof(this->param2); union { float real; uint32_t base; } u_param3; u_param3.real = this->param3; *(outbuffer + offset + 0) = (u_param3.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_param3.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_param3.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_param3.base >> (8 * 3)) & 0xFF; offset += sizeof(this->param3); union { float real; uint32_t base; } u_param4; u_param4.real = this->param4; *(outbuffer + offset + 0) = (u_param4.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_param4.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_param4.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_param4.base >> (8 * 3)) & 0xFF; offset += sizeof(this->param4); union { float real; uint32_t base; } u_param5; u_param5.real = this->param5; *(outbuffer + offset + 0) = (u_param5.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_param5.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_param5.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_param5.base >> (8 * 3)) & 0xFF; offset += sizeof(this->param5); union { float real; uint32_t base; } u_param6; u_param6.real = this->param6; *(outbuffer + offset + 0) = (u_param6.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_param6.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_param6.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_param6.base >> (8 * 3)) & 0xFF; offset += sizeof(this->param6); union { float real; uint32_t base; } u_param7; u_param7.real = this->param7; *(outbuffer + offset + 0) = (u_param7.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_param7.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_param7.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_param7.base >> (8 * 3)) & 0xFF; offset += sizeof(this->param7); return offset; } virtual int deserialize(unsigned char *inbuffer) { int offset = 0; this->command = ((uint16_t) (*(inbuffer + offset))); this->command |= ((uint16_t) (*(inbuffer + offset + 1))) << (8 * 1); offset += sizeof(this->command); this->confirmation = ((uint8_t) (*(inbuffer + offset))); offset += sizeof(this->confirmation); union { float real; uint32_t base; } u_param1; u_param1.base = 0; u_param1.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_param1.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_param1.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_param1.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->param1 = u_param1.real; offset += sizeof(this->param1); union { float real; uint32_t base; } u_param2; u_param2.base = 0; u_param2.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_param2.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_param2.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_param2.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->param2 = u_param2.real; offset += sizeof(this->param2); union { float real; uint32_t base; } u_param3; u_param3.base = 0; u_param3.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_param3.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_param3.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_param3.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->param3 = u_param3.real; offset += sizeof(this->param3); union { float real; uint32_t base; } u_param4; u_param4.base = 0; u_param4.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_param4.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_param4.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_param4.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->param4 = u_param4.real; offset += sizeof(this->param4); union { float real; uint32_t base; } u_param5; u_param5.base = 0; u_param5.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_param5.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_param5.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_param5.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->param5 = u_param5.real; offset += sizeof(this->param5); union { float real; uint32_t base; } u_param6; u_param6.base = 0; u_param6.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_param6.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_param6.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_param6.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->param6 = u_param6.real; offset += sizeof(this->param6); union { float real; uint32_t base; } u_param7; u_param7.base = 0; u_param7.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_param7.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_param7.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_param7.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->param7 = u_param7.real; offset += sizeof(this->param7); return offset; } const char * getType(){ return COMMANDLONG; }; const char * getMD5(){ return "5972d4d8225f9d160bb683f0834762b4"; }; }; class CommandLongResponse : public ros::Msg { public: bool success; uint8_t result; CommandLongResponse(): success(0), result(0) { } virtual int serialize(unsigned char *outbuffer) const { int offset = 0; union { bool real; uint8_t base; } u_success; u_success.real = this->success; *(outbuffer + offset + 0) = (u_success.base >> (8 * 0)) & 0xFF; offset += sizeof(this->success); *(outbuffer + offset + 0) = (this->result >> (8 * 0)) & 0xFF; offset += sizeof(this->result); return offset; } virtual int deserialize(unsigned char *inbuffer) { int offset = 0; union { bool real; uint8_t base; } u_success; u_success.base = 0; u_success.base |= ((uint8_t) (*(inbuffer + offset + 0))) << (8 * 0); this->success = u_success.real; offset += sizeof(this->success); this->result = ((uint8_t) (*(inbuffer + offset))); offset += sizeof(this->result); return offset; } const char * getType(){ return COMMANDLONG; }; const char * getMD5(){ return "1cd894375e4e3d2861d2222772894fdb"; }; }; class CommandLong { public: typedef CommandLongRequest Request; typedef CommandLongResponse Response; }; } #endif
Changliu52/UnicornTeensyDrone
libraries_teensy3.2/ros_lib/vi_ekf/teensyPilot.h
<reponame>Changliu52/UnicornTeensyDrone #ifndef _ROS_vi_ekf_teensyPilot_h #define _ROS_vi_ekf_teensyPilot_h #include <stdint.h> #include <string.h> #include <stdlib.h> #include "ros/msg.h" namespace vi_ekf { class teensyPilot : public ros::Msg { public: float qw; float qx; float qy; float qz; float px; float py; float pz; float vx; float vy; float vz; float bx; float by; float bz; float lambda; int8_t status; teensyPilot(): qw(0), qx(0), qy(0), qz(0), px(0), py(0), pz(0), vx(0), vy(0), vz(0), bx(0), by(0), bz(0), lambda(0), status(0) { } virtual int serialize(unsigned char *outbuffer) const { int offset = 0; union { float real; uint32_t base; } u_qw; u_qw.real = this->qw; *(outbuffer + offset + 0) = (u_qw.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_qw.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_qw.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_qw.base >> (8 * 3)) & 0xFF; offset += sizeof(this->qw); union { float real; uint32_t base; } u_qx; u_qx.real = this->qx; *(outbuffer + offset + 0) = (u_qx.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_qx.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_qx.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_qx.base >> (8 * 3)) & 0xFF; offset += sizeof(this->qx); union { float real; uint32_t base; } u_qy; u_qy.real = this->qy; *(outbuffer + offset + 0) = (u_qy.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_qy.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_qy.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_qy.base >> (8 * 3)) & 0xFF; offset += sizeof(this->qy); union { float real; uint32_t base; } u_qz; u_qz.real = this->qz; *(outbuffer + offset + 0) = (u_qz.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_qz.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_qz.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_qz.base >> (8 * 3)) & 0xFF; offset += sizeof(this->qz); union { float real; uint32_t base; } u_px; u_px.real = this->px; *(outbuffer + offset + 0) = (u_px.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_px.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_px.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_px.base >> (8 * 3)) & 0xFF; offset += sizeof(this->px); union { float real; uint32_t base; } u_py; u_py.real = this->py; *(outbuffer + offset + 0) = (u_py.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_py.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_py.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_py.base >> (8 * 3)) & 0xFF; offset += sizeof(this->py); union { float real; uint32_t base; } u_pz; u_pz.real = this->pz; *(outbuffer + offset + 0) = (u_pz.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_pz.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_pz.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_pz.base >> (8 * 3)) & 0xFF; offset += sizeof(this->pz); union { float real; uint32_t base; } u_vx; u_vx.real = this->vx; *(outbuffer + offset + 0) = (u_vx.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_vx.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_vx.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_vx.base >> (8 * 3)) & 0xFF; offset += sizeof(this->vx); union { float real; uint32_t base; } u_vy; u_vy.real = this->vy; *(outbuffer + offset + 0) = (u_vy.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_vy.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_vy.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_vy.base >> (8 * 3)) & 0xFF; offset += sizeof(this->vy); union { float real; uint32_t base; } u_vz; u_vz.real = this->vz; *(outbuffer + offset + 0) = (u_vz.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_vz.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_vz.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_vz.base >> (8 * 3)) & 0xFF; offset += sizeof(this->vz); union { float real; uint32_t base; } u_bx; u_bx.real = this->bx; *(outbuffer + offset + 0) = (u_bx.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_bx.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_bx.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_bx.base >> (8 * 3)) & 0xFF; offset += sizeof(this->bx); union { float real; uint32_t base; } u_by; u_by.real = this->by; *(outbuffer + offset + 0) = (u_by.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_by.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_by.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_by.base >> (8 * 3)) & 0xFF; offset += sizeof(this->by); union { float real; uint32_t base; } u_bz; u_bz.real = this->bz; *(outbuffer + offset + 0) = (u_bz.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_bz.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_bz.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_bz.base >> (8 * 3)) & 0xFF; offset += sizeof(this->bz); union { float real; uint32_t base; } u_lambda; u_lambda.real = this->lambda; *(outbuffer + offset + 0) = (u_lambda.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_lambda.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_lambda.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_lambda.base >> (8 * 3)) & 0xFF; offset += sizeof(this->lambda); union { int8_t real; uint8_t base; } u_status; u_status.real = this->status; *(outbuffer + offset + 0) = (u_status.base >> (8 * 0)) & 0xFF; offset += sizeof(this->status); return offset; } virtual int deserialize(unsigned char *inbuffer) { int offset = 0; union { float real; uint32_t base; } u_qw; u_qw.base = 0; u_qw.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_qw.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_qw.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_qw.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->qw = u_qw.real; offset += sizeof(this->qw); union { float real; uint32_t base; } u_qx; u_qx.base = 0; u_qx.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_qx.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_qx.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_qx.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->qx = u_qx.real; offset += sizeof(this->qx); union { float real; uint32_t base; } u_qy; u_qy.base = 0; u_qy.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_qy.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_qy.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_qy.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->qy = u_qy.real; offset += sizeof(this->qy); union { float real; uint32_t base; } u_qz; u_qz.base = 0; u_qz.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_qz.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_qz.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_qz.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->qz = u_qz.real; offset += sizeof(this->qz); union { float real; uint32_t base; } u_px; u_px.base = 0; u_px.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_px.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_px.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_px.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->px = u_px.real; offset += sizeof(this->px); union { float real; uint32_t base; } u_py; u_py.base = 0; u_py.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_py.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_py.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_py.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->py = u_py.real; offset += sizeof(this->py); union { float real; uint32_t base; } u_pz; u_pz.base = 0; u_pz.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_pz.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_pz.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_pz.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->pz = u_pz.real; offset += sizeof(this->pz); union { float real; uint32_t base; } u_vx; u_vx.base = 0; u_vx.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_vx.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_vx.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_vx.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->vx = u_vx.real; offset += sizeof(this->vx); union { float real; uint32_t base; } u_vy; u_vy.base = 0; u_vy.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_vy.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_vy.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_vy.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->vy = u_vy.real; offset += sizeof(this->vy); union { float real; uint32_t base; } u_vz; u_vz.base = 0; u_vz.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_vz.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_vz.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_vz.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->vz = u_vz.real; offset += sizeof(this->vz); union { float real; uint32_t base; } u_bx; u_bx.base = 0; u_bx.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_bx.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_bx.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_bx.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->bx = u_bx.real; offset += sizeof(this->bx); union { float real; uint32_t base; } u_by; u_by.base = 0; u_by.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_by.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_by.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_by.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->by = u_by.real; offset += sizeof(this->by); union { float real; uint32_t base; } u_bz; u_bz.base = 0; u_bz.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_bz.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_bz.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_bz.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->bz = u_bz.real; offset += sizeof(this->bz); union { float real; uint32_t base; } u_lambda; u_lambda.base = 0; u_lambda.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_lambda.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_lambda.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_lambda.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->lambda = u_lambda.real; offset += sizeof(this->lambda); union { int8_t real; uint8_t base; } u_status; u_status.base = 0; u_status.base |= ((uint8_t) (*(inbuffer + offset + 0))) << (8 * 0); this->status = u_status.real; offset += sizeof(this->status); return offset; } const char * getType(){ return "vi_ekf/teensyPilot"; }; const char * getMD5(){ return "f7c0a5df511c8bd0f4fea596f54972b0"; }; }; } #endif
Changliu52/UnicornTeensyDrone
unicorn/AccelController.h
//©2016 <NAME> #ifndef __Accel_Controller_H__ #define __Accel_Controller_H__ #include <Arduino.h> // function to Convert desired acceleration vector to desired thrust and desired attitude. // Note: dt is in micro-seconds void accel_2_attitudeThrust() { // Make sure not close to shut down motors or reverse flying (need better codes!!) for (int i=0; i<3; i++) { if (accelD_smt[i] <-2.50) accelD_smt[i] =-2.50; else if (accelD_smt[i] > 2.50) accelD_smt[i] = 2.50; } // compute total thrust vector in world frame // thrust_v = force_v - mg_v float force_v[3]; scale3(accelD_smt, M_QUAD, force_v); float mg_v[3] = {0, 0, -M_QUAD*g}; float thrust_v[3]; subtract3(force_v, mg_v, thrust_v); // totolThust = ||thrust_v|| float totalThrust = norm3(thrust_v); // acceleration limit: beta * force_v = mg_v + thrust_v; && ||thrust_v|| = max_total_thrust float max_total_thrust = 4.00*max_thurst*0.9*g/1000.00; // 90% max throttle in N if (totalThrust > max_total_thrust) { float a = norm3(force_v); a = a*a; float b = -2*force_v[2]*mg_v[2]; float c = (mg_v[2]*mg_v[2]) - (max_total_thrust*max_total_thrust); float beta = (-b + sqrt(b*b-(4*a*c)))/2/a; scale3(force_v, beta); subtract3(force_v, mg_v, thrust_v); totalThrust = max_total_thrust; //Serial.println(beta); } // average thrust for each rotor is averageThust = ||thrust_v||/4 averageThrust = totalThrust/4.00; // in N averageThrust = averageThrust*1000.00/g; // convert to gram (Convert averageThrust to gram for PololuServo) // rescale Bd_z to unit vector (z-axis of the desired body frame) float Bd_z[3]; scale3(thrust_v, 1.00/totalThrust, Bd_z); //______ // Compute inital Bd_x (x-axis of the desired body frame in world xy plane) float Bd_x[3]; Bd_x[0] = cos(desireAttitude[2]); Bd_x[1] = sin(desireAttitude[2]); Bd_x[2] = 0; // Compute Bd_y = (Bd_z X Bd_x)/||Bd_z X Bd_x|| (y-axis of the desired body frame) float Bd_y[3]; cross3(Bd_z, Bd_x, Bd_y); float Bd_yNorm = norm3(Bd_y); if(Bd_yNorm > 0.001){ // Make sure Bd_y is not parallel with Bd_z!! scale3(Bd_y, 1/norm3(Bd_y)); // Compute real Bd_x = Bd_y X Bd_z (project it to the plane normal to Bd_z) cross3(Bd_y, Bd_z, Bd_x); //----> Compute Rd if (Bd_x[0] + Bd_y[1] + Bd_z[2]> -0.999 || Bd_x[0] + Bd_y[1] + Bd_z[2]< -1.001){ // check reverse rotation Rd[0][0] = Bd_x[0]; Rd[0][1] = Bd_y[0]; Rd[0][2] = Bd_z[0]; Rd[1][0] = Bd_x[1]; Rd[1][1] = Bd_y[1]; Rd[1][2] = Bd_z[1]; Rd[2][0] = Bd_x[2]; Rd[2][1] = Bd_y[2]; Rd[2][2] = Bd_z[2]; //----> Compute DotRd = (Rd - RdOld)/dt float timenow = micros(); float dt = timenow - Rd_timer_last; Rd_timer_last = timenow; if (dt > 0.0) {// && dt < 40000.0) { // make sure we have reasonable timing (assumes runing at 50 Hz but allow minimium 25 Hz) //if (dt > 40000.0) dt = 20000.0; // smooth transation (assmue 50 hz) subtract3(Rd, RdOld, DotRd); scale3(DotRd, 1000000.00f/dt); // sin(Rad)/s ~= Rad/s } copy3(Rd, RdOld); // Log old Rd } } } #endif
Changliu52/UnicornTeensyDrone
libraries_teensy3.2/ros_lib/mavros/Mavlink.h
#ifndef _ROS_mavros_Mavlink_h #define _ROS_mavros_Mavlink_h #include <stdint.h> #include <string.h> #include <stdlib.h> #include "ros/msg.h" #include "std_msgs/Header.h" namespace mavros { class Mavlink : public ros::Msg { public: std_msgs::Header header; uint8_t len; uint8_t seq; uint8_t sysid; uint8_t compid; uint8_t msgid; bool fromlcm; uint8_t payload64_length; uint64_t st_payload64; uint64_t * payload64; Mavlink(): header(), len(0), seq(0), sysid(0), compid(0), msgid(0), fromlcm(0), payload64_length(0), payload64(NULL) { } virtual int serialize(unsigned char *outbuffer) const { int offset = 0; offset += this->header.serialize(outbuffer + offset); *(outbuffer + offset + 0) = (this->len >> (8 * 0)) & 0xFF; offset += sizeof(this->len); *(outbuffer + offset + 0) = (this->seq >> (8 * 0)) & 0xFF; offset += sizeof(this->seq); *(outbuffer + offset + 0) = (this->sysid >> (8 * 0)) & 0xFF; offset += sizeof(this->sysid); *(outbuffer + offset + 0) = (this->compid >> (8 * 0)) & 0xFF; offset += sizeof(this->compid); *(outbuffer + offset + 0) = (this->msgid >> (8 * 0)) & 0xFF; offset += sizeof(this->msgid); union { bool real; uint8_t base; } u_fromlcm; u_fromlcm.real = this->fromlcm; *(outbuffer + offset + 0) = (u_fromlcm.base >> (8 * 0)) & 0xFF; offset += sizeof(this->fromlcm); *(outbuffer + offset++) = payload64_length; *(outbuffer + offset++) = 0; *(outbuffer + offset++) = 0; *(outbuffer + offset++) = 0; for( uint8_t i = 0; i < payload64_length; i++){ union { uint64_t real; uint32_t base; } u_payload64i; u_payload64i.real = this->payload64[i]; *(outbuffer + offset + 0) = (u_payload64i.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_payload64i.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_payload64i.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_payload64i.base >> (8 * 3)) & 0xFF; offset += sizeof(this->payload64[i]); } return offset; } virtual int deserialize(unsigned char *inbuffer) { int offset = 0; offset += this->header.deserialize(inbuffer + offset); this->len = ((uint8_t) (*(inbuffer + offset))); offset += sizeof(this->len); this->seq = ((uint8_t) (*(inbuffer + offset))); offset += sizeof(this->seq); this->sysid = ((uint8_t) (*(inbuffer + offset))); offset += sizeof(this->sysid); this->compid = ((uint8_t) (*(inbuffer + offset))); offset += sizeof(this->compid); this->msgid = ((uint8_t) (*(inbuffer + offset))); offset += sizeof(this->msgid); union { bool real; uint8_t base; } u_fromlcm; u_fromlcm.base = 0; u_fromlcm.base |= ((uint8_t) (*(inbuffer + offset + 0))) << (8 * 0); this->fromlcm = u_fromlcm.real; offset += sizeof(this->fromlcm); uint8_t payload64_lengthT = *(inbuffer + offset++); if(payload64_lengthT > payload64_length) this->payload64 = (uint64_t*)realloc(this->payload64, payload64_lengthT * sizeof(uint64_t)); offset += 3; payload64_length = payload64_lengthT; for( uint8_t i = 0; i < payload64_length; i++){ union { uint64_t real; uint32_t base; } u_st_payload64; u_st_payload64.base = 0; u_st_payload64.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_st_payload64.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_st_payload64.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_st_payload64.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->st_payload64 = u_st_payload64.real; offset += sizeof(this->st_payload64); memcpy( &(this->payload64[i]), &(this->st_payload64), sizeof(uint64_t)); } return offset; } const char * getType(){ return "mavros/Mavlink"; }; const char * getMD5(){ return "3513d96e87d97146fed4643086047ddd"; }; }; } #endif
Changliu52/UnicornTeensyDrone
libraries_teensy3.2/ros_lib/mavros/WaypointPush.h
<gh_stars>1-10 #ifndef _ROS_SERVICE_WaypointPush_h #define _ROS_SERVICE_WaypointPush_h #include <stdint.h> #include <string.h> #include <stdlib.h> #include "ros/msg.h" #include "mavros/Waypoint.h" namespace mavros { static const char WAYPOINTPUSH[] = "mavros/WaypointPush"; class WaypointPushRequest : public ros::Msg { public: uint8_t waypoints_length; mavros::Waypoint st_waypoints; mavros::Waypoint * waypoints; WaypointPushRequest(): waypoints_length(0), waypoints(NULL) { } virtual int serialize(unsigned char *outbuffer) const { int offset = 0; *(outbuffer + offset++) = waypoints_length; *(outbuffer + offset++) = 0; *(outbuffer + offset++) = 0; *(outbuffer + offset++) = 0; for( uint8_t i = 0; i < waypoints_length; i++){ offset += this->waypoints[i].serialize(outbuffer + offset); } return offset; } virtual int deserialize(unsigned char *inbuffer) { int offset = 0; uint8_t waypoints_lengthT = *(inbuffer + offset++); if(waypoints_lengthT > waypoints_length) this->waypoints = (mavros::Waypoint*)realloc(this->waypoints, waypoints_lengthT * sizeof(mavros::Waypoint)); offset += 3; waypoints_length = waypoints_lengthT; for( uint8_t i = 0; i < waypoints_length; i++){ offset += this->st_waypoints.deserialize(inbuffer + offset); memcpy( &(this->waypoints[i]), &(this->st_waypoints), sizeof(mavros::Waypoint)); } return offset; } const char * getType(){ return WAYPOINTPUSH; }; const char * getMD5(){ return "9e87303e70921b453f266db2c0ff55c3"; }; }; class WaypointPushResponse : public ros::Msg { public: bool success; uint32_t wp_transfered; WaypointPushResponse(): success(0), wp_transfered(0) { } virtual int serialize(unsigned char *outbuffer) const { int offset = 0; union { bool real; uint8_t base; } u_success; u_success.real = this->success; *(outbuffer + offset + 0) = (u_success.base >> (8 * 0)) & 0xFF; offset += sizeof(this->success); *(outbuffer + offset + 0) = (this->wp_transfered >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (this->wp_transfered >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (this->wp_transfered >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (this->wp_transfered >> (8 * 3)) & 0xFF; offset += sizeof(this->wp_transfered); return offset; } virtual int deserialize(unsigned char *inbuffer) { int offset = 0; union { bool real; uint8_t base; } u_success; u_success.base = 0; u_success.base |= ((uint8_t) (*(inbuffer + offset + 0))) << (8 * 0); this->success = u_success.real; offset += sizeof(this->success); this->wp_transfered = ((uint32_t) (*(inbuffer + offset))); this->wp_transfered |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); this->wp_transfered |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); this->wp_transfered |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); offset += sizeof(this->wp_transfered); return offset; } const char * getType(){ return WAYPOINTPUSH; }; const char * getMD5(){ return "90e0074a42480231d34eed864d14365e"; }; }; class WaypointPush { public: typedef WaypointPushRequest Request; typedef WaypointPushResponse Response; }; } #endif
Changliu52/UnicornTeensyDrone
libraries_teensy3.2/FreeIMU/Calibration Files/calibration250.h
/** * FreeIMU calibration header. Automatically generated by FreeIMU_GUI. * Do not edit manually unless you know what you are doing. */ #define CALIBRATION_H const int acc_off_x = 43; const int acc_off_y = -71; const int acc_off_z = 1414; const float acc_scale_x = 16466.404159; const float acc_scale_y = 16502.275454; const float acc_scale_z = 16711.110165; const int magn_off_x = -1; const int magn_off_y = -67; const int magn_off_z = -26; const float magn_scale_x = 524.399730; const float magn_scale_y = 491.219696; const float magn_scale_z = 473.890738;
Changliu52/UnicornTeensyDrone
unicorn/PositionController.h
<gh_stars>1-10 //©2016 <NAME> #ifndef POSITION_CONTROLLER_H_ #define POSITION_CONTROLLER_H_ #include "AccelController.h" #include "AttitudeController.h" #include "spektrumSatil.h" #include "ESC_PWM.h" #include <Arduino.h> //####################### // ACCELERATION controller (this controller update RATE is driven by the vision update RATE) //####################### void attach_acceleration_controller() { for (int i=0; i<3; i++) { // PID-a controller accelD[i] = accel_user[i] - (kp_i[2]*position_integ[i]) - (kp_p[1]*acceSmt[i]);//pida controller // Limit acceleration command output if (accelD[i] > 4.00) accelD[i] =4.00; else if (accelD[i] < -4.00) accelD[i] =-4.00; } } //####################### // POSITION controller (this controller update RATE is driven by the vision update RATE) //####################### void attach_position_controller() { // check odroid disconnection (running at mainloop speed) make sure to copy this into detach_positon_controller() (with some changes!) if (!vision_new_measurment_) { if (odroid_lost_count_ < LOOP_HZ) odroid_lost_count_++; else vision_available_ = 4; return; } else odroid_lost_count_ = 0; // Position Control: Compute desired acceleration vector float timenow = micros(); // update controller if (timenow > position_timer && position_timer > 0.0001) { float dt = timenow - position_timer; for (int i=0; i<3; i++) { // velocity error float veloError = 0.00; if(i<2) veloError = vVision[i]-veloD[i]; else veloError = vVision[i]; // limit differential if (veloError > 3.00) veloError = 3.00; else if (veloError <-3.00) veloError =-3.00; // position integral error float posiError = pVision[i]-posiD[i]; if (veloError > -kp_i[1] && veloError < kp_i[1]){ // only accumulate in slow motion if (posiError > 0.5) posiError = 0.5; // set maximum integral steps if (posiError < -0.5) posiError = -0.5; position_integ[i] += posiError * dt/1000000.0; } if(position_integ[i] > 2.0) position_integ[i] = 2.0; //limit max integral part if(position_integ[i] <-2.0) position_integ[i] =-2.0; // PID-a controller accelD[i] = - (kp_p[0] *posiError) - (kp_d[0] *veloError) - (kp_i[0]*position_integ[i]) - (kp_a*acceSmt[i]);//pida controller // Limit acceleration command output if (accelD[i] > 4.00) accelD[i] =4.00; else if (accelD[i] < -4.00) accelD[i] =-4.00; } } // update timer position_timer = timenow; // reset new vision update flag vision_new_measurment_ = 0; } // detach position controller //___________________________ void detach_position_controller() { // check odroid disconnection (running at mainloop speed) if (!vision_new_measurment_) { if (odroid_lost_count_ < LOOP_HZ) odroid_lost_count_++; else vision_available_ = 4; } else { vision_new_measurment_ = 0; odroid_lost_count_ = 0; } // reset position timer position_timer = micros(); // reset position integral if(!armed||!onAir){ for (int i=0; i<3; i++) {position_integ[i] = 0.00;} } } //######################## // filter all the acceleration command from outer controller to inner controller //######################## void filter_accel_d() { for (int i=0; i<3; i++){ filter_value(accelD+i, accelD_smt+i, kp_d[1]); } } //###################### // Automatic control process //###################### //—————————————————————— // RC void auto_control_process_RC(float timeChange) { // When vision is available and finished smooth transation, then only do manual control conversion if(vision_available_ ==1 && newMap ==0){ // newMap for smooth transation convert_RC_velo(); compute_velo2posi(timeChange/1000000.0); // When vision is NOT available, or in the smooth transation } else { convert_RC_accel(); filter_accel_d(); attach_acceleration_controller(); detach_position_controller(); // reset vision controller // Convert accel to attitude and thrust accel_2_attitudeThrust(); } } //______________________ // OUTTER void auto_control_process_OUTTER() { // When vision is available and finished smooth transation if(vision_available_ ==1 && newMap ==0){ // newMap for smooth transation attach_position_controller(); // Filter outter controller output filter_accel_d(); // Convert accel to attitude and thrust accel_2_attitudeThrust(); } } //______________________ // INNER void auto_control_process_INNER(float timeChange) { attach_attitude_controller(timeChange); apply_body_inertia(); CommandQuad250(); } #endif
Changliu52/UnicornTeensyDrone
libraries_teensy3.2/ros_lib/mavros/WaypointList.h
#ifndef _ROS_mavros_WaypointList_h #define _ROS_mavros_WaypointList_h #include <stdint.h> #include <string.h> #include <stdlib.h> #include "ros/msg.h" #include "mavros/Waypoint.h" namespace mavros { class WaypointList : public ros::Msg { public: uint8_t waypoints_length; mavros::Waypoint st_waypoints; mavros::Waypoint * waypoints; WaypointList(): waypoints_length(0), waypoints(NULL) { } virtual int serialize(unsigned char *outbuffer) const { int offset = 0; *(outbuffer + offset++) = waypoints_length; *(outbuffer + offset++) = 0; *(outbuffer + offset++) = 0; *(outbuffer + offset++) = 0; for( uint8_t i = 0; i < waypoints_length; i++){ offset += this->waypoints[i].serialize(outbuffer + offset); } return offset; } virtual int deserialize(unsigned char *inbuffer) { int offset = 0; uint8_t waypoints_lengthT = *(inbuffer + offset++); if(waypoints_lengthT > waypoints_length) this->waypoints = (mavros::Waypoint*)realloc(this->waypoints, waypoints_lengthT * sizeof(mavros::Waypoint)); offset += 3; waypoints_length = waypoints_lengthT; for( uint8_t i = 0; i < waypoints_length; i++){ offset += this->st_waypoints.deserialize(inbuffer + offset); memcpy( &(this->waypoints[i]), &(this->st_waypoints), sizeof(mavros::Waypoint)); } return offset; } const char * getType(){ return "mavros/WaypointList"; }; const char * getMD5(){ return "9e87303e70921b453f266db2c0ff55c3"; }; }; } #endif
Changliu52/UnicornTeensyDrone
libraries_teensy3.2/rbuf/rbuf.h
// // simple ring buffer class // #ifndef RBUF_H #define RBUF_H #include <inttypes.h> // if used for debug adjust buffer size depending on how verbose messages are and // in/out rates - overflows are blocked prior to add #define RBUF_SIZE 2048 class rbuf { public: rbuf(); ~rbuf(); // functions void empty(); uint16_t len(); uint8_t putI(uint8_t Data); uint8_t putAHex(uint8_t Data); uint8_t put(uint8_t* pData); uint8_t get(uint8_t* pData); uint8_t getI(); uint8_t putWordI(uint16_t Data); uint8_t putWord(uint16_t* pData); uint8_t getWord(uint16_t* pData); uint8_t putBlock(const void* vpData, uint16_t Length); uint8_t getBlock(void* vpData, uint16_t Length); private: // variables volatile uint8_t m_Buffer[RBUF_SIZE]; volatile uint8_t* m_pIn; volatile uint8_t* m_pOut; volatile uint16_t m_Length; }; #endif
Changliu52/UnicornTeensyDrone
libraries_teensy3.2/FreeIMU/Calibration Files/calibrationUNICON.h
<reponame>Changliu52/UnicornTeensyDrone /** * FreeIMU calibration header. Automatically generated by FreeIMU_GUI. * Do not edit manually unless you know what you are doing. */ #define CALIBRATION_H const int acc_off_x = 204; const int acc_off_y = -11; const int acc_off_z = 2033; const float acc_scale_x = 16310.204894; const float acc_scale_y = 16369.693317; const float acc_scale_z = 16672.439290; const int magn_off_x = -49; const int magn_off_y = -70; const int magn_off_z = 23; const float magn_scale_x = 535.920637; const float magn_scale_y = 499.238496; const float magn_scale_z = 453.973802;
Changliu52/UnicornTeensyDrone
unicorn/globleVairbles.h
//©2016 <NAME> #ifndef Globle_variables_h #define Globle_variables_h //_______________________________ // User Defines #define SAMPLING_RATE 2500.00f // micro seconds, 400Hz (remember to change loop_hz)!!!!! #define LOOP_HZ 400 // loop hz (must change accordingly with Sampling_rate)!! #define M_QUAD 0.63f // in kg !!!!!!!!!!!!####### CHECK THIS BEFORE FLIGHT############ #define ARM_LENGTH 240.00f // in mm #define Jx 0.012795f // in kgxcm2 #define Jy 0.012879f // in kgxcm2 #define Jz 0.023746f // in kgxcm2 #define pi 3.1415927f #define g 9.8f float QuadCenInVis[4] = {0.0, -0.055, 0.0, 0.075}; // in meter //__________________________________ // Flags for Finite State Machine boolean armed, onAir, enableControl = 0; boolean initialised = 0; uint8_t initCount = 0; float lastR22 = 0; //_____________________________ // Global Objects and Variables // Serial Ports HardwareSerial* XBeeSerial = &Serial3; HardwareSerial* SpectrumSerial = &Serial2; HardwareSerial* FlowSerial = &Serial1; // Set the FreeIMU object FreeIMU my3IMU = FreeIMU(); // Controllers //____________________________________ // Initial Gain Parameters // attitude controller gain float kp[3] = {2600.00, 2800.00, 10.00}; // {2600.00, 2800.00, 10.00}; // x y z {2400.00, 2400.00, 15.00}; 500 no odroid float ki[3] = {130.0, 150.0, 0.0}; // {130.0, 150.0, 0.0}; float kd[3] = {300.00, 400.00, 5.00}; // {320.00, 420.00, 5.00}; // x y z {530.00, 530.00, 10.00}; 200 no odroid const float I_cut = 0.5; const float thrustRampLimit = 500.0; // in gram (500 g allow max) // position controller gain float kp_p[3] = {1.6, 0.0, 0.0}; // p v_cf X 2.0 0.0 0.0 float kp_i[3] = {0.6, 0.5, 0.0}; // i velo_thres X 0.6 0.5 0.0 float kp_d[3] = {7.0, 20.0, 0.0}; // d ac_d_smoth X 6.0 20.0 0.0 float kp_a = 4.00; // velocity controller gain float kvp[3] = {3.20, 3.20, 8.00}; //x y altitude float kvi[3] = {0.70, 0.00, 0.00}; //x y altitude float kvd[3] = {5.00, 5.00, 12.00}; //x y altitude // Attitude controller Variables //__________________________________________________ float R[3][3] = {{1.00,0.00,0.00},{0.00,1.00,0.00},{0.00,0.00,1.00}}; float Rd[3][3] = {{1.00,0.00,0.00},{0.00,1.00,0.00},{0.00,0.00,1.00}}; float RdOld[3][3] = {{1.00,0.00,0.00},{0.00,1.00,0.00},{0.00,0.00,1.00}}; float DotRd[3][3] = {{0.00,0.00,0.00},{0.00,0.00,0.00},{0.00,0.00,0.00}}; float IErrorR[3] = {0.00, 0.00, 0.00}; // integral of attitude error float Omega[3] = {0.00, 0.00, 0.00}; // Gyro reading in rad/s float OmegaOld[3] = {0.00, 0.00, 0.00}; // Gyro reading in rad/s float DotOmega[3] = {0.00, 0.00, 0.00}; // angular acceleration reading in rad/s/s float AngularAccelD[3] = {0.00, 0.00, 0.00}; // Controller output float Moment[3] = {0.00, 0.00, 0.00}; // required moment after computing inertia float DeltaT[3] = {0.00, 0.00, 0.00}; //x,y,z float thrust[4] = {0.00, 0.00, 0.00, 0.00}; // expected thrust generated by each axis in gram float throttle[4] = {0.00, 0.00, 0.00, 0.00}; // expected throttle given to each motor in servo 0-180 float throttleDamp = 0.00; // scales down throttle level for smooth takeoff // Accel Controller //___________________________________ float accelD[3] = {0.00, 0.00, 0.00}; // x, y, z (front-left-up) in world frame float accelD_smt[3] = {0.00, 0.00, 0.00}; // Position controller //___________________________________ float position_timer = 0.00; float position_integ[3] = {0.00, 0.00, 0.00}; float posiD[3] = {0.00, 0.00, 0.00}; // x, y, z (m) in world frame float posAltiOffset = 0.00; int newMap = 100; float pVision_cf[3] = {0.00, 0.00, 0.00}; // position value after complementary filter float vVision_cf[3] = {0.00, 0.00, 0.00}; // velocity value after complementary filter float SVO_cf_ofset[3] = {0.00, 0.00, 0.00}; // IMU //___________________________________ float acce[4] = {0.00, 0.00, 0.00, 0.00}; // rotation invariant body acceleration with respect to earth {0,x,y,z} (front-left-up) in g float acceSmt[3] = {0.00, 0.00, 0.00}; // rotation invariant body acceleration with respect to earth {x,y,z} (front-left-up) in g float velocityIMU[3] = {0.00, 0.00, 0.00}; float AltiOutput[3] = {0.00, 0.00, 0.00}; // {verticalVelocity, altitude, gravityCompensationScale} float q[4] = {0.00, 0.00, 0.00, 0.00}; // w,x,y,z output from IMU fusion //float OmegaBufferX[64]; //float OmegaBufferY[64]; uint8_t gyroDelayCounter = 0; float omega_w[2] = {0.00, 0.00}; // delayed omega in body frame (world {x-axis, y-axis} compensation) float omegaDelay_w[2]= {0.00, 0.00}; // delayed gyro omega measurement in WORLD frame to sync with vision // RC controller //____________________________________ float desireAttitude[3] = {0.00,0.00,0.00}; // rotate angle around body frame axis {x, y,z} (front-left-up) float desireAttitude_raw[3] = {0.00,0.00,0.00}; float throttleLevel = 0.00; // altitude command from controller float throttleLevel_raw = 0.00; float accel_user[3] = {0.00,0.00,0.00}; float Rd_timer_last = 0.00; float accel_timer_last= 0.00; float velo_timer_last = 0.00; float veloD[3] = {0.00, 0.00, 0.00}; // x, y, z(altitude) (front-left-up) float veloDold[3] = {0.00, 0.00, 0.00}; float DotVeloD[3] = {0.00, 0.00, 0.00}; // SELFIE //____________________________________ #define selfie_pin 6 boolean selfie_lock = 0; float selfie_timer = 0.0; #define selfieDISARM 0 #define selfieMINSPIN 1 #define selfieACTIVE 2 int selfie_state = selfieDISARM; // ESC //___________________________________ float averageThrust = 0.00; float averageThrust_last = 0.00; // Thrust limit #define max_thurst 450.0 // in grams for one motor // ROS interface //_____________________________________ float pVision[3] = {0.00, 0.00, 0.00}; float vVision[3] = {0.00, 0.00, 0.00}; float vVision_raw[3] = {0.00, 0.00, 0.00}; float qVision[4] = {0.00, 0.00, 0.00, 0.00}; float lambdaVision = 1.00; float VIbias_accel[3] = {0.00, 0.00, 0.00}; float init_position[3] = {0.0, 0.0, 0.0}; int8_t vision_available_ = 4; bool vision_new_measurment_ = 0; uint16_t odroid_lost_count_ = 0; // counter to check odroid connection lost #define slamLED 5 // ROS related float rosStatus = 0.0; // this is used to log the loop time (in microS) of the extremely slow loop (guessed due to ros com) about 0.2s ros::NodeHandle nh; #include "odroidListener.h" vi_ekf::odroidListener ros_listener; tf::IMUBroadcaster imu_broadcaster; #endif
Changliu52/UnicornTeensyDrone
libraries_teensy3.2/ros_lib/mavros/CommandTOL.h
<gh_stars>1-10 #ifndef _ROS_SERVICE_CommandTOL_h #define _ROS_SERVICE_CommandTOL_h #include <stdint.h> #include <string.h> #include <stdlib.h> #include "ros/msg.h" namespace mavros { static const char COMMANDTOL[] = "mavros/CommandTOL"; class CommandTOLRequest : public ros::Msg { public: float min_pitch; float yaw; float latitude; float longitude; float altitude; CommandTOLRequest(): min_pitch(0), yaw(0), latitude(0), longitude(0), altitude(0) { } virtual int serialize(unsigned char *outbuffer) const { int offset = 0; union { float real; uint32_t base; } u_min_pitch; u_min_pitch.real = this->min_pitch; *(outbuffer + offset + 0) = (u_min_pitch.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_min_pitch.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_min_pitch.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_min_pitch.base >> (8 * 3)) & 0xFF; offset += sizeof(this->min_pitch); union { float real; uint32_t base; } u_yaw; u_yaw.real = this->yaw; *(outbuffer + offset + 0) = (u_yaw.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_yaw.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_yaw.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_yaw.base >> (8 * 3)) & 0xFF; offset += sizeof(this->yaw); union { float real; uint32_t base; } u_latitude; u_latitude.real = this->latitude; *(outbuffer + offset + 0) = (u_latitude.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_latitude.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_latitude.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_latitude.base >> (8 * 3)) & 0xFF; offset += sizeof(this->latitude); union { float real; uint32_t base; } u_longitude; u_longitude.real = this->longitude; *(outbuffer + offset + 0) = (u_longitude.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_longitude.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_longitude.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_longitude.base >> (8 * 3)) & 0xFF; offset += sizeof(this->longitude); union { float real; uint32_t base; } u_altitude; u_altitude.real = this->altitude; *(outbuffer + offset + 0) = (u_altitude.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_altitude.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_altitude.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_altitude.base >> (8 * 3)) & 0xFF; offset += sizeof(this->altitude); return offset; } virtual int deserialize(unsigned char *inbuffer) { int offset = 0; union { float real; uint32_t base; } u_min_pitch; u_min_pitch.base = 0; u_min_pitch.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_min_pitch.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_min_pitch.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_min_pitch.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->min_pitch = u_min_pitch.real; offset += sizeof(this->min_pitch); union { float real; uint32_t base; } u_yaw; u_yaw.base = 0; u_yaw.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_yaw.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_yaw.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_yaw.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->yaw = u_yaw.real; offset += sizeof(this->yaw); union { float real; uint32_t base; } u_latitude; u_latitude.base = 0; u_latitude.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_latitude.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_latitude.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_latitude.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->latitude = u_latitude.real; offset += sizeof(this->latitude); union { float real; uint32_t base; } u_longitude; u_longitude.base = 0; u_longitude.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_longitude.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_longitude.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_longitude.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->longitude = u_longitude.real; offset += sizeof(this->longitude); union { float real; uint32_t base; } u_altitude; u_altitude.base = 0; u_altitude.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_altitude.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_altitude.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_altitude.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->altitude = u_altitude.real; offset += sizeof(this->altitude); return offset; } const char * getType(){ return COMMANDTOL; }; const char * getMD5(){ return "5aec7e34bcfe9ec68949aebae7bcd1ec"; }; }; class CommandTOLResponse : public ros::Msg { public: bool success; uint8_t result; CommandTOLResponse(): success(0), result(0) { } virtual int serialize(unsigned char *outbuffer) const { int offset = 0; union { bool real; uint8_t base; } u_success; u_success.real = this->success; *(outbuffer + offset + 0) = (u_success.base >> (8 * 0)) & 0xFF; offset += sizeof(this->success); *(outbuffer + offset + 0) = (this->result >> (8 * 0)) & 0xFF; offset += sizeof(this->result); return offset; } virtual int deserialize(unsigned char *inbuffer) { int offset = 0; union { bool real; uint8_t base; } u_success; u_success.base = 0; u_success.base |= ((uint8_t) (*(inbuffer + offset + 0))) << (8 * 0); this->success = u_success.real; offset += sizeof(this->success); this->result = ((uint8_t) (*(inbuffer + offset))); offset += sizeof(this->result); return offset; } const char * getType(){ return COMMANDTOL; }; const char * getMD5(){ return "1cd894375e4e3d2861d2222772894fdb"; }; }; class CommandTOL { public: typedef CommandTOLRequest Request; typedef CommandTOLResponse Response; }; } #endif
Changliu52/UnicornTeensyDrone
libraries_teensy3.2/ros_lib/svo_msgs/DenseInput.h
<reponame>Changliu52/UnicornTeensyDrone #ifndef _ROS_svo_msgs_DenseInput_h #define _ROS_svo_msgs_DenseInput_h #include <stdint.h> #include <string.h> #include <stdlib.h> #include "ros/msg.h" #include "std_msgs/Header.h" #include "geometry_msgs/Pose.h" #include "sensor_msgs/Image.h" namespace svo_msgs { class DenseInput : public ros::Msg { public: std_msgs::Header header; uint32_t frame_id; geometry_msgs::Pose pose; sensor_msgs::Image image; float min_depth; float max_depth; DenseInput(): header(), frame_id(0), pose(), image(), min_depth(0), max_depth(0) { } virtual int serialize(unsigned char *outbuffer) const { int offset = 0; offset += this->header.serialize(outbuffer + offset); *(outbuffer + offset + 0) = (this->frame_id >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (this->frame_id >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (this->frame_id >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (this->frame_id >> (8 * 3)) & 0xFF; offset += sizeof(this->frame_id); offset += this->pose.serialize(outbuffer + offset); offset += this->image.serialize(outbuffer + offset); union { float real; uint32_t base; } u_min_depth; u_min_depth.real = this->min_depth; *(outbuffer + offset + 0) = (u_min_depth.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_min_depth.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_min_depth.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_min_depth.base >> (8 * 3)) & 0xFF; offset += sizeof(this->min_depth); union { float real; uint32_t base; } u_max_depth; u_max_depth.real = this->max_depth; *(outbuffer + offset + 0) = (u_max_depth.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_max_depth.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_max_depth.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_max_depth.base >> (8 * 3)) & 0xFF; offset += sizeof(this->max_depth); return offset; } virtual int deserialize(unsigned char *inbuffer) { int offset = 0; offset += this->header.deserialize(inbuffer + offset); this->frame_id = ((uint32_t) (*(inbuffer + offset))); this->frame_id |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); this->frame_id |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); this->frame_id |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); offset += sizeof(this->frame_id); offset += this->pose.deserialize(inbuffer + offset); offset += this->image.deserialize(inbuffer + offset); union { float real; uint32_t base; } u_min_depth; u_min_depth.base = 0; u_min_depth.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_min_depth.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_min_depth.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_min_depth.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->min_depth = u_min_depth.real; offset += sizeof(this->min_depth); union { float real; uint32_t base; } u_max_depth; u_max_depth.base = 0; u_max_depth.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_max_depth.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_max_depth.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_max_depth.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->max_depth = u_max_depth.real; offset += sizeof(this->max_depth); return offset; } const char * getType(){ return "svo_msgs/DenseInput"; }; const char * getMD5(){ return "cea677f47dcf08581cc9f5efece2f7e7"; }; }; } #endif
Changliu52/UnicornTeensyDrone
libraries_teensy3.2/ros_lib/mavros/CommandHome.h
<gh_stars>1-10 #ifndef _ROS_SERVICE_CommandHome_h #define _ROS_SERVICE_CommandHome_h #include <stdint.h> #include <string.h> #include <stdlib.h> #include "ros/msg.h" namespace mavros { static const char COMMANDHOME[] = "mavros/CommandHome"; class CommandHomeRequest : public ros::Msg { public: bool current_gps; float latitude; float longitude; float altitude; CommandHomeRequest(): current_gps(0), latitude(0), longitude(0), altitude(0) { } virtual int serialize(unsigned char *outbuffer) const { int offset = 0; union { bool real; uint8_t base; } u_current_gps; u_current_gps.real = this->current_gps; *(outbuffer + offset + 0) = (u_current_gps.base >> (8 * 0)) & 0xFF; offset += sizeof(this->current_gps); union { float real; uint32_t base; } u_latitude; u_latitude.real = this->latitude; *(outbuffer + offset + 0) = (u_latitude.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_latitude.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_latitude.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_latitude.base >> (8 * 3)) & 0xFF; offset += sizeof(this->latitude); union { float real; uint32_t base; } u_longitude; u_longitude.real = this->longitude; *(outbuffer + offset + 0) = (u_longitude.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_longitude.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_longitude.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_longitude.base >> (8 * 3)) & 0xFF; offset += sizeof(this->longitude); union { float real; uint32_t base; } u_altitude; u_altitude.real = this->altitude; *(outbuffer + offset + 0) = (u_altitude.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_altitude.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_altitude.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_altitude.base >> (8 * 3)) & 0xFF; offset += sizeof(this->altitude); return offset; } virtual int deserialize(unsigned char *inbuffer) { int offset = 0; union { bool real; uint8_t base; } u_current_gps; u_current_gps.base = 0; u_current_gps.base |= ((uint8_t) (*(inbuffer + offset + 0))) << (8 * 0); this->current_gps = u_current_gps.real; offset += sizeof(this->current_gps); union { float real; uint32_t base; } u_latitude; u_latitude.base = 0; u_latitude.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_latitude.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_latitude.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_latitude.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->latitude = u_latitude.real; offset += sizeof(this->latitude); union { float real; uint32_t base; } u_longitude; u_longitude.base = 0; u_longitude.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_longitude.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_longitude.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_longitude.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->longitude = u_longitude.real; offset += sizeof(this->longitude); union { float real; uint32_t base; } u_altitude; u_altitude.base = 0; u_altitude.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_altitude.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_altitude.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_altitude.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->altitude = u_altitude.real; offset += sizeof(this->altitude); return offset; } const char * getType(){ return COMMANDHOME; }; const char * getMD5(){ return "4afab8683774a6cfa862aace483f5274"; }; }; class CommandHomeResponse : public ros::Msg { public: bool success; uint8_t result; CommandHomeResponse(): success(0), result(0) { } virtual int serialize(unsigned char *outbuffer) const { int offset = 0; union { bool real; uint8_t base; } u_success; u_success.real = this->success; *(outbuffer + offset + 0) = (u_success.base >> (8 * 0)) & 0xFF; offset += sizeof(this->success); *(outbuffer + offset + 0) = (this->result >> (8 * 0)) & 0xFF; offset += sizeof(this->result); return offset; } virtual int deserialize(unsigned char *inbuffer) { int offset = 0; union { bool real; uint8_t base; } u_success; u_success.base = 0; u_success.base |= ((uint8_t) (*(inbuffer + offset + 0))) << (8 * 0); this->success = u_success.real; offset += sizeof(this->success); this->result = ((uint8_t) (*(inbuffer + offset))); offset += sizeof(this->result); return offset; } const char * getType(){ return COMMANDHOME; }; const char * getMD5(){ return "1cd894375e4e3d2861d2222772894fdb"; }; }; class CommandHome { public: typedef CommandHomeRequest Request; typedef CommandHomeResponse Response; }; } #endif
Changliu52/UnicornTeensyDrone
libraries_teensy3.2/ros_lib/svo_msgs/Feature.h
#ifndef _ROS_svo_msgs_Feature_h #define _ROS_svo_msgs_Feature_h #include <stdint.h> #include <string.h> #include <stdlib.h> #include "ros/msg.h" namespace svo_msgs { class Feature : public ros::Msg { public: float u; float v; float x; float y; float z; Feature(): u(0), v(0), x(0), y(0), z(0) { } virtual int serialize(unsigned char *outbuffer) const { int offset = 0; union { float real; uint32_t base; } u_u; u_u.real = this->u; *(outbuffer + offset + 0) = (u_u.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_u.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_u.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_u.base >> (8 * 3)) & 0xFF; offset += sizeof(this->u); union { float real; uint32_t base; } u_v; u_v.real = this->v; *(outbuffer + offset + 0) = (u_v.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_v.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_v.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_v.base >> (8 * 3)) & 0xFF; offset += sizeof(this->v); union { float real; uint32_t base; } u_x; u_x.real = this->x; *(outbuffer + offset + 0) = (u_x.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_x.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_x.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_x.base >> (8 * 3)) & 0xFF; offset += sizeof(this->x); union { float real; uint32_t base; } u_y; u_y.real = this->y; *(outbuffer + offset + 0) = (u_y.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_y.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_y.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_y.base >> (8 * 3)) & 0xFF; offset += sizeof(this->y); union { float real; uint32_t base; } u_z; u_z.real = this->z; *(outbuffer + offset + 0) = (u_z.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_z.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_z.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_z.base >> (8 * 3)) & 0xFF; offset += sizeof(this->z); return offset; } virtual int deserialize(unsigned char *inbuffer) { int offset = 0; union { float real; uint32_t base; } u_u; u_u.base = 0; u_u.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_u.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_u.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_u.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->u = u_u.real; offset += sizeof(this->u); union { float real; uint32_t base; } u_v; u_v.base = 0; u_v.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_v.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_v.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_v.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->v = u_v.real; offset += sizeof(this->v); union { float real; uint32_t base; } u_x; u_x.base = 0; u_x.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_x.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_x.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_x.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->x = u_x.real; offset += sizeof(this->x); union { float real; uint32_t base; } u_y; u_y.base = 0; u_y.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_y.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_y.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_y.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->y = u_y.real; offset += sizeof(this->y); union { float real; uint32_t base; } u_z; u_z.base = 0; u_z.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_z.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_z.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_z.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->z = u_z.real; offset += sizeof(this->z); return offset; } const char * getType(){ return "svo_msgs/Feature"; }; const char * getMD5(){ return "4f7761c191bddfddcd2f99bea993a700"; }; }; } #endif
Changliu52/UnicornTeensyDrone
unicorn/PositionManageSVO.h
//©2016 <NAME> #ifndef POSITION_MANAGE_SVO_H_ #define POSITION_MANAGE_SVO_H_ #include "spektrumSatil.h" //________________________ // For smooth transation //------------------------- void vision_smoothTrans() { // This takes care of the smooth transation to vision position control if (((newMap >0 && vision_available_==1) && enableControl) && selfie_state == selfieACTIVE) { convert_RC_velo(); // set current veloD for initial run problem // refresh position command posiD[0] = pVision[0]; posiD[1] = pVision[1]; posAltiOffset = pVision[2]-veloD[2]; // refresh complementary filter buffer for (int i=0; i<3; i++){ vVision_cf[i] = vVision[i]; } // Update counter newMap-- ; } // Resets the newMap counter whenever vision becomes unavailable else if((vision_available_ !=1 || !enableControl) || selfie_state != selfieACTIVE) { // set new map for smooth transation newMap = 200; // skip 200 measurements to make sure reliable reading (remember this is runing at 400Hz!!) } } // Complementary filter to combine velocity with acceleration //______________________________________ void complementaryFilter3D(float* veloOut, float* Velo, float* Accel, float tau, float loopTime) // loopTime in s { float a=tau/(tau+loopTime); for (int i=0; i<3; i++) { veloOut[i]= a* (veloOut[i] + loopTime*(9.8*Accel[i])) + (1-a)*Velo[i]; // note here accel is scaled 0.1 times (accel is in 10m/s) } } // Compensate velocity delay //_________________________________________ #define delay_bl 12 // this value is computed by total delay from vision computer: [0.02s(vision)+0.01s(serial)]*360(imuLoopHz) = 10.8 uint8_t delay_bf_index = 0; float deltaV_x[delay_bl]; // velocity compensation of each cycle in WORLD frame float deltaV_y[delay_bl]; float deltaV_z[delay_bl]; float deltaV_comp[3] = {0.0, 0.0, 0.0}; // {x, y, z} in world frame for directly compensate velocity void init_vision_velo_delayCompensator() { for (int i=0; i<delay_bl; i++) { deltaV_x[i] = 0.0; deltaV_y[i] = 0.0; deltaV_z[i] = 0.0; } } void update_vision_velo_delayCompensator(float* acelIn, float dt) { // add new accel measurement deltaV_x[delay_bf_index] = 9.8* acelIn[0] * dt; deltaV_comp[0] += deltaV_x[delay_bf_index]; deltaV_y[delay_bf_index] = 9.8* acelIn[1] * dt; deltaV_comp[1] += deltaV_y[delay_bf_index]; deltaV_z[delay_bf_index] = 9.8* acelIn[2] * dt; deltaV_comp[2] += deltaV_z[delay_bf_index]; // shift indexer delay_bf_index++; if (delay_bf_index== delay_bl) delay_bf_index = 0; // delete oldest data deltaV_comp[0] -= deltaV_x[delay_bf_index]; deltaV_comp[1] -= deltaV_y[delay_bf_index]; deltaV_comp[2] -= deltaV_z[delay_bf_index]; } void compensate_visionVelocity(float* vVelo) { for (int i=0; i<3; i++) { vVelo[i] += deltaV_comp[i]; } } #endif
Changliu52/UnicornTeensyDrone
libraries_teensy3.2/ros_lib/svo_msgs/NbvTrajectory.h
#ifndef _ROS_svo_msgs_NbvTrajectory_h #define _ROS_svo_msgs_NbvTrajectory_h #include <stdint.h> #include <string.h> #include <stdlib.h> #include "ros/msg.h" #include "std_msgs/Header.h" #include "geometry_msgs/Pose.h" namespace svo_msgs { class NbvTrajectory : public ros::Msg { public: std_msgs::Header header; uint8_t trajectory_length; geometry_msgs::Pose st_trajectory; geometry_msgs::Pose * trajectory; NbvTrajectory(): header(), trajectory_length(0), trajectory(NULL) { } virtual int serialize(unsigned char *outbuffer) const { int offset = 0; offset += this->header.serialize(outbuffer + offset); *(outbuffer + offset++) = trajectory_length; *(outbuffer + offset++) = 0; *(outbuffer + offset++) = 0; *(outbuffer + offset++) = 0; for( uint8_t i = 0; i < trajectory_length; i++){ offset += this->trajectory[i].serialize(outbuffer + offset); } return offset; } virtual int deserialize(unsigned char *inbuffer) { int offset = 0; offset += this->header.deserialize(inbuffer + offset); uint8_t trajectory_lengthT = *(inbuffer + offset++); if(trajectory_lengthT > trajectory_length) this->trajectory = (geometry_msgs::Pose*)realloc(this->trajectory, trajectory_lengthT * sizeof(geometry_msgs::Pose)); offset += 3; trajectory_length = trajectory_lengthT; for( uint8_t i = 0; i < trajectory_length; i++){ offset += this->st_trajectory.deserialize(inbuffer + offset); memcpy( &(this->trajectory[i]), &(this->st_trajectory), sizeof(geometry_msgs::Pose)); } return offset; } const char * getType(){ return "svo_msgs/NbvTrajectory"; }; const char * getMD5(){ return "eb6b516341d535312e1b3849a61711c1"; }; }; } #endif
Changliu52/UnicornTeensyDrone
libraries_teensy3.2/FreeIMU/Calibration Files/calibrationFlipensy.h
<gh_stars>1-10 /** * FreeIMU calibration header. Automatically generated by FreeIMU_GUI. * Do not edit manually unless you know what you are doing. */ #define CALIBRATION_H const int acc_off_x = 261; const int acc_off_y = 156; const int acc_off_z = 491; const float acc_scale_x = 16386.272503; const float acc_scale_y = 16494.930885; const float acc_scale_z = 16772.044958; const int magn_off_x = -100; const int magn_off_y = -137; const int magn_off_z = -52; const float magn_scale_x = 567.008521; const float magn_scale_y = 528.510663; const float magn_scale_z = 477.477617;
Changliu52/UnicornTeensyDrone
libraries_teensy3.2/ros_lib/mavros/ParamPull.h
<gh_stars>1-10 #ifndef _ROS_SERVICE_ParamPull_h #define _ROS_SERVICE_ParamPull_h #include <stdint.h> #include <string.h> #include <stdlib.h> #include "ros/msg.h" namespace mavros { static const char PARAMPULL[] = "mavros/ParamPull"; class ParamPullRequest : public ros::Msg { public: bool force_pull; ParamPullRequest(): force_pull(0) { } virtual int serialize(unsigned char *outbuffer) const { int offset = 0; union { bool real; uint8_t base; } u_force_pull; u_force_pull.real = this->force_pull; *(outbuffer + offset + 0) = (u_force_pull.base >> (8 * 0)) & 0xFF; offset += sizeof(this->force_pull); return offset; } virtual int deserialize(unsigned char *inbuffer) { int offset = 0; union { bool real; uint8_t base; } u_force_pull; u_force_pull.base = 0; u_force_pull.base |= ((uint8_t) (*(inbuffer + offset + 0))) << (8 * 0); this->force_pull = u_force_pull.real; offset += sizeof(this->force_pull); return offset; } const char * getType(){ return PARAMPULL; }; const char * getMD5(){ return "16415b4e049d3f92df764eeb461102b7"; }; }; class ParamPullResponse : public ros::Msg { public: bool success; uint32_t param_received; ParamPullResponse(): success(0), param_received(0) { } virtual int serialize(unsigned char *outbuffer) const { int offset = 0; union { bool real; uint8_t base; } u_success; u_success.real = this->success; *(outbuffer + offset + 0) = (u_success.base >> (8 * 0)) & 0xFF; offset += sizeof(this->success); *(outbuffer + offset + 0) = (this->param_received >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (this->param_received >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (this->param_received >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (this->param_received >> (8 * 3)) & 0xFF; offset += sizeof(this->param_received); return offset; } virtual int deserialize(unsigned char *inbuffer) { int offset = 0; union { bool real; uint8_t base; } u_success; u_success.base = 0; u_success.base |= ((uint8_t) (*(inbuffer + offset + 0))) << (8 * 0); this->success = u_success.real; offset += sizeof(this->success); this->param_received = ((uint32_t) (*(inbuffer + offset))); this->param_received |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); this->param_received |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); this->param_received |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); offset += sizeof(this->param_received); return offset; } const char * getType(){ return PARAMPULL; }; const char * getMD5(){ return "5601e883220b149a3209512e966299f0"; }; }; class ParamPull { public: typedef ParamPullRequest Request; typedef ParamPullResponse Response; }; } #endif
Changliu52/UnicornTeensyDrone
unicorn/ESC_PWM.h
//©2016 <NAME> #ifndef __ESCPWM_H__ #define __ESCPWM_H__ #include <Arduino.h> /* ESC / Servo signal generation done in hardware by FLEX timer, without ISR (yay!) We are using flex timer0 which supports 8 channels. Currently generating 400 Hz PWM signal that is fed into electronic speed controllers corresponding to each rotor. This code will probably be expanded to also generate servo signal for gimbal stabilization (hopefully in near future). Big thanks to kha from #aeroquad for helping me get this up and running. == PIN Configuration == Channel - PIN name - Teensy 3.0 PIN numbering FTM0_CH0 - PTC1 - 22 - m1 FTM0_CH1 - PTC2 - 23 - m2 FTM0_CH2 - PTC3 - 9 - Not used FTM0_CH3 - PTC4 - 10 - Not used FTM0_CH4 - PTD4 - 6 - m5 FTM0_CH5 - PTD5 - 20 - m3 FTM0_CH6 - PTD6 - 21 - m4 FTM0_CH7 - PTD7 - 5 - m6 */ #define M0 22 #define M1 23 #define M2 20 #define M3 21 #define maxPWM 8191.0 //####################################### void motorsStop() { analogWrite(M0, 10); analogWrite(M1, 10); analogWrite(M2, 10); analogWrite(M3, 10); } void motorsNeutr() { analogWrite(M0, 400); analogWrite(M1, 400); analogWrite(M2, 400); analogWrite(M3, 400); } void motorInit() { analogWriteFrequency(M0, 1000);//5859Hz , this set all the pin on this timer analogWriteResolution(13); // 0-8191!!! -> 0-100%PWM motorsStop(); } void motors_update(uint16_t* MotorOut) //MotorOut in us { analogWrite(M0, MotorOut[0]); analogWrite(M1, MotorOut[1]); analogWrite(M2, MotorOut[2]); analogWrite(M3, MotorOut[3]); } //__________________________________________________-- // Convert duty cycle% to pwm value, according to the Motor pwm resolution void moveServo(float* dutycycles) { #define minDuty 0 #define maxDuty 100 uint16_t motorPWM[4]; for (int i=0; i<4; i++){ // bracket if (dutycycles[i]<minDuty) {dutycycles[i]=minDuty;} else if (dutycycles[i]>maxDuty) {dutycycles[i]=maxDuty;} // convert to duty cycle motorPWM[i] = (uint16_t)((dutycycles[i]-minDuty)*maxPWM/(maxDuty-minDuty)); //Map the duty cycle to the corresponding PWM pulse. } //Serial.println(motorPWM[0]); motors_update(motorPWM); } //###################################### //________________________________ // convert motor value from command to thrust value (lineariser) // Remember to change maxthrust in globleVairbles.h void thrust2throttle250_PWM_CLOSELoop (float* thrust, float* PWMout) { for (int i=0; i<4; i++) { //PWMout[i] = 2.71*sqrt(thrust[i])-0.009837; // elite PWMout[i] = 2.262*sqrt(thrust[i])+2.575; // AirGear first 4:13 measurements if(PWMout[i]>50.0) PWMout[i]=50.0; } } #endif
Changliu52/UnicornTeensyDrone
libraries_teensy3.2/AP_Filter/Filter.h
#ifndef __FILTER_H__ #define __FILTER_H__ /* Umbrella header for the Filter library */ #include "FilterClass.h" #include "AverageFilter.h" #include "DerivativeFilter.h" #include "FilterWithBuffer.h" #include "LowPassFilter.h" #include "ModeFilter.h" #include "Butter.h" #endif //__FILTER_H__
Changliu52/UnicornTeensyDrone
libraries_teensy3.2/FreeIMU/FreeIMU.h
<gh_stars>1-10 /* FreeIMU.h - A libre and easy to use orientation sensing library for Arduino Copyright (C) 2011 <NAME> <fabio at varesano dot net> Development of this code has been supported by the Department of Computer Science, Universita' degli Studi di Torino, Italy within the Piemonte Project http://www.piemonte.di.unito.it/ This program is free software: you can redistribute it and/or modify it under the terms of the version 3 GNU General Public License as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef FreeIMU_h #define FreeIMU_h // Uncomment the appropriated version of FreeIMU you are using //#define FREEIMU_v01 //#define FREEIMU_v02 //#define FREEIMU_v03 //#define FREEIMU_v035 //#define FREEIMU_v035_MS //#define FREEIMU_v035_BMP #define FREEIMU_v04 // 3rd party boards. Please consider donating or buying a FreeIMU board to support this library development. //#define SEN_10121 //IMU Digital Combo Board - 6 Degrees of Freedom ITG3200/ADXL345 SEN-10121 http://www.sparkfun.com/products/10121 //#define SEN_10736 //9 Degrees of Freedom - Razor IMU SEN-10736 http://www.sparkfun.com/products/10736/ //#define SEN_10724 //9 Degrees of Freedom - Sensor Stick SEN-10724 http://www.sparkfun.com/products/10724 //#define SEN_10183 //9 Degrees of Freedom - Sensor Stick SEN-10183 http://www.sparkfun.com/products/10183 //#define ARDUIMU_v3 // DIYDrones ArduIMU+ V3 http://store.diydrones.com/ArduIMU_V3_p/kt-arduimu-30.htm or https://www.sparkfun.com/products/11055 //#define GEN_MPU6050 // Generic MPU6050 breakout board. Compatible with GY-521, SEN-11028 and other MPU6050 wich have the MPU6050 AD0 pin connected to GND. //#define DFROBOT //DFROBOT 10DOF SEN-1040 IMU //#define MPU9250_5611 //MPU-9250 IMU with MS5611 Altimeter from eBay //#define GEN_MPU9150 //#define GEN_MPU9250 //#define Altimu10 // Pololu AltIMU v10 - 10 DOF IMU - http://www.pololu.com/product/1269 //#define GY_88 //GY-88 Sensor Board from eBay #define DISABLE_MAGN // Uncomment this line to disable the magnetometer in the sensor fusion algorithm //Magnetic declination angle for iCompass #define MAG_DEC 4 //+4.0 degrees for Israel #define MAG_DEC -13.1603 //degrees for Flushing, NY //Number of samples to average in iCompass #define WINDOW_SIZE 10 //Set to 1 to turn off the Running Average // Set filter type: 1 = Madgwick Gradient Descent, 0 - Madgwick implementation of Mahoney DCM // in Quaternion form. #define MARG 1 // *** No configuration needed below this line *** #define FREEIMU_LIB_VERSION "DEV" #define FREEIMU_DEVELOPER "<NAME> - varesano.net" #if F_CPU == 16000000L #define FREEIMU_FREQ "16 MHz" #elif F_CPU == 8000000L #define FREEIMU_FREQ "8 MHz" #elif F_CPU == 24000000L #define FREEIMU_FREQ "24 MHz" #elif F_CPU == 48000000L #define FREEIMU_FREQ "48 MHz" #elif F_CPU == 72000000L #define FREEIMU_FREQ "48 MHz" #else #define FREEIMU_FREQ "Not Defined" #endif // board IDs #if defined(FREEIMU_v01) #define FREEIMU_ID "FreeIMU v0.1" #elif defined(FREEIMU_v02) #define FREEIMU_ID "FreeIMU v0.2" #elif defined(FREEIMU_v03) #define FREEIMU_ID "FreeIMU v0.3" #elif defined(FREEIMU_v035) #define FREEIMU_ID "FreeIMU v0.3.5" #elif defined(FREEIMU_v035_BMP) #define FREEIMU_ID "FreeIMU v0.3.5_BMP" #elif defined(FREEIMU_v035_MS) #define FREEIMU_ID "FreeIMU v0.3.5_MS" #elif defined(FREEIMU_v04) #define FREEIMU_ID "FreeIMU v0.4" #elif defined(SEN_10121) #define FREEIMU_ID "SparkFun 10121" #elif defined(SEN_10736) #define FREEIMU_ID "SparkFun 10736" #elif defined(SEN_10724) #define FREEIMU_ID "SparkFun 10724" #elif defined(SEN_10183) #define FREEIMU_ID "SparkFun 10183" #elif defined(ARDUIMU_v3) #define FREEIMU_ID "DIY Drones ArduIMU+ V3" #elif defined(DFROBOT) #define FREEIMU_ID "DFROBOT" #elif defined(GEN_MPU6050) #define FREEIMU_ID "GEN MPU-6050" #elif defined(GEN_MPU9150) #define FREEIMU_ID "GEN MPU-9150" #elif defined(MPU9250_5611) #define FREEIMU_ID "MPU9150_5611" #elif defined(GEN_MPU9250) #define FREEIMU_ID "GEN MPU-9250" #elif defined(Altimu10) #define FREEIMU_ID "AltIMU-v10" #elif defined(GY_88) #define FREEIMU_ID "GY-88 Sensor Board" #endif #define HAS_ITG3200() (defined(DFROBOT) || defined(FREEIMU_v01) || defined(FREEIMU_v02) || defined(FREEIMU_v03) || defined(FREEIMU_v035) || defined(FREEIMU_v035_MS) || defined(FREEIMU_v035_BMP) || defined(SEN_10121) || defined(SEN_10736) || defined(SEN_10724) || defined(SEN_10183)) #define HAS_ADXL345() (defined(DFROBOT) || defined(FREEIMU_v01) || defined(FREEIMU_v02) || defined(FREEIMU_v03) || defined(SEN_10121) || defined(SEN_10736) || defined(SEN_10724) || defined(SEN_10183)) #define HAS_BMA180() (defined(FREEIMU_v035) || defined(FREEIMU_v035_MS) || defined(FREEIMU_v035_BMP)) #define HAS_MPU6050() (defined(GY_88) || defined(FREEIMU_v04) || defined(GEN_MPU6050)) #define HAS_MPU9150() (defined(GEN_MPU9150)) #define HAS_MPU9250() (defined(MPU9250_5611) || defined(GEN_MPU9250)) #define HAS_MS5611() (defined(MPU9250_5611) || defined(FREEIMU_v035_MS) || defined(FREEIMU_v04)) #define HAS_BMP085() (defined(GY_88) || defined(DFROBOT)) #define HAS_HMC5883L() (defined(GY_88) || defined(DFROBOT) || defined(FREEIMU_v01) || defined(FREEIMU_v02) || defined(FREEIMU_v03) || defined(FREEIMU_v035) || defined(FREEIMU_v035_MS) || defined(FREEIMU_v035_BMP) || defined(FREEIMU_v04) || defined(SEN_10736) || defined(SEN_10724) || defined(SEN_10183) || defined(ARDUIMU_v3)) #define HAS_MPU6000() (defined(ARDUIMU_v3)) #define HAS_ALTIMU10() (defined(Altimu10)) #define HAS_LPS331() (defined(Altimu10)) #define HAS_L3D20() (defined(Altimu10)) #define HAS_LSM303() (defined(Altimu10)) #define IS_6DOM() (defined(SEN_10121) || defined(GEN_MPU6050)) #define IS_9DOM() (defined(GY_88) || defined(Altimu10) || defined(GEN_MPU9250) || defined(MPU9250_5611) || defined(GEN_MPU9150) || defined(DFROBOT) || defined(FREEIMU_v01) || defined(FREEIMU_v02) || defined(FREEIMU_v03) || defined(FREEIMU_v035) || defined(FREEIMU_v035_MS) || defined(FREEIMU_v035_BMP) || defined(FREEIMU_v04) || defined(SEN_10736) || defined(SEN_10724) || defined(SEN_10183) || defined(ARDUIMU_v3)) #define HAS_AXIS_ALIGNED() (defined(GY_88) || defined(GEN_MPU6050) || defined(DFROBOT) || defined(FREEIMU_v01) || defined(FREEIMU_v02) || defined(FREEIMU_v03) || defined(FREEIMU_v035) || defined(FREEIMU_v035_MS) || defined(FREEIMU_v035_BMP) || defined(FREEIMU_v04) || defined(SEN_10121) || defined(SEN_10736)) #include <Wire.h> #include "Arduino.h" #include "calibration.h" #ifndef CALIBRATION_H #include <EEPROM.h> #endif #define FREEIMU_EEPROM_BASE 0x0A #define FREEIMU_EEPROM_SIGNATURE 0x19 //#if FREEIMU_VER <= 3 #if HAS_ADXL345() #include <ADXL345.h> // default I2C 7-bit addresses of the sensors #define FIMU_ACC_ADDR ADXL345_ADDR_ALT_LOW // SDO connected to GND //#define FIMU_ADXL345_DEF_ADDR ADXL345_ADDR_ALT_HIGH // SDO connected to GND #elif HAS_BMA180() #include <bma180.h> #define FIMU_ACC_ADDR BMA180_ADDRESS_SDO_LOW //#define FIMU_ACC_ADDR BMA180_ADDRESS_SDO_HIGH //#elif FREEIMU_VER == 7 #elif HAS_MPU6050() #include <Wire.h> #include "I2Cdev.h" #include "MPU60X0.h" #define FIMU_ACCGYRO_ADDR MPU60X0_DEFAULT_ADDRESS #elif HAS_MPU6000() #include <SPI.h> #include "I2Cdev.h" #include "MPU60X0.h" #define FIMU_ACCGYRO_ADDR MPU60X0_DEFAULT_SS_PIN #elif HAS_MPU9150() #include <Wire.h> #include "I2Cdev.h" #include "MPU60X0.h" #include "AK8975.h" #include "iCompass.h" #define FIMU_ACCGYRO_ADDR MPU60X0_DEFAULT_ADDRESS #elif HAS_MPU9250() #include <Wire.h> #include "I2Cdev.h" #include "MPU60X0.h" #include "AK8963.h" #include "iCompass.h" #define FIMU_ACCGYRO_ADDR MPU60X0_DEFAULT_ADDRESS #elif HAS_ALTIMU10() #include <Wire.h> #endif #if HAS_BMP085() #include <BMP085.h> #elif HAS_MS5611() #include <MS561101BA.h> #define FIMU_BARO_ADDR MS561101BA_ADDR_CSB_LOW //#define FIMU_BARO_ADDR MS561101BA_ADDR_CSB_HIGH #elif HAS_LPS331() #include <LPS331.h> #endif #if HAS_MS5611() || HAS_BMP085() || HAS_LPS331() #include <FilteringScheme.h> #include <AltitudeComplementary.h> #endif #if HAS_ITG3200() #include <ITG3200.h> //Added next line for Sen1040 #define FIMU_ITG3200_DEF_ADDR ITG3200_ADDR_AD0_LOW #elif HAS_L3D20() #include <L3G.h> #endif #if HAS_HMC5883L() #include <HMC58X3.h> #include "iCompass.h" #endif #if HAS_LSM303() #include <LSM303.h> #include "iCompass.h" #endif #define FIMU_BMA180_DEF_ADDR BMA180_ADDRESS_SDO_LOW #define FIMU_ITG3200_DEF_ADDR ITG3200_ADDR_AD0_LOW // AD0 connected to GND // HMC5843 address is fixed so don't bother to define it // proportional gain governs rate of convergence to accelerometer/magnetometer // integral gain governs rate of convergence of gyroscope biases // set up defines for various boards in my inventory, DFROBOT and Freeimu have // temperature calibration curves. (3.31.14) #if defined(DFROBOT) #define twoKpDef (2.0f * 0.5f) #define twoKiDef (2.0f * 0.00002f) #define betaDef 0.05f #elif defined(FREEIMU_v04) #define twoKpDef (2.0f * 0.75f) //works with and without mag enabled #define twoKiDef (2.0f * 0.1625f) #define betaDef 0.1f//!!!!!!!!!!!to change0.05f #define ExlongDef 0.06f #elif defined(GEN_MPU6050) #define twoKpDef (2.0f * 0.5f) #define twoKiDef (2.0f * 0.25f) #define betaDef 0.05f // 2 * proportional gain #elif defined(GEN_MPU9150) #define twoKpDef (2.0f * 0.75f) #define twoKiDef (2.0f * 0.1f) #define betaDef 0.05f // 2 * proportional gain #elif defined(Altimu10) //#define twoKpDef (2.0f * 1.01f) //#define twoKiDef (2.0f * 0.00002f) #define twoKpDef (2.0f * 2.75f) #define twoKiDef (2.0f * 0.1625f) #define betaDef 0.05f #elif defined(GEN_MPU9250) #define twoKpDef (2.0f * 0.95f) #define twoKiDef (2.0f * 0.05f) #define betaDef 0.05f // 2 * proportional gain #else #define twoKpDef (2.0f * 0.5f) #define twoKiDef (2.0f * 0.1f) #define betaDef 0.05f #endif #ifndef cbi #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit)) #endif class FreeIMU { public: FreeIMU(); void init(); /*void init(); //void init0(bool fastmode); //void init(bool fastmode); */ void RESET(); void RESET_Q(); #if HAS_ITG3200() void init(bool fastmode); void init(int acc_addr, int gyro_addr, bool fastmode); #elif HAS_ALTIMU10() void init(bool fastmode); void init0(bool fastmode); #else void init(bool fastmode); void init(int accgyro_addr, bool fastmode); #endif #ifndef CALIBRATION_H void calLoad(); #endif void zeroGyro(); void initGyros(); void getRawValues(int * raw_values); void getValues(float * values); void getQ(float * q, float * val); void getEuler(float * angles); void getYawPitchRoll(float * ypr); void getEulerRad(float * angles); void getYawPitchRollRad(float * ypr); float invSqrt(float x); void setTempCalib(int opt_temp_cal); float calcMagHeading(float q0, float q1, float q2, float q3, float bx, float by, float bz); void initializeQ(float hdg); //////////////////////// // My function!!!!!!!!!!!!!!!!!!!!!!! void EstimatedAlt(float compensated_accel_earth, float* output); void getYpr_EarthAccel_EstAlt(float* ypr, float* dyn_acc_earth, float* output); void getEuler_EarthAccel_EstAlt_gyro(float* euler, float* dyn_acc_earth, float* output, float* gyrorate); void getEuler_EarthAccel_EstAlt_gyro_vis(float* euler, float* dyn_acc_earth, float* output, float* gyrorate, float* qVision, HardwareSerial* XBee, int8_t vision_available, float*biasAccel); void setExlong(); bool initialised = 0; // set this to 0 will reset the altitude estimator ///////////////////// #if HAS_MS5611() float getBaroAlt(); float getBaroAlt(float sea_press); float getBaroTemperature(); float getBaroPressure(); #elif HAS_BMP085() float getBaroAlt(); float getBaroTemperature(); float getBaroPressure(); #elif HAS_LPS331() float getBaroAlt(); float getBaroTemperature(); float getBaroPressure(); #endif #if HAS_MS5611() || HAS_BMP085() || HAS_LPS331() float getEstAltitude(); #endif // we make them public so that users can interact directly with device classes #if HAS_ADXL345() ADXL345 acc; #elif HAS_BMA180() BMA180 acc; #endif #if HAS_HMC5883L() HMC58X3 magn; iCompass maghead; #endif #if HAS_ITG3200() ITG3200 gyro; #elif HAS_MPU6050() MPU60X0 accgyro; #elif HAS_MPU6000() MPU60X0 accgyro; #elif HAS_MPU9150() MPU60X0 accgyro; AK8975 mag; iCompass maghead; #elif HAS_MPU9250() MPU60X0 accgyro; AK8963 mag; iCompass maghead; #endif #if HAS_L3D20() L3G gyro; #endif #if HAS_LSM303() LSM303 compass; // accelerometer, magnetometer and heading - same as iCompass iCompass maghead; #endif #if HAS_MS5611() MS561101BA baro; #elif HAS_BMP085() BMP085 baro085; #elif HAS_LPS331() LPS331 baro331; #endif #if HAS_MS5611() || HAS_BMP085() || HAS_LPS331() KalmanFilter kPress; // Altitude Kalman Filter. AltComp altComp; // Altitude Complementary Filter. #endif int* raw_acc, raw_gyro, raw_magn; // calibration parameters int16_t gyro_off_x, gyro_off_y, gyro_off_z; int16_t acc_off_x, acc_off_y, acc_off_z, magn_off_x, magn_off_y, magn_off_z; float acc_scale_x, acc_scale_y, acc_scale_z, magn_scale_x, magn_scale_y, magn_scale_z; float val[11]; int8_t nsamples, temp_break, temp_corr_on, instability_fix; int16_t DTemp; float rt, senTemp, senTemp_break; float sampleFreq; // half the sample period expressed in seconds private: //void AHRSupdate(float gx, float gy, float gz, float ax, float ay, float az, float mx, float my, float mz); //void AHRSupdateIMU(float gx, float gy, float gz, float ax, float ay, float az); bool bSPI; float bx, by, bz; float iq0, iq1, iq2, iq3; float exInt, eyInt, ezInt; // scaled integral error volatile float twoKp; // 2 * proportional gain (Kp) volatile float twoKi; // 2 * integral gain (Ki) volatile float q0, q1, q2, q3, q3old; // quaternion of sensor frame relative to auxiliary frame volatile float integralFBx, integralFBy, integralFBz; unsigned long lastUpdate, now; // sample period expressed in milliseconds unsigned long lastUpdate1, now1; float dt2; //Madgwick AHRS Gradient Descent volatile float beta; // algorithm gain #if(MARG == 0) void AHRSupdate(float gx, float gy, float gz, float ax, float ay, float az, float mx, float my, float mz); void AHRSupdateIMU(float gx, float gy, float gz, float ax, float ay, float az); #else void MadgwickAHRSupdate(float gx, float gy, float gz, float ax, float ay, float az, float mx, float my, float mz); void MadgwickAHRSupdateIMU(float gx, float gy, float gz, float ax, float ay, float az); #endif ////////////// // My function!!!!!! ////////////// float s0v, s1v, s2v, s3v; float gxb, gyb, gzb, Exlong; int8_t vision_available; void MadgwickAHRSupdateIMU_vis(float gx, float gy, float gz, float ax, float ay, float az, float* qVision, HardwareSerial* XBee); void getQ_vis(float * q, float * val, float* qVision, HardwareSerial* XBee); }; //////////////////////////////// // My function!!!!!!!!!!!!! void q_mult(float* q1, float* q2, float* q3); void QuatRot(float * vec, float * q, float* newVec); //////////////////////// float invSqrt(float number); void arr3_rad_to_deg(float * arr); void Qmultiply(float * q, float * q1, float * q2); void gravityCompensateAcc(float * acc, float * q); #endif // FreeIMU_h
Changliu52/UnicornTeensyDrone
libraries_teensy3.2/FreeIMU/Calibration Files/calibrationS500.h
/** * FreeIMU calibration header. Automatically generated by FreeIMU_GUI. * Do not edit manually unless you know what you are doing. */ #define CALIBRATION_H const int acc_off_x = 89; const int acc_off_y = 32; const int acc_off_z = 2708; const float acc_scale_x = 16386.652279; const float acc_scale_y = 16351.250348; const float acc_scale_z = 16579.212920; const int magn_off_x = 24; const int magn_off_y = -34; const int magn_off_z = -1; const float magn_scale_x = 541.252165; const float magn_scale_y = 509.329748; const float magn_scale_z = 456.377591;
Changliu52/UnicornTeensyDrone
libraries_teensy3.2/ros_lib/mavros/RCOut.h
<reponame>Changliu52/UnicornTeensyDrone #ifndef _ROS_mavros_RCOut_h #define _ROS_mavros_RCOut_h #include <stdint.h> #include <string.h> #include <stdlib.h> #include "ros/msg.h" #include "std_msgs/Header.h" namespace mavros { class RCOut : public ros::Msg { public: std_msgs::Header header; uint8_t channels_length; uint16_t st_channels; uint16_t * channels; RCOut(): header(), channels_length(0), channels(NULL) { } virtual int serialize(unsigned char *outbuffer) const { int offset = 0; offset += this->header.serialize(outbuffer + offset); *(outbuffer + offset++) = channels_length; *(outbuffer + offset++) = 0; *(outbuffer + offset++) = 0; *(outbuffer + offset++) = 0; for( uint8_t i = 0; i < channels_length; i++){ *(outbuffer + offset + 0) = (this->channels[i] >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (this->channels[i] >> (8 * 1)) & 0xFF; offset += sizeof(this->channels[i]); } return offset; } virtual int deserialize(unsigned char *inbuffer) { int offset = 0; offset += this->header.deserialize(inbuffer + offset); uint8_t channels_lengthT = *(inbuffer + offset++); if(channels_lengthT > channels_length) this->channels = (uint16_t*)realloc(this->channels, channels_lengthT * sizeof(uint16_t)); offset += 3; channels_length = channels_lengthT; for( uint8_t i = 0; i < channels_length; i++){ this->st_channels = ((uint16_t) (*(inbuffer + offset))); this->st_channels |= ((uint16_t) (*(inbuffer + offset + 1))) << (8 * 1); offset += sizeof(this->st_channels); memcpy( &(this->channels[i]), &(this->st_channels), sizeof(uint16_t)); } return offset; } const char * getType(){ return "mavros/RCOut"; }; const char * getMD5(){ return "52cacf104bab5ae3b103cfe176590713"; }; }; } #endif
Changliu52/UnicornTeensyDrone
libraries_teensy3.2/ros_lib/mavros/CommandInt.h
#ifndef _ROS_SERVICE_CommandInt_h #define _ROS_SERVICE_CommandInt_h #include <stdint.h> #include <string.h> #include <stdlib.h> #include "ros/msg.h" namespace mavros { static const char COMMANDINT[] = "mavros/CommandInt"; class CommandIntRequest : public ros::Msg { public: uint8_t frame; uint16_t command; uint8_t current; uint8_t autocontinue; float param1; float param2; float param3; float param4; int32_t x; int32_t y; float z; CommandIntRequest(): frame(0), command(0), current(0), autocontinue(0), param1(0), param2(0), param3(0), param4(0), x(0), y(0), z(0) { } virtual int serialize(unsigned char *outbuffer) const { int offset = 0; *(outbuffer + offset + 0) = (this->frame >> (8 * 0)) & 0xFF; offset += sizeof(this->frame); *(outbuffer + offset + 0) = (this->command >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (this->command >> (8 * 1)) & 0xFF; offset += sizeof(this->command); *(outbuffer + offset + 0) = (this->current >> (8 * 0)) & 0xFF; offset += sizeof(this->current); *(outbuffer + offset + 0) = (this->autocontinue >> (8 * 0)) & 0xFF; offset += sizeof(this->autocontinue); union { float real; uint32_t base; } u_param1; u_param1.real = this->param1; *(outbuffer + offset + 0) = (u_param1.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_param1.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_param1.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_param1.base >> (8 * 3)) & 0xFF; offset += sizeof(this->param1); union { float real; uint32_t base; } u_param2; u_param2.real = this->param2; *(outbuffer + offset + 0) = (u_param2.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_param2.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_param2.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_param2.base >> (8 * 3)) & 0xFF; offset += sizeof(this->param2); union { float real; uint32_t base; } u_param3; u_param3.real = this->param3; *(outbuffer + offset + 0) = (u_param3.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_param3.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_param3.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_param3.base >> (8 * 3)) & 0xFF; offset += sizeof(this->param3); union { float real; uint32_t base; } u_param4; u_param4.real = this->param4; *(outbuffer + offset + 0) = (u_param4.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_param4.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_param4.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_param4.base >> (8 * 3)) & 0xFF; offset += sizeof(this->param4); union { int32_t real; uint32_t base; } u_x; u_x.real = this->x; *(outbuffer + offset + 0) = (u_x.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_x.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_x.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_x.base >> (8 * 3)) & 0xFF; offset += sizeof(this->x); union { int32_t real; uint32_t base; } u_y; u_y.real = this->y; *(outbuffer + offset + 0) = (u_y.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_y.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_y.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_y.base >> (8 * 3)) & 0xFF; offset += sizeof(this->y); union { float real; uint32_t base; } u_z; u_z.real = this->z; *(outbuffer + offset + 0) = (u_z.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_z.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_z.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_z.base >> (8 * 3)) & 0xFF; offset += sizeof(this->z); return offset; } virtual int deserialize(unsigned char *inbuffer) { int offset = 0; this->frame = ((uint8_t) (*(inbuffer + offset))); offset += sizeof(this->frame); this->command = ((uint16_t) (*(inbuffer + offset))); this->command |= ((uint16_t) (*(inbuffer + offset + 1))) << (8 * 1); offset += sizeof(this->command); this->current = ((uint8_t) (*(inbuffer + offset))); offset += sizeof(this->current); this->autocontinue = ((uint8_t) (*(inbuffer + offset))); offset += sizeof(this->autocontinue); union { float real; uint32_t base; } u_param1; u_param1.base = 0; u_param1.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_param1.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_param1.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_param1.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->param1 = u_param1.real; offset += sizeof(this->param1); union { float real; uint32_t base; } u_param2; u_param2.base = 0; u_param2.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_param2.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_param2.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_param2.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->param2 = u_param2.real; offset += sizeof(this->param2); union { float real; uint32_t base; } u_param3; u_param3.base = 0; u_param3.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_param3.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_param3.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_param3.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->param3 = u_param3.real; offset += sizeof(this->param3); union { float real; uint32_t base; } u_param4; u_param4.base = 0; u_param4.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_param4.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_param4.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_param4.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->param4 = u_param4.real; offset += sizeof(this->param4); union { int32_t real; uint32_t base; } u_x; u_x.base = 0; u_x.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_x.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_x.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_x.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->x = u_x.real; offset += sizeof(this->x); union { int32_t real; uint32_t base; } u_y; u_y.base = 0; u_y.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_y.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_y.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_y.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->y = u_y.real; offset += sizeof(this->y); union { float real; uint32_t base; } u_z; u_z.base = 0; u_z.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_z.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_z.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_z.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->z = u_z.real; offset += sizeof(this->z); return offset; } const char * getType(){ return COMMANDINT; }; const char * getMD5(){ return "1a1e7ee075d7c5e220ed29842ff91d0d"; }; }; class CommandIntResponse : public ros::Msg { public: bool success; CommandIntResponse(): success(0) { } virtual int serialize(unsigned char *outbuffer) const { int offset = 0; union { bool real; uint8_t base; } u_success; u_success.real = this->success; *(outbuffer + offset + 0) = (u_success.base >> (8 * 0)) & 0xFF; offset += sizeof(this->success); return offset; } virtual int deserialize(unsigned char *inbuffer) { int offset = 0; union { bool real; uint8_t base; } u_success; u_success.base = 0; u_success.base |= ((uint8_t) (*(inbuffer + offset + 0))) << (8 * 0); this->success = u_success.real; offset += sizeof(this->success); return offset; } const char * getType(){ return COMMANDINT; }; const char * getMD5(){ return "358e233cde0c8a8bcfea4ce193f8fc15"; }; }; class CommandInt { public: typedef CommandIntRequest Request; typedef CommandIntResponse Response; }; } #endif
Changliu52/UnicornTeensyDrone
unicorn/COM.h
//©2016 <NAME> #ifndef __COM_H__ #define __COM_H__ #include <Arduino.h> // constants const uint8_t START_BYTE = 0xF0; const uint8_t STOP_BYTE = 0xA5; // Mode variable int MODE = 0; //0 - No com, 1 - gain tuning, 2 - status debugging // Gains var union{ struct{ float PGain[3]; float IGain[3]; float DGain[3]; } v; uint8_t GAINmessage[36]; } Gains; // Status var union{ struct{ float q[4]; float qD[4]; float currentHeight; float desireHeight; float currentVelox; float desireVelox; float currentVeloy; float desireVeloy; uint32_t LoopHz; } v; uint8_t message[60]; } STATUS; //_______________________________________________ // Functions template <class USerial> // Helper Function to read control command from PC boolean read_data(USerial *s, uint8_t message[], uint8_t messID, uint8_t stringLength) { // NB. String length is basically the message + the iD, so mess length plus 1 if (s->available() >= stringLength+4) { if (s->read() != START_BYTE) return 0; if (s->read() != stringLength) return 0; if (s->read() != messID) return 0; uint8_t checksum = START_BYTE + stringLength + messID; for (int i = 0; i< stringLength-1; i++) { checksum += message[i] = s->read(); } if(s->read() != checksum || s->read() != STOP_BYTE) return 0; s->flush(); // Avoid Serial Jem return 1; } else { return 0; } } // Helper Function to read synchronised data from UART template <class USerial> boolean read_sync_data(uint8_t message[], uint8_t messID, uint8_t stringLength, USerial *s) { // NB. String length is basically the message + the iD, so mess length plus 1 if (s->available() >= stringLength+4) { if (s->read() != START_BYTE) return 0; if (s->read() != stringLength) return 0; if (s->read() != messID) return 0; uint8_t checksum = START_BYTE + stringLength + messID; for (int i = 0; i< stringLength-1; i++) { checksum += message[i] = s->read(); } if(s->read() != checksum || s->read() != STOP_BYTE) return 0; return 1; } else { return 0; } } template <class USerial> // This Helper function is coupled with Serialio function in Matlab void write_data(uint8_t writeBytes[], uint8_t messID, uint8_t stringLength, USerial *s) { // NB. String length is basically the message + the iD, so mess length plus 1 // Write Header s->write(START_BYTE); // 1.These 2 bytes are 'start message' s->write(stringLength); // 2.String length is basically the message + the iD, so mess length plus 1 s->write(messID); // 3.From above table // Write Message uint8_t checksum = START_BYTE+messID+stringLength; for (int i=0;i<(stringLength-1);++i) { s->write(writeBytes[i]); checksum += writeBytes[i]; // Compute checksum } // Write Checksum s->write(checksum); // s->write(STOP_BYTE); // } //_______________________________________ // Global Functions template <class USerial> // This function is coupled with Serialio function in Matlab boolean Read_gains(USerial *s) { if(read_data(s, Gains.GAINmessage, 0x01, 0x25)){ for (int i = 0; i < 3; i++) { kp_p[i] = Gains.v.PGain[i];//kp[i] = Gains.v.PGain[i];//kvp[i] = Gains.v.PGain[i];// kp_i[i] = Gains.v.IGain[i];//ki[i] = Gains.v.IGain[i];//kvi[i] = Gains.v.IGain[i];// kp_d[i] = Gains.v.DGain[i];//kd[i] = Gains.v.DGain[i];//kvd[i] = Gains.v.DGain[i];// } return 1; }else{ return 0; } } template <class USerial> // This function is coupled with Serialio function in Matlab void Boardcast_Gains(USerial *s) { for (int i = 0; i < 3; i++) { Gains.v.PGain[i] = kp_p[i];//Gains.v.PGain[i] = kp[i];//kvp[i];// Gains.v.IGain[i] = kp_i[i];//Gains.v.IGain[i] = ki[i];//kvi[i];// Gains.v.DGain[i] = kp_d[i];//Gains.v.DGain[i] = kd[i];//kvd[i];// } write_data(Gains.GAINmessage, 0x01, 0x25, s); } template <class USerial> // This function is coupled with Serialio function in Matlab void Boardcast_status(USerial *s, float dt) { STATUS.v.q[0] = q[0]; STATUS.v.q[1] = q[1]; STATUS.v.q[2] = q[2]; STATUS.v.q[3] = q[3]; STATUS.v.qD[0] = sqrt(1.0 + Rd[0][0] + Rd[1][1] + Rd[2][2]) / 2.0; float w4 = (4.0 * STATUS.v.qD[0]); STATUS.v.qD[1] = (Rd[2][1] - Rd[1][2]) / w4; STATUS.v.qD[2] = (Rd[0][2] - Rd[2][0]) / w4; STATUS.v.qD[3] = (Rd[1][0] - Rd[0][1]) / w4; /*STATUS.v.qD[0] = qVision[0];//pVision[0];//SVOposition_w[1];// STATUS.v.qD[1] = qVision[1];//pVision[1];//SVOposition_w[2];// STATUS.v.qD[2] = qVision[2];//pVision[2];//SVOposition_w[3];// STATUS.v.qD[3] = qVision[3];//1.0;//accelD_smt[2];*/ STATUS.v.currentHeight = pVision[0];//vVision[1];//lambdaVision;//lambdaVision;//vVision_cf[1];//lambdaVision;//-omegaDelay_w[0];//SVOvelosity[1];//ultrasonic_alti;//flowAltitude;//R[2][2];//flowAltitude;//0;//AltiOutput[1];//flowVeloWorldSmt[0];//DotVeloD[1];//flowVeloWorld[0];//accelD[0];//flowVeloWorld[0]; STATUS.v.desireHeight = pVision[1];//vVision_raw[1];//lambdaVision;//vVision_raw[1];//lambdaVision;//lambdaVision;//vVision[1];//accelD_smt[0];//lambdaVision; //ultrasonic_valu;//veloD[2];//veloD[0];//flowVeloWorldSmtOld[0];//flowAltitude;//flowVeloWorldSmt[1];//1000.00/altiPeriod;//DotVeloD[2];//flowVeloWorld[1];//accelD[0];//veloD[2];//flowVeloWorld[1]; STATUS.v.currentVelox = pVision[2];//pVision[2];//flowVeloWorldSmt[0]; STATUS.v.desireVelox = posiD[0];//pVision[0];//acceSmt[0];//rosStatus;//posiD[1];//pVision_cf[2];//veloD[0]; STATUS.v.currentVeloy = posiD[1];//pVision[1];//(float)vision_available_;//posiD[2]; if (armed && onAir && enableControl){ STATUS.v.desireVeloy = posiD[2];//pVision[2];//1.0; }else { STATUS.v.desireVeloy = 0.0; } write_data(STATUS.message, 0x02, 0x3D, s); } #endif
Changliu52/UnicornTeensyDrone
libraries_teensy3.2/ros_lib/svo_msgs/Info.h
#ifndef _ROS_svo_msgs_Info_h #define _ROS_svo_msgs_Info_h #include <stdint.h> #include <string.h> #include <stdlib.h> #include "ros/msg.h" #include "std_msgs/Header.h" namespace svo_msgs { class Info : public ros::Msg { public: std_msgs::Header header; float processing_time; uint8_t keyframes_length; int32_t st_keyframes; int32_t * keyframes; int32_t num_matches; int32_t tracking_quality; int32_t stage; Info(): header(), processing_time(0), keyframes_length(0), keyframes(NULL), num_matches(0), tracking_quality(0), stage(0) { } virtual int serialize(unsigned char *outbuffer) const { int offset = 0; offset += this->header.serialize(outbuffer + offset); union { float real; uint32_t base; } u_processing_time; u_processing_time.real = this->processing_time; *(outbuffer + offset + 0) = (u_processing_time.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_processing_time.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_processing_time.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_processing_time.base >> (8 * 3)) & 0xFF; offset += sizeof(this->processing_time); *(outbuffer + offset++) = keyframes_length; *(outbuffer + offset++) = 0; *(outbuffer + offset++) = 0; *(outbuffer + offset++) = 0; for( uint8_t i = 0; i < keyframes_length; i++){ union { int32_t real; uint32_t base; } u_keyframesi; u_keyframesi.real = this->keyframes[i]; *(outbuffer + offset + 0) = (u_keyframesi.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_keyframesi.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_keyframesi.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_keyframesi.base >> (8 * 3)) & 0xFF; offset += sizeof(this->keyframes[i]); } union { int32_t real; uint32_t base; } u_num_matches; u_num_matches.real = this->num_matches; *(outbuffer + offset + 0) = (u_num_matches.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_num_matches.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_num_matches.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_num_matches.base >> (8 * 3)) & 0xFF; offset += sizeof(this->num_matches); union { int32_t real; uint32_t base; } u_tracking_quality; u_tracking_quality.real = this->tracking_quality; *(outbuffer + offset + 0) = (u_tracking_quality.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_tracking_quality.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_tracking_quality.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_tracking_quality.base >> (8 * 3)) & 0xFF; offset += sizeof(this->tracking_quality); union { int32_t real; uint32_t base; } u_stage; u_stage.real = this->stage; *(outbuffer + offset + 0) = (u_stage.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_stage.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_stage.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_stage.base >> (8 * 3)) & 0xFF; offset += sizeof(this->stage); return offset; } virtual int deserialize(unsigned char *inbuffer) { int offset = 0; offset += this->header.deserialize(inbuffer + offset); union { float real; uint32_t base; } u_processing_time; u_processing_time.base = 0; u_processing_time.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_processing_time.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_processing_time.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_processing_time.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->processing_time = u_processing_time.real; offset += sizeof(this->processing_time); uint8_t keyframes_lengthT = *(inbuffer + offset++); if(keyframes_lengthT > keyframes_length) this->keyframes = (int32_t*)realloc(this->keyframes, keyframes_lengthT * sizeof(int32_t)); offset += 3; keyframes_length = keyframes_lengthT; for( uint8_t i = 0; i < keyframes_length; i++){ union { int32_t real; uint32_t base; } u_st_keyframes; u_st_keyframes.base = 0; u_st_keyframes.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_st_keyframes.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_st_keyframes.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_st_keyframes.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->st_keyframes = u_st_keyframes.real; offset += sizeof(this->st_keyframes); memcpy( &(this->keyframes[i]), &(this->st_keyframes), sizeof(int32_t)); } union { int32_t real; uint32_t base; } u_num_matches; u_num_matches.base = 0; u_num_matches.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_num_matches.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_num_matches.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_num_matches.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->num_matches = u_num_matches.real; offset += sizeof(this->num_matches); union { int32_t real; uint32_t base; } u_tracking_quality; u_tracking_quality.base = 0; u_tracking_quality.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_tracking_quality.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_tracking_quality.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_tracking_quality.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->tracking_quality = u_tracking_quality.real; offset += sizeof(this->tracking_quality); union { int32_t real; uint32_t base; } u_stage; u_stage.base = 0; u_stage.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_stage.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_stage.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_stage.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->stage = u_stage.real; offset += sizeof(this->stage); return offset; } const char * getType(){ return "svo_msgs/Info"; }; const char * getMD5(){ return "175acf2e539a9219addbcbeafca8552f"; }; }; } #endif
Changliu52/UnicornTeensyDrone
unicorn/MyMatMath.h
<filename>unicorn/MyMatMath.h //©2016 <NAME> #ifndef MyMatrixMath_h #define MyMatrixMath_h #include "Arduino.h" // B = A void copy3(float A[3][3], float B[3][3]); void copy3(float A[3], float B[3]); // B = A' //__________________________________________ void transpose3(float A[3][3], float B[3][3]); // A = kA, // a = ka, // B = kA, // b = ka //__________________________________________ void scale3(float A[3][3], float k); void scale3(float a[3], float k); void scale3(float A[3][3], float k, float B[3][3]); void scale3(float a[3], float k, float b[3]); // c = a + b //_______________________________________ void add3(float a[3], float b[3], float c[3]); // c = a - b, // C = A - B //_______________________________________ void subtract3(float a[3], float b[3], float c[3]); void subtract3(float a[3][3], float b[3][3], float c[3][3]); // c = A*b, // C = A*B //_________________________________________ void multiply3(float A[3][3], float b[3], float c[3]); void multiply3(float A[3][3], float B[3][3], float C[3][3]); // a x b = c //________________________________________ void cross3(float a[3], float b[3], float* c); // ||a|| //________________________________________ float norm3(float a[3]); // b = Av //________________________________________ void veeSkew3(float A[3][3], float b[3]); // Print //_______________________________________ // Matrix Printing Routine // Uses tabs to separate numbers under assumption printed float width won't cause problems void matPrint(float* A, int m, int n, String label); void matPrint(float* A, int m, int n, HardwareSerial* s); // A^-1 //___________________________ int Invert(float* A, int n); // I void eye(float mat[10][10], float val); void eye(float mat[7][7], float val); void eye(float mat[3][3], float val); #endif
Changliu52/UnicornTeensyDrone
unicorn/selfieManager.h
<gh_stars>1-10 //©2016 <NAME> #ifndef __SELFIE_H__ #define __SELFIE_H__ #include <Arduino.h> //############## // function to update selfie button command //############## void update_selfie_command() { int timeNow = millis(); // button pressed if(digitalRead(selfie_pin) == HIGH){ // button hold for more than 1 seconds if(timeNow-selfie_timer > 1000){ selfie_timer = timeNow; // reset timer // change state if (vision_available_ !=1 && selfie_state ==selfieDISARM) return; selfie_state++; selfie_state = selfie_state%3; } // button NOT pressed } else { selfie_timer = timeNow; // reset timer } } //______________ // Reset selfie Command void reset_selfie_command() { selfie_timer = millis(); // reset timer selfie_state = selfieDISARM; // disARM quad } //###################### // functions to process selfie command //###################### void selfie_process_RC(float timeChange) { if (selfie_state == selfieACTIVE){ auto_control_process_RC(timeChange); } } void selfie_process_OUTTER() { if (selfie_state == selfieACTIVE){ auto_control_process_OUTTER(); } } void selfie_process_INNER(float timeChange) { // control activated if (selfie_state == selfieACTIVE) { auto_control_process_INNER(timeChange); // disARMed } else if (selfie_state == selfieDISARM) { motorsStop(); detach_attitude_controller(); detach_position_controller(); // motors minmum spin } else if (selfie_state == selfieMINSPIN) { motorsNeutr(); detach_attitude_controller(); detach_position_controller(); } } #endif
Changliu52/UnicornTeensyDrone
libraries_teensy3.2/FreeIMU/Calibration Files/calibrationTetherSLAM.h
/** * FreeIMU calibration header. Automatically generated by FreeIMU_GUI. * Do not edit manually unless you know what you are doing. */ #define CALIBRATION_H const int acc_off_x = 389; const int acc_off_y = 82; const int acc_off_z = 2083; const float acc_scale_x = 16294.721810; const float acc_scale_y = 16336.774940; const float acc_scale_z = 16621.171104; const int magn_off_x = -55; const int magn_off_y = -127; const int magn_off_z = -20; const float magn_scale_x = 522.100275; const float magn_scale_y = 490.744465; const float magn_scale_z = 466.478712;
Changliu52/UnicornTeensyDrone
unicorn/IMU_broadcaster.h
<gh_stars>1-10 //©2016 <NAME> #ifndef ROS_IMU_BROADCASTER_H_ #define ROS_IMU_BROADCASTER_H_ #include <geometry_msgs/TransformStamped.h> namespace tf { class IMUBroadcaster { public: IMUBroadcaster() : publisher_("teensy/imu", &internal_msg) {} void init(ros::NodeHandle &nh) { nh.advertise(publisher_); internal_msg.header.frame_id = "Teensy"; internal_msg.child_frame_id = "gravity"; } void sendTransform_teensy(ros::NodeHandle &nh, float* Q, float* accel) { internal_msg.header.frame_id = "Teensy"; internal_msg.transform.translation.x = accel[1]; internal_msg.transform.translation.y = accel[2]; internal_msg.transform.translation.z = accel[3]; internal_msg.transform.rotation.w = Q[0]; internal_msg.transform.rotation.x = Q[1]; internal_msg.transform.rotation.y = Q[2]; internal_msg.transform.rotation.z = Q[3]; internal_msg.header.stamp = nh.now(); publisher_.publish(&internal_msg); } void sendTransform_teensy_freeExposure(ros::NodeHandle &nh, float* Q, float* accel) { internal_msg.header.frame_id = "Exposure"; internal_msg.transform.translation.x = accel[1]; internal_msg.transform.translation.y = accel[2]; internal_msg.transform.translation.z = accel[3]; internal_msg.transform.rotation.w = Q[0]; internal_msg.transform.rotation.x = Q[1]; internal_msg.transform.rotation.y = Q[2]; internal_msg.transform.rotation.z = Q[3]; internal_msg.header.stamp = nh.now(); publisher_.publish(&internal_msg); } void sendTransform_reset(ros::NodeHandle &nh, float* Q, float* initPosition) { internal_msg.header.frame_id = "reset"; internal_msg.transform.translation.x = initPosition[0]; internal_msg.transform.translation.y = initPosition[1]; internal_msg.transform.translation.z = initPosition[2]; internal_msg.transform.rotation.w = Q[0]; internal_msg.transform.rotation.x = Q[1]; internal_msg.transform.rotation.y = Q[2]; internal_msg.transform.rotation.z = Q[3]; internal_msg.header.stamp = nh.now(); publisher_.publish(&internal_msg); } private: geometry_msgs::TransformStamped internal_msg; ros::Publisher publisher_; }; } #endif
Changliu52/UnicornTeensyDrone
libraries_teensy3.2/FreeIMU/Calibration Files/calibrationTilty.h
/** * FreeIMU calibration header. Automatically generated by FreeIMU_GUI. * Do not edit manually unless you know what you are doing. */ #define CALIBRATION_H const int acc_off_x = 240; const int acc_off_y = -103; const int acc_off_z = -1040; const float acc_scale_x = 16527.832968; const float acc_scale_y = 16362.661637; const float acc_scale_z = 16683.945280; const int magn_off_x = 582; const int magn_off_y = -93; const int magn_off_z = -173; const float magn_scale_x = 545.169762; const float magn_scale_y = 537.496807; const float magn_scale_z = 522.795161;
Changliu52/UnicornTeensyDrone
libraries_teensy3.2/FreeIMU/Calibration Files/calibration250solo.h
/** * FreeIMU calibration header. Automatically generated by FreeIMU_GUI. * Do not edit manually unless you know what you are doing. */ #define CALIBRATION_H const int acc_off_x = 273; const int acc_off_y = 60; const int acc_off_z = 2297; const float acc_scale_x = 16292.892636; const float acc_scale_y = 16452.125894; const float acc_scale_z = 16718.925861; const int magn_off_x = -87; const int magn_off_y = -66; const int magn_off_z = 147; const float magn_scale_x = 561.265766; const float magn_scale_y = 515.504362; const float magn_scale_z = 471.026031;
Changliu52/UnicornTeensyDrone
libraries_teensy3.2/FreeIMU/Calibration Files/calibrationFlipensy2.h
<filename>libraries_teensy3.2/FreeIMU/Calibration Files/calibrationFlipensy2.h /** * FreeIMU calibration header. Automatically generated by FreeIMU_GUI. * Do not edit manually unless you know what you are doing. */ #define CALIBRATION_H const int acc_off_x = 267; const int acc_off_y = 2; const int acc_off_z = 1607; const float acc_scale_x = 16494.843304; const float acc_scale_y = 16448.809782; const float acc_scale_z = 16775.003024; const int magn_off_x = 32; const int magn_off_y = -101; const int magn_off_z = -21; const float magn_scale_x = 545.371699; const float magn_scale_y = 514.181197; const float magn_scale_z = 475.319744;
Changliu52/UnicornTeensyDrone
libraries_teensy3.2/AP_Filter/Butter.h
#ifndef __FILTER_BUTTER_H__ #define __FILTER_BUTTER_H__ //#include <AP_HAL.h> template <typename Coefficients> class Butter2 { public: float filter(float input) { float newhist = input + Coefficients::Coef1*hist[1] + Coefficients::Coef2*hist[0]; float ret = (newhist + 2*hist[1] + hist[0])/Coefficients::GAIN; hist[0] = hist[1]; hist[1] = newhist; return ret; } private: float hist[2]; }; struct butter100_025_coeffs { #if defined(__AVR__) || defined(__ARDUINO_X86__) || defined(__SAM3X8E__) static const float Coef1 = 1.9777864838f; static const float Coef2 = -0.9780305085f; static const float GAIN = 1.639178228e+04f; #else static constexpr float Coef1 = 1.9777864838f; static constexpr float Coef2 = -0.9780305085f; static constexpr float GAIN = 1.639178228e+04f; #endif }; typedef Butter2<butter100_025_coeffs> butter100hz0_25; //100hz sample, 0.25hz fcut typedef Butter2<butter100_025_coeffs> butter50hz0_125; //50hz sample, 0.125hz fcut typedef Butter2<butter100_025_coeffs> butter10hz0_025; //10hz sample, 0.025hz fcut struct butter100_05_coeffs { #if defined(__AVR__) || defined(__ARDUINO_X86__) || defined(__SAM3X8E__) static const float Coef1 = 1.9555782403f; static const float Coef2 = -0.9565436765f; static const float GAIN = 4.143204922e+03f; #else static constexpr float Coef1 = 1.9555782403f; static constexpr float Coef2 = -0.9565436765f; static constexpr float GAIN = 4.143204922e+03f; #endif }; typedef Butter2<butter100_05_coeffs> butter100hz0_5; //100hz sample, 0.5hz fcut typedef Butter2<butter100_05_coeffs> butter50hz0_25; //50hz sample, 0.25hz fcut typedef Butter2<butter100_05_coeffs> butter10hz0_05; //10hz sample, 0.05hz fcut struct butter100_1_coeffs { #if defined(__AVR__) || defined(__ARDUINO_X86__) || defined(__SAM3X8E__) static const float Coef1 = 1.9111970674f; static const float Coef2 = -0.9149758348f; static const float GAIN = 1.058546241e+03f; #else static constexpr float Coef1 = 1.9111970674f; static constexpr float Coef2 = -0.9149758348f; static constexpr float GAIN = 1.058546241e+03f; #endif }; typedef Butter2<butter100_1_coeffs> butter100hz1_0; //100hz sample, 1hz fcut typedef Butter2<butter100_1_coeffs> butter50hz0_5; //50hz sample, 0.5hz fcut typedef Butter2<butter100_1_coeffs> butter10hz0_1; //10hz sample, 0.1hz fcut struct butter100_1_5_coeffs { #if defined(__AVR__) || defined(__ARDUINO_X86__) || defined(__SAM3X8E__) static const float Coef1 = 1.8668922797f; static const float Coef2 = -0.8752145483f; static const float GAIN = 4.806381793e+02f; #else static constexpr float Coef1 = 1.8668922797f; static constexpr float Coef2 = -0.8752145483f; static constexpr float GAIN = 4.806381793e+02f; #endif }; typedef Butter2<butter100_1_5_coeffs> butter100hz1_5; //100hz sample, 1.5hz fcut typedef Butter2<butter100_1_5_coeffs> butter50hz0_75; //50hz sample, 0.75hz fcut typedef Butter2<butter100_1_5_coeffs> butter10hz0_15; //10hz sample, 0.15hz fcut struct butter100_2_coeffs { #if defined(__AVR__) || defined(__ARDUINO_X86__) || defined(__SAM3X8E__) static const float Coef1 = 1.8226949252f; static const float Coef2 = -0.8371816513f; static const float GAIN = 2.761148367e+02f; #else static constexpr float Coef1 = 1.8226949252f; static constexpr float Coef2 = -0.8371816513f; static constexpr float GAIN = 2.761148367e+02f; #endif }; typedef Butter2<butter100_2_coeffs> butter100hz2_0; //100hz sample, 2hz fcut typedef Butter2<butter100_2_coeffs> butter50hz1_0; //50hz sample, 1hz fcut typedef Butter2<butter100_2_coeffs> butter10hz0_2; //10hz sample, 0.2hz fcut struct butter100_3_coeffs { #if defined(__AVR__) || defined(__ARDUINO_X86__) || defined(__SAM3X8E__) static const float Coef1 = 1.7347257688f; static const float Coef2 = -0.7660066009f; static const float GAIN = 1.278738361e+02f; #else static constexpr float Coef1 = 1.7347257688f; static constexpr float Coef2 = -0.7660066009f; static constexpr float GAIN = 1.278738361e+02f; #endif }; typedef Butter2<butter100_3_coeffs> butter100hz3_0; //100hz sample, 3hz fcut typedef Butter2<butter100_3_coeffs> butter50hz1_5; //50hz sample, 1.5hz fcut typedef Butter2<butter100_3_coeffs> butter10hz0_3; //10hz sample, 0.3hz fcut struct butter100_4_coeffs { #if defined(__AVR__) || defined(__ARDUINO_X86__) || defined(__SAM3X8E__) static const float Coef1 = 1.6474599811f; static const float Coef2 = -0.7008967812f; static const float GAIN = 7.485478157e+01f; #else static constexpr float Coef1 = 1.6474599811f; static constexpr float Coef2 = -0.7008967812f; static constexpr float GAIN = 7.485478157e+01f; #endif }; typedef Butter2<butter100_4_coeffs> butter100hz4_0; //100hz sample, 4hz fcut typedef Butter2<butter100_4_coeffs> butter50hz2_0; //50hz sample, 2hz fcut typedef Butter2<butter100_4_coeffs> butter10hz0_4; //10hz sample, .4hz fcut struct butter100_8_coeffs { #if defined(__AVR__) || defined(__ARDUINO_X86__) || defined(__SAM3X8E__) static const float Coef1 = 1.3072850288f; static const float Coef2 = -0.4918122372f; static const float GAIN = 2.167702007e+01f; #else static constexpr float Coef1 = 1.3072850288f; static constexpr float Coef2 = -0.4918122372f; static constexpr float GAIN = 2.167702007e+01f; #endif }; typedef Butter2<butter100_8_coeffs> butter100hz8_0; //100hz sample, 8hz fcut typedef Butter2<butter100_8_coeffs> butter50hz4_0; //50hz sample, 4hz fcut typedef Butter2<butter100_8_coeffs> butter10hz0_8; //10hz sample, .8hz fcut struct butter50_8_coeffs { #if defined(__AVR__) || defined(__ARDUINO_X86__) || defined(__SAM3X8E__) static const float Coef1 = 0.6710290908f; static const float Coef2 = -0.2523246263f; static const float GAIN = 6.881181354e+00f; #else static constexpr float Coef1 = 0.6710290908f; static constexpr float Coef2 = -0.2523246263f; static constexpr float GAIN = 6.881181354e+00f; #endif }; typedef Butter2<butter50_8_coeffs> butter50hz8_0; //50hz sample, 8hz fcut typedef Butter2<butter50_8_coeffs> butter10hz1_6; //10hz sample, 1.6hz fcut #endif // __FILTER_BUTTER_H__
Changliu52/UnicornTeensyDrone
libraries_teensy3.2/ros_lib/mavros/Waypoint.h
#ifndef _ROS_mavros_Waypoint_h #define _ROS_mavros_Waypoint_h #include <stdint.h> #include <string.h> #include <stdlib.h> #include "ros/msg.h" namespace mavros { class Waypoint : public ros::Msg { public: uint8_t frame; uint16_t command; bool is_current; bool autocontinue; float param1; float param2; float param3; float param4; float x_lat; float y_long; float z_alt; enum { FRAME_GLOBAL = 0 }; enum { FRAME_LOCAL_NED = 1 }; enum { FRAME_MISSION = 2 }; enum { FRAME_GLOBAL_REL_ALT = 3 }; enum { FRAME_LOCAL_ENU = 4 }; enum { NAV_WAYPOINT = 16 }; enum { NAV_LOITER_UNLIM = 17 }; enum { NAV_LOITER_TURNS = 18 }; enum { NAV_LOITER_TIME = 19 }; enum { NAV_RETURN_TO_LAUNCH = 20 }; enum { NAV_LAND = 21 }; enum { NAV_TAKEOFF = 22 }; Waypoint(): frame(0), command(0), is_current(0), autocontinue(0), param1(0), param2(0), param3(0), param4(0), x_lat(0), y_long(0), z_alt(0) { } virtual int serialize(unsigned char *outbuffer) const { int offset = 0; *(outbuffer + offset + 0) = (this->frame >> (8 * 0)) & 0xFF; offset += sizeof(this->frame); *(outbuffer + offset + 0) = (this->command >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (this->command >> (8 * 1)) & 0xFF; offset += sizeof(this->command); union { bool real; uint8_t base; } u_is_current; u_is_current.real = this->is_current; *(outbuffer + offset + 0) = (u_is_current.base >> (8 * 0)) & 0xFF; offset += sizeof(this->is_current); union { bool real; uint8_t base; } u_autocontinue; u_autocontinue.real = this->autocontinue; *(outbuffer + offset + 0) = (u_autocontinue.base >> (8 * 0)) & 0xFF; offset += sizeof(this->autocontinue); union { float real; uint32_t base; } u_param1; u_param1.real = this->param1; *(outbuffer + offset + 0) = (u_param1.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_param1.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_param1.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_param1.base >> (8 * 3)) & 0xFF; offset += sizeof(this->param1); union { float real; uint32_t base; } u_param2; u_param2.real = this->param2; *(outbuffer + offset + 0) = (u_param2.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_param2.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_param2.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_param2.base >> (8 * 3)) & 0xFF; offset += sizeof(this->param2); union { float real; uint32_t base; } u_param3; u_param3.real = this->param3; *(outbuffer + offset + 0) = (u_param3.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_param3.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_param3.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_param3.base >> (8 * 3)) & 0xFF; offset += sizeof(this->param3); union { float real; uint32_t base; } u_param4; u_param4.real = this->param4; *(outbuffer + offset + 0) = (u_param4.base >> (8 * 0)) & 0xFF; *(outbuffer + offset + 1) = (u_param4.base >> (8 * 1)) & 0xFF; *(outbuffer + offset + 2) = (u_param4.base >> (8 * 2)) & 0xFF; *(outbuffer + offset + 3) = (u_param4.base >> (8 * 3)) & 0xFF; offset += sizeof(this->param4); offset += serializeAvrFloat64(outbuffer + offset, this->x_lat); offset += serializeAvrFloat64(outbuffer + offset, this->y_long); offset += serializeAvrFloat64(outbuffer + offset, this->z_alt); return offset; } virtual int deserialize(unsigned char *inbuffer) { int offset = 0; this->frame = ((uint8_t) (*(inbuffer + offset))); offset += sizeof(this->frame); this->command = ((uint16_t) (*(inbuffer + offset))); this->command |= ((uint16_t) (*(inbuffer + offset + 1))) << (8 * 1); offset += sizeof(this->command); union { bool real; uint8_t base; } u_is_current; u_is_current.base = 0; u_is_current.base |= ((uint8_t) (*(inbuffer + offset + 0))) << (8 * 0); this->is_current = u_is_current.real; offset += sizeof(this->is_current); union { bool real; uint8_t base; } u_autocontinue; u_autocontinue.base = 0; u_autocontinue.base |= ((uint8_t) (*(inbuffer + offset + 0))) << (8 * 0); this->autocontinue = u_autocontinue.real; offset += sizeof(this->autocontinue); union { float real; uint32_t base; } u_param1; u_param1.base = 0; u_param1.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_param1.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_param1.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_param1.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->param1 = u_param1.real; offset += sizeof(this->param1); union { float real; uint32_t base; } u_param2; u_param2.base = 0; u_param2.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_param2.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_param2.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_param2.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->param2 = u_param2.real; offset += sizeof(this->param2); union { float real; uint32_t base; } u_param3; u_param3.base = 0; u_param3.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_param3.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_param3.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_param3.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->param3 = u_param3.real; offset += sizeof(this->param3); union { float real; uint32_t base; } u_param4; u_param4.base = 0; u_param4.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0); u_param4.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1); u_param4.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2); u_param4.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3); this->param4 = u_param4.real; offset += sizeof(this->param4); offset += deserializeAvrFloat64(inbuffer + offset, &(this->x_lat)); offset += deserializeAvrFloat64(inbuffer + offset, &(this->y_long)); offset += deserializeAvrFloat64(inbuffer + offset, &(this->z_alt)); return offset; } const char * getType(){ return "mavros/Waypoint"; }; const char * getMD5(){ return "2173cf54c2af16a135dca8d104aae309"; }; }; } #endif
Changliu52/UnicornTeensyDrone
libraries_teensy3.2/FreeIMU/MadgwickAHRS.h
<reponame>Changliu52/UnicornTeensyDrone<gh_stars>1-10 //===================================================================================================== // MadgwickAHRS.c //===================================================================================================== // // Implementation of Madgwick's IMU and AHRS algorithms. // See: http://www.x-io.co.uk/node/8#open_source_ahrs_and_imu_algorithms // // Date Author Notes // 29/09/2011 <NAME> Initial release // 02/10/2011 <NAME> Optimised for reduced CPU load // 19/02/2012 <NAME> Magnetometer measurement is normalised // //===================================================================================================== #ifndef _MadgwickAHRS_ #define _MadgwickAHRS_ //--------------------------------------------------------------------------------------------------- // Header files #include <math.h> //--------------------------------------------------------------------------------------------------- // Definitions //#define sampleFreq 512.0f // sample frequency in Hz //#define betaDef 0.1f // 2 * proportional gain //--------------------------------------------------------------------------------------------------- // Variable definitions //volatile float beta = betaDef; // 2 * proportional gain (Kp) //volatile float q0 = 1.0f, q1 = 0.0f, q2 = 0.0f, q3 = 0.0f; // quaternion of sensor frame relative to auxiliary frame //--------------------------------------------------------------------------------------------------- // Function declarations //float invSqrt(float x); //==================================================================================================== // Functions //--------------------------------------------------------------------------------------------------- // AHRS algorithm update void FreeIMU::MadgwickAHRSupdate(float gx, float gy, float gz, float ax, float ay, float az, float mx, float my, float mz) { float recipNorm; float s0, s1, s2, s3; float qDot1, qDot2, qDot3, qDot4; float hx, hy; float _2q0mx, _2q0my, _2q0mz, _2q1mx, _2bx, _2bz, _4bx, _4bz, _2q0, _2q1, _2q2, _2q3, _2q0q2, _2q2q3, q0q0, q0q1, q0q2, q0q3, q1q1, q1q2, q1q3, q2q2, q2q3, q3q3; // Use IMU algorithm if magnetometer measurement invalid (avoids NaN in magnetometer normalisation) if((mx == 0.0f) && (my == 0.0f) && (mz == 0.0f)) { MadgwickAHRSupdateIMU(gx, gy, gz, ax, ay, az); return; } // Rate of change of quaternion from gyroscope qDot1 = 0.5f * (-q1 * gx - q2 * gy - q3 * gz); qDot2 = 0.5f * (q0 * gx + q2 * gz - q3 * gy); qDot3 = 0.5f * (q0 * gy - q1 * gz + q3 * gx); qDot4 = 0.5f * (q0 * gz + q1 * gy - q2 * gx); // Compute feedback only if accelerometer measurement valid (avoids NaN in accelerometer normalisation) if(!((ax == 0.0f) && (ay == 0.0f) && (az == 0.0f))) { // Normalise accelerometer measurement recipNorm = invSqrt(ax * ax + ay * ay + az * az); ax *= recipNorm; ay *= recipNorm; az *= recipNorm; // Normalise magnetometer measurement recipNorm = invSqrt(mx * mx + my * my + mz * mz); mx *= recipNorm; my *= recipNorm; mz *= recipNorm; // Auxiliary variables to avoid repeated arithmetic _2q0mx = 2.0f * q0 * mx; _2q0my = 2.0f * q0 * my; _2q0mz = 2.0f * q0 * mz; _2q1mx = 2.0f * q1 * mx; _2q0 = 2.0f * q0; _2q1 = 2.0f * q1; _2q2 = 2.0f * q2; _2q3 = 2.0f * q3; _2q0q2 = 2.0f * q0 * q2; _2q2q3 = 2.0f * q2 * q3; q0q0 = q0 * q0; q0q1 = q0 * q1; q0q2 = q0 * q2; q0q3 = q0 * q3; q1q1 = q1 * q1; q1q2 = q1 * q2; q1q3 = q1 * q3; q2q2 = q2 * q2; q2q3 = q2 * q3; q3q3 = q3 * q3; // Reference direction of Earth's magnetic field hx = mx * q0q0 - _2q0my * q3 + _2q0mz * q2 + mx * q1q1 + _2q1 * my * q2 + _2q1 * mz * q3 - mx * q2q2 - mx * q3q3; hy = _2q0mx * q3 + my * q0q0 - _2q0mz * q1 + _2q1mx * q2 - my * q1q1 + my * q2q2 + _2q2 * mz * q3 - my * q3q3; _2bx = sqrt(hx * hx + hy * hy); _2bz = -_2q0mx * q2 + _2q0my * q1 + mz * q0q0 + _2q1mx * q3 - mz * q1q1 + _2q2 * my * q3 - mz * q2q2 + mz * q3q3; _4bx = 2.0f * _2bx; _4bz = 2.0f * _2bz; // Gradient decent algorithm corrective step s0 = -_2q2 * (2.0f * q1q3 - _2q0q2 - ax) + _2q1 * (2.0f * q0q1 + _2q2q3 - ay) - _2bz * q2 * (_2bx * (0.5f - q2q2 - q3q3) + _2bz * (q1q3 - q0q2) - mx) + (-_2bx * q3 + _2bz * q1) * (_2bx * (q1q2 - q0q3) + _2bz * (q0q1 + q2q3) - my) + _2bx * q2 * (_2bx * (q0q2 + q1q3) + _2bz * (0.5f - q1q1 - q2q2) - mz); s1 = _2q3 * (2.0f * q1q3 - _2q0q2 - ax) + _2q0 * (2.0f * q0q1 + _2q2q3 - ay) - 4.0f * q1 * (1 - 2.0f * q1q1 - 2.0f * q2q2 - az) + _2bz * q3 * (_2bx * (0.5f - q2q2 - q3q3) + _2bz * (q1q3 - q0q2) - mx) + (_2bx * q2 + _2bz * q0) * (_2bx * (q1q2 - q0q3) + _2bz * (q0q1 + q2q3) - my) + (_2bx * q3 - _4bz * q1) * (_2bx * (q0q2 + q1q3) + _2bz * (0.5f - q1q1 - q2q2) - mz); s2 = -_2q0 * (2.0f * q1q3 - _2q0q2 - ax) + _2q3 * (2.0f * q0q1 + _2q2q3 - ay) - 4.0f * q2 * (1 - 2.0f * q1q1 - 2.0f * q2q2 - az) + (-_4bx * q2 - _2bz * q0) * (_2bx * (0.5f - q2q2 - q3q3) + _2bz * (q1q3 - q0q2) - mx) + (_2bx * q1 + _2bz * q3) * (_2bx * (q1q2 - q0q3) + _2bz * (q0q1 + q2q3) - my) + (_2bx * q0 - _4bz * q2) * (_2bx * (q0q2 + q1q3) + _2bz * (0.5f - q1q1 - q2q2) - mz); s3 = _2q1 * (2.0f * q1q3 - _2q0q2 - ax) + _2q2 * (2.0f * q0q1 + _2q2q3 - ay) + (-_4bx * q3 + _2bz * q1) * (_2bx * (0.5f - q2q2 - q3q3) + _2bz * (q1q3 - q0q2) - mx) + (-_2bx * q0 + _2bz * q2) * (_2bx * (q1q2 - q0q3) + _2bz * (q0q1 + q2q3) - my) + _2bx * q1 * (_2bx * (q0q2 + q1q3) + _2bz * (0.5f - q1q1 - q2q2) - mz); recipNorm = invSqrt(s0 * s0 + s1 * s1 + s2 * s2 + s3 * s3); // normalise step magnitude s0 *= recipNorm; s1 *= recipNorm; s2 *= recipNorm; s3 *= recipNorm; // Apply feedback step qDot1 -= beta * s0; qDot2 -= beta * s1; qDot3 -= beta * s2; qDot4 -= beta * s3; } // Integrate rate of change of quaternion to yield quaternion q0 += qDot1 * (1.0f / sampleFreq); q1 += qDot2 * (1.0f / sampleFreq); q2 += qDot3 * (1.0f / sampleFreq); q3 += qDot4 * (1.0f / sampleFreq); // Normalise quaternion recipNorm = invSqrt(q0 * q0 + q1 * q1 + q2 * q2 + q3 * q3); q0 *= recipNorm; q1 *= recipNorm; q2 *= recipNorm; q3 *= recipNorm; } //--------------------------------------------------------------------------------------------------- // IMU algorithm update void FreeIMU::MadgwickAHRSupdateIMU(float gx, float gy, float gz, float ax, float ay, float az) { float recipNorm; float s0, s1, s2, s3; float qDot1, qDot2, qDot3, qDot4; float _2q0, _2q1, _2q2, _2q3, _4q0, _4q1, _4q2 ,_8q1, _8q2, q0q0, q1q1, q2q2, q3q3; // Rate of change of quaternion from gyroscope qDot1 = 0.5f * (-q1 * gx - q2 * gy - q3 * gz); qDot2 = 0.5f * (q0 * gx + q2 * gz - q3 * gy); qDot3 = 0.5f * (q0 * gy - q1 * gz + q3 * gx); qDot4 = 0.5f * (q0 * gz + q1 * gy - q2 * gx); // Compute feedback only if accelerometer measurement valid (avoids NaN in accelerometer normalisation) if(!((ax == 0.0f) && (ay == 0.0f) && (az == 0.0f))) { // Normalise accelerometer measurement recipNorm = invSqrt(ax * ax + ay * ay + az * az); ax *= recipNorm; ay *= recipNorm; az *= recipNorm; // Auxiliary variables to avoid repeated arithmetic _2q0 = 2.0f * q0; _2q1 = 2.0f * q1; _2q2 = 2.0f * q2; _2q3 = 2.0f * q3; _4q0 = 4.0f * q0; _4q1 = 4.0f * q1; _4q2 = 4.0f * q2; _8q1 = 8.0f * q1; _8q2 = 8.0f * q2; q0q0 = q0 * q0; q1q1 = q1 * q1; q2q2 = q2 * q2; q3q3 = q3 * q3; // Gradient decent algorithm corrective step s0 = _4q0 * q2q2 + _2q2 * ax + _4q0 * q1q1 - _2q1 * ay; s1 = _4q1 * q3q3 - _2q3 * ax + 4.0f * q0q0 * q1 - _2q0 * ay - _4q1 + _8q1 * q1q1 + _8q1 * q2q2 + _4q1 * az; s2 = 4.0f * q0q0 * q2 + _2q0 * ax + _4q2 * q3q3 - _2q3 * ay - _4q2 + _8q2 * q1q1 + _8q2 * q2q2 + _4q2 * az; s3 = 4.0f * q1q1 * q3 - _2q1 * ax + 4.0f * q2q2 * q3 - _2q2 * ay; recipNorm = invSqrt(s0 * s0 + s1 * s1 + s2 * s2 + s3 * s3); // normalise step magnitude s0 *= recipNorm; s1 *= recipNorm; s2 *= recipNorm; s3 *= recipNorm; // Apply feedback step qDot1 -= beta * s0; qDot2 -= beta * s1; qDot3 -= beta * s2; qDot4 -= beta * s3; } // Integrate rate of change of quaternion to yield quaternion q0 += qDot1 * (1.0f / sampleFreq); q1 += qDot2 * (1.0f / sampleFreq); q2 += qDot3 * (1.0f / sampleFreq); q3 += qDot4 * (1.0f / sampleFreq); // Normalise quaternion recipNorm = invSqrt(q0 * q0 + q1 * q1 + q2 * q2 + q3 * q3); q0 *= recipNorm; q1 *= recipNorm; q2 *= recipNorm; q3 *= recipNorm; } //////////////////////////////////////////////// // Mine Function ©2016 <NAME> //_________________________________________________________________ // fuse vision with IMU ( here qv0, qv1, qv2, qv3 are quaternion measured from vision sensor) /////////////////////////////////////////////// void FreeIMU::MadgwickAHRSupdateIMU_vis(float gx, float gy, float gz, float ax, float ay, float az, float* qVision, HardwareSerial* XBee) { float recipNorm; float sVec[4]; float qDot1, qDot2, qDot3, qDot4; // Rate of change of quaternion from gyroscope gx -= gxb; gy -= gyb; gz -= gzb; qDot1 = 0.5f * (-q1 * gx - q2 * gy - q3 * gz); qDot2 = 0.5f * (q0 * gx + q2 * gz - q3 * gy); qDot3 = 0.5f * (q0 * gy - q1 * gz + q3 * gx); qDot4 = 0.5f * (q0 * gz + q1 * gy - q2 * gx); // Compute feedback only if accelerometer measurement valid (avoids NaN in accelerometer normalisation) if(!((ax == 0.0f) && (ay == 0.0f) && (az == 0.0f))) { // IMU fusion //##################### float _2q0, _2q1, _2q2, _2q3, _4q0, _4q1, _4q2 ,_8q1, _8q2, q0q0, q1q1, q2q2, q3q3; // Normalise accelerometer measurement recipNorm = invSqrt(ax * ax + ay * ay + az * az); ax *= recipNorm; ay *= recipNorm; az *= recipNorm; //XBee->print(gx); XBee->print(' '); XBee->print(gy); XBee->print(' '); XBee->println(gz); // Auxiliary variables to avoid repeated arithmetic _2q0 = 2.0f * q0; _2q1 = 2.0f * q1; _2q2 = 2.0f * q2; _2q3 = 2.0f * q3; _4q0 = 4.0f * q0; _4q1 = 4.0f * q1; _4q2 = 4.0f * q2; _8q1 = 8.0f * q1; _8q2 = 8.0f * q2; q0q0 = q0 * q0; q1q1 = q1 * q1; q2q2 = q2 * q2; q3q3 = q3 * q3; // Gradient decent algorithm corrective step sVec[0] = _4q0 * q2q2 + _2q2 * ax + _4q0 * q1q1 - _2q1 * ay; sVec[1] = _4q1 * q3q3 - _2q3 * ax + 4.0f * q0q0 * q1 - _2q0 * ay - _4q1 + _8q1 * q1q1 + _8q1 * q2q2 + _4q1 * az; sVec[2] = 4.0f * q0q0 * q2 + _2q0 * ax + _4q2 * q3q3 - _2q3 * ay - _4q2 + _8q2 * q1q1 + _8q2 * q2q2 + _4q2 * az; sVec[3] = 4.0f * q1q1 * q3 - _2q1 * ax + 4.0f * q2q2 * q3 - _2q2 * ay; // Vision Fusion //########################## if(((qVision[0] != 0.0f) || (qVision[1] != 0.0f) || (qVision[2] != 0.0f) || (qVision[3] != 0.0f)) && vision_available == 1) { float qSensor[4] = {q0, q1, q2, q3}; // sensor frame rotation float Ws_z[4] = {0.0, 0.0, 0.0, 1.0}; // z axis of sensor world frame float Ws_x[4] = {0.0, 1.0, 0.0, 0.0}; // x axis of sensor world frame // new//////// float S_x[4]; QuatRot(Ws_x, qSensor, S_x); // sensor x-axis in sensor world frame float qVisionCon[4] = {qVision[0], -qVision[1], -qVision[2], -qVision[3]}; float Wv_x[4]; QuatRot(S_x, qVisionCon, Wv_x);// ACTUAL x axis of vision world frame in sensor world frame recipNorm = invSqrt(Wv_x[1]*Wv_x[1] + Wv_x[2]*Wv_x[2]);//project to xy plane float _2Vx = 2.0*Wv_x[1]*recipNorm; // normalise float _2Vy = 2.0*Wv_x[2]*recipNorm; // new////// // Substitude equation //---------------- // 1. Compute vision x-axis field in vision frame // So we expecting // 2. f function (error function) f = Ws_xinS - Wv_xinS float fb[3] = {((2.0f-_2Vx)*(0.5f-(q2q2)-(q3q3))) - (_2Vy*(q1*q2+(q0*q3))), ((2.0f-_2Vx)*(q1*q2-(q0*q3))) - (_2Vy*(0.5f-(q1q1)-(q3q3))), ((2.0f-_2Vx)*(q0*q2+(q1*q3))) - (_2Vy*(q2*q3-(q0*q1)))}; //!!! // 3. Jacobian (assume Wv_x does not change with q: Wv_xinS is treated as a constant) float Jb[3][4] = {{ 0.0f, 0.0f, -4.0*q2, -4.0*q3}, {-2.0f*q3, 2.0f*q2, 2.0f*q1, -2.0f*q0}, { 2.0f*q2, 2.0f*q3, 2.0f*q0, 2.0f*q1}}; // Gradient decent algorithm corrective step (JbT * fb) s0v = Jb[0][0]*fb[0] + (Jb[1][0]*fb[1]) + (Jb[2][0]*fb[2]); s1v = Jb[0][1]*fb[0] + (Jb[1][1]*fb[1]) + (Jb[2][1]*fb[2]); s2v = Jb[0][2]*fb[0] + (Jb[1][2]*fb[1]) + (Jb[2][2]*fb[2]); s3v = Jb[0][3]*fb[0] + (Jb[1][3]*fb[1]) + (Jb[2][3]*fb[2]); //XBee->print(fb[0]); XBee->print(' '); XBee->print(fb[1]); XBee->print(' '); XBee->println(fb[2]); } if (vision_available != 1) { s0v = 0.0; s1v = 0.0; s2v = 0.0; s3v = 0.0; } // Add vision error feedback sVec[0] += s0v; sVec[1] += s1v; sVec[2] += s2v; sVec[3] += s3v; // compute gyro bias as the integral feedback float qSensorStar[4] = {q0, -q1, -q2, -q3}; float gE[4]; q_mult(qSensorStar, sVec, gE); // Compute angular error in each gyro axis (sensor frame) gxb += Exlong * 2.0f * gE[1] * (1.0f / sampleFreq); // integrate angular error to get bias estimation (Exlong is the gain) gyb += Exlong * 2.0f * gE[2] * (1.0f / sampleFreq); gzb += Exlong * 2.0f * gE[3] * (1.0f / sampleFreq); // normalise error vector recipNorm = invSqrt(sVec[0] * sVec[0] + sVec[1] * sVec[1] + sVec[2] * sVec[2] + sVec[3] * sVec[3]); // normalise step magnitude sVec[0] *= recipNorm; sVec[1] *= recipNorm; sVec[2] *= recipNorm; sVec[3] *= recipNorm; // Apply feedback step qDot1 -= beta * sVec[0]; qDot2 -= beta * sVec[1]; qDot3 -= beta * sVec[2]; qDot4 -= beta * sVec[3]; } // Integrate rate of change of quaternion to yield quaternion q0 += qDot1 * (1.0f / sampleFreq); q1 += qDot2 * (1.0f / sampleFreq); q2 += qDot3 * (1.0f / sampleFreq); q3 += qDot4 * (1.0f / sampleFreq); // Normalise quaternion recipNorm = invSqrt(q0 * q0 + q1 * q1 + q2 * q2 + q3 * q3); q0 *= recipNorm; q1 *= recipNorm; q2 *= recipNorm; q3 *= recipNorm; } /////////////////////////////////////////////// //__________________________________________________________________ //--------------------------------------------------------------------------------------------------- // Fast inverse square-root // See: http://en.wikipedia.org/wiki/Fast_inverse_square_root //float invSqrt(float x) { // float halfx = 0.5f * x; // float y = x; // long i = *(long*)&y; // i = 0x5f3759df - (i>>1); // y = *(float*)&i; // y = y * (1.5f - (halfx * y * y)); // return y; //} //==================================================================================================== // END OF CODE //==================================================================================================== #endif
Changliu52/UnicornTeensyDrone
libraries_teensy3.2/LPS331/LPS331.h
<reponame>Changliu52/UnicornTeensyDrone #ifndef LPS331_h #define LPS331_h #include <Arduino.h> // for byte data type // SA0 states #define LPS331_SA0_LOW 0 #define LPS331_SA0_HIGH 1 #define LPS331_SA0_AUTO 2 // register addresses // Note: Some of the register names in the datasheet are inconsistent // between Table 14 in section 6 and the register descriptions in // section 7. Where they differ, the names from section 7 have been // used here. #define LPS331_REF_P_XL 0x08 #define LPS331_REF_P_L 0x09 #define LPS331_REF_P_H 0x0A #define LPS331_WHO_AM_I 0x0F #define LPS331_RES_CONF 0x10 #define LPS331_CTRL_REG1 0x20 #define LPS331_CTRL_REG2 0x21 #define LPS331_CTRL_REG3 0x22 #define LPS331_INTERRUPT_CFG 0x23 #define LPS331_INT_SOURCE 0x24 #define LPS331_THS_P_L 0x25 #define LPS331_THS_P_H 0x26 #define LPS331_STATUS_REG 0x27 #define LPS331_PRESS_OUT_XL 0x28 #define LPS331_PRESS_OUT_L 0x29 #define LPS331_PRESS_OUT_H 0x2A #define LPS331_TEMP_OUT_L 0x2B #define LPS331_TEMP_OUT_H 0x2C #define LPS331_AMP_CTRL 0x30 #define LPS331_DELTA_PRESS_XL 0x3C #define LPS331_DELTA_PRESS_L 0x3D #define LPS331_DELTA_PRESS_H 0x3E class LPS331 { public: LPS331(void); bool init(byte sa0 = LPS331_SA0_AUTO); void enableDefault(void); void writeReg(byte reg, byte value); byte readReg(byte reg); float readPressureMillibars(void); float readPressureInchesHg(void); long readPressureRaw(void); float readTemperatureC(void); float readTemperatureF(void); int readTemperatureRaw(void); static float pressureToAltitudeMeters(float pressure_mbar, float altimeter_setting_mbar = 1013.25); static float pressureToAltitudeFeet(float pressure_inHg, float altimeter_setting_inHg = 29.9213); private: byte address; bool autoDetectAddress(void); bool testWhoAmI(void); }; #endif
marceloh220/XPT2046_TOUCH_MBEDOS
touch.h
#ifndef _TOUCH_H_ #define _TOUCH_H_ #include "mbed.h" #endif
Qiaowen-Jia/java-ranger
src/examples/concolic/concolic_BesselImp.c
/* The BesselImp.c file, which implements the native function */ #include <jni.h> /* Java Native Interface headers */ #include "concolic_Bessel.h" /* Auto-generated header created by javah -jni */ #include <math.h> /* Include math.h for the prototype of function y0 */ /* Our C definition of the function bessely0 declared in Bessel.java */ JNIEXPORT jdouble JNICALL Java_concolic_Bessel_bessely0(JNIEnv *env, jobject obj, jdouble x) { double y; /* Call the Y0(x) Bessel function from the standard C mathematical library */ y = y0(x); return y; }
Gip-Gip/Sweer
common/include/ssln_sub.h
/* ssln_sub.h - includes files needed by ssln_sub.c ENUMS: TYPEDEFS: DEFINITIONS: MACROS: */ #ifndef SSLN_SUB_H #include <ssln_cmn.h> #define FREEALL() {ssln_rid(workingSubtrahend); ssln_rid(workingMinuend);} #define SSLN_SUB_H NULL #endif
Gip-Gip/Sweer
common/include/ssln_typ.h
/* ssln_typ.h - defines the types used by ssln ENUMS: TYPEDEFS: DEFINITIONS: MACROS: */ #ifndef SSLN_TYP_H #include <ssln_def.h> typedef long int natural; typedef unsigned char numeral; typedef char character; typedef character * string; typedef enum { none, err_errno, } ssln_error; typedef enum { false, true, neither, } bool; typedef struct { bool negative; bool literal; ssln_error error; natural integerSize; natural fractionalSize; numeral *integer; numeral *fractional; } ssln; #define SSLN_TYP_H NULL #endif
Gip-Gip/Sweer
common/include/ssln_cmn.h
<gh_stars>0 /* ssln_cmn.h - includes files needed all around the Sweer project ENUMS: TYPEDEFS: DEFINITIONS: MACROS: */ #ifndef SSLN_CMN_H #include <stdlib.h> #include <string.h> #include <errno.h> #include <ssln_typ.h> #include <ssln_mac.h> extern string ssln_numTable[]; extern ssln ssln_eEr(); extern ssln ssln_new(void); extern ssln ssln_set(ssln *, ssln); extern ssln ssln_adi(ssln *); extern ssln ssln_i2n(natural); extern string ssln_sap(string, string, bool, bool); extern void ssln_rid(ssln); extern bool ssln_cmp(ssln, ssln); extern bool ssln_gt(ssln, ssln); extern ssln ssln_add(ssln, ssln); extern ssln ssln_sub(ssln, ssln); extern ssln ssln_div(ssln, ssln); extern ssln ssln_mod(ssln, ssln); extern natural ssln_n2i(ssln); extern ssln ssln_ras(ssln, natural); #define SSLN_CMN_H NULL #endif
Gip-Gip/Sweer
common/include/ssln_add.h
/* ssln_add.h - includes files needed by ssln_add.c ENUMS: TYPEDEFS: DEFINITIONS: MACROS: */ #ifndef SSLN_ADD_H #include <ssln_cmn.h> #define FREEALL() SSLN_CLNLIT(addend); #define SSLN_ADD_H NULL #endif
Gip-Gip/Sweer
common/include/ssln_adi.h
/* ssln_adi.h - includes files needed by ssln_adi.c ENUMS: TYPEDEFS: DEFINITIONS: MACROS: */ #ifndef SSLN_ADI_H #include <ssln_cmn.h> #define SSLN_ADI_H NULL #endif
Gip-Gip/Sweer
common/ssln_new.c
<filename>common/ssln_new.c /* ssln_new - returns a new large number ARGUMENTS: VARIABLES: ssln ret - the new large number being returned */ #include <ssln_cmn.h> ssln ssln_new() { ssln ret; ret.negative = false; ret.literal = false; ret.error = none; ret.integerSize = NUMALLOC; ret.fractionalSize = NUMALLOC; if(!(ret.integer = calloc(NUMALLOC, sizeof(numeral))) || !(ret.fractional = calloc(NUMALLOC, sizeof(numeral)))) ret.error = err_errno + errno; return ret; }
Gip-Gip/Sweer
common/include/ssln_gt.h
<gh_stars>0 /* ssln_gt.h - includes files needed by ssln_gt.c ENUMS: TYPEDEFS: DEFINITIONS: MACROS: */ #ifndef SSLN_GT_H #include <ssln_cmn.h> #define FREEALL() {ssln_rid(cmpnum1); ssln_rid(cmpnum2);} #define SSLN_GT_H NULL #endif
Gip-Gip/Sweer
common/ssln_adi.c
<filename>common/ssln_adi.c<gh_stars>0 /* ssln_adi - adds a single numeral to the end of an ssln's integer-part ARGUMENTS: ssln num - the number being added to VARIABLES: */ #include <ssln_adi.h> ssln ssln_adi(ssln *num) { if(!(num->integer = realloc(num->integer, num->integerSize += NUMALLOC))) num->error = err_errno + errno; num->integer[num->integerSize - ONE] = ZERO; return *(num); }
Gip-Gip/Sweer
common/include/ssln_str.h
<reponame>Gip-Gip/Sweer /* ssln_str.h - includes files for ssln_str.c ENUMS: TYPEDEFS: DEFINITIONS: MACROS: */ #ifndef SSLN_STR_H #include <ssln_cmn.h> #define SSLN_STR_H NULL #endif
Gip-Gip/Sweer
common/ssln_n2s.c
/* ssln_n2s - converts a number to a string of the desired base ARGUMENTS: ssln num - the number being converted natural base - the base to use VARIABLES: string ret - the string being returned */ #include <ssln_n2s.h> string ssln_n2s(ssln num, natural base) { string ret = calloc(STRALLOC, sizeof(character)); ssln workNum = ssln_new(); bool negative = num.negative; ssln_set(&workNum, num); workNum.negative = false; while(ssln_gt(workNum, SSLN_ZERO)) { ret = ssln_sap( ret, ssln_numTable[ssln_n2i(ssln_mod(workNum, ssln_i2n(base)))], true, false); ssln_set(&workNum, ssln_div(workNum, ssln_i2n(base))); } /* The string returned would be blank if the ssln was zero... */ if(!strlen(ret)) ret = ssln_sap(ret, ssln_numTable[ZERO], true, false); if(negative) ret = ssln_sap(ret, SSLN_NEG, true, false); ssln_rid(workNum); return ret; }
Gip-Gip/Sweer
common/include/ssln_eEr.h
/* ssln_eEr.h - includes files needed by ssln_eEr.c ENUMS: TYPEDEFS: DEFINITIONS: MACROS: */ #ifndef SSLN_EER_H #include <ssln_cmn.h> #define SSLN_EER_H NULL #endif
Gip-Gip/Sweer
common/ssln_n2i.c
/* ssln_n2i - converts SSLNs to integers ARGUMENTS: VARIABLES: */ #include <ssln_n2i.h> natural ssln_n2i(ssln src) { natural retInt = ZERO, numn = src.integerSize; while(numn--) { retInt <<= BYTESHFT; retInt = src.integer[numn]; } FREEALL(); return retInt; }
Gip-Gip/Sweer
common/ssln_mod.c
<gh_stars>0 /* ssln_div - divides the dividend by the divisor ARGUMENTS: ssln dividend ssln divisor VARIABLES: */ #include <ssln_mod.h> ssln ssln_mod(ssln dividend, ssln divisor) { ssln workingDividend = ssln_new(), workingDivisor = ssln_new(); natural raise = dividend.integerSize; ssln_set(&workingDividend, dividend); ssln_set(&workingDivisor, divisor); if(ssln_cmp(workingDivisor, SSLN_ZERO)) { FREEALL(); workingDividend.literal = true; return workingDividend; } while(ssln_gt(workingDividend, workingDivisor) || ssln_cmp(workingDividend, workingDivisor)) { while(ssln_gt(workingDividend, ssln_ras(workingDivisor, raise)) || ssln_cmp(workingDividend, ssln_ras(workingDivisor, raise))) { ssln_set( &workingDividend, ssln_sub(workingDividend, ssln_ras(workingDivisor, raise))); } raise --; } FREEALL(); workingDividend.literal = true; return workingDividend; }
Gip-Gip/Sweer
common/ssln_rid.c
/* ssln_rid - removes the given ssln from memory ARGUMENTS: ssln num - the ssln being removed VARIABLES: */ #include <ssln_rid.h> void ssln_rid(ssln num) { free(num.integer); free(num.fractional); }
Gip-Gip/Sweer
common/ssln_add.c
<gh_stars>0 /* ssln_add - adds two sslns together ARGUMENTS: ssln aguend ssln addend VARIABLES: */ #include <ssln_add.h> ssln ssln_add(ssln aguend, ssln addend) { ssln ret; natural numn = INDEXINIT, worknum; bool carry = false; if(aguend.negative & (!addend.negative)) { aguend.negative = false; ret = ssln_sub(aguend, addend); ret.negative = !ret.negative; return ret; } if((!aguend.negative) & addend.negative) { addend.negative = false; return ssln_sub(aguend, addend); } ret = ssln_new(); ret.literal = true; ssln_set(&ret, aguend); while(++numn < addend.integerSize || carry) { if(numn == ret.integerSize) ssln_adi(&ret); worknum = ret.integer[numn] + carry + (numn < addend.integerSize ? addend.integer[numn] : ZERO); ret.integer[numn] = worknum % CARRYNUM; carry = worknum / CARRYNUM; } FREEALL(); return ret; }
Gip-Gip/Sweer
include/sweer.h
/* sweer.h - a header for everything Sweer ENUMS: TYPEDEFS: DEFINITIONS: MACROS: */ #ifndef SWEER_H #ifndef NULL #define NULL #endif /* TYPEDEFS */ typedef long unsigned int natural; typedef unsigned char numeral; typedef char character; typedef character * string; typedef enum { ssln_err_none, ssln_err_errno, } ssln_error; typedef enum { false, true, neither, } bool; typedef struct { bool negative; bool literal; ssln_error error; natural integerSize; natural fractionalSize; numeral *integer; numeral *fractional; } ssln; /* VARIABLES */ extern string ssln_numTable; /* FUNCTIONS */ extern ssln ssln_eEr(natural); extern ssln ssln_new(void); extern ssln ssln_set(ssln *, ssln); extern ssln ssln_adi(ssln *); extern ssln ssln_i2n(natural); extern void ssln_rid(ssln); extern bool ssln_cmp(ssln, ssln); extern bool ssln_gt(ssln, ssln); extern ssln ssln_add(ssln, ssln); extern ssln ssln_sub(ssln, ssln); extern ssln ssln_div(ssln, ssln); extern ssln ssln_mod(ssln, ssln); extern string ssln_n2s(ssln, natural); #define SWEER_H NULL #endif
Gip-Gip/Sweer
common/include/ssln_mac.h
<reponame>Gip-Gip/Sweer<gh_stars>0 /* ssln_mac.h - defines a few handy macros ENUMS: TYPEDEFS: DEFINITIONS: MACROS: */ #ifndef SSLN_MAC_H #define SSLN_CLNLIT(num) if(num.literal) ssln_rid(num); #define SSLN_MAC_H NULL #endif
Gip-Gip/Sweer
common/include/ssln_cmp.h
<gh_stars>0 /* ssln_cmp.h - includes files needed by ssln_cmp.c ENUMS: TYPEDEFS: DEFINITIONS: MACROS: */ #ifndef SSLN_CMP_H #include <ssln_cmn.h> #define FREEALL() {SSLN_CLNLIT(num1); SSLN_CLNLIT(num2);} #define SSLN_CMP_H NULL #endif
Gip-Gip/Sweer
common/ssln_cmp.c
<gh_stars>0 /* ssln_cmp - compares two numbers and returns "true" if they are equal ARGUMENTS: VARIABLES: */ #include <ssln_cmp.h> bool ssln_cmp(ssln num1, ssln num2) { if(num1.negative == num2.negative && num1.integerSize == num2.integerSize && num1.fractionalSize == num2.fractionalSize && !memcmp(num1.integer, num2.integer, num1.integerSize) && !memcmp(num1.fractional, num2.fractional, num1.fractionalSize)) { FREEALL(); return true; } FREEALL(); return false; }
Gip-Gip/Sweer
common/ssln_ras.c
<reponame>Gip-Gip/Sweer /* ssln_ras - adds a given number of digits to an SSLN ARGUMENTS: ssln num natural raise VARIABLES: */ #include <ssln_cmn.h> ssln ssln_ras(ssln num, natural raise) { ssln workNum = ssln_new(), ret = ssln_new(); ssln_set(&ret, num); ssln_set(&workNum, ret); free(ret.integer); ret.integer = calloc(ret.integerSize += raise, sizeof(numeral)); memcpy(ret.integer + raise, workNum.integer, workNum.integerSize); ssln_rid(workNum); ret.literal = true; return ret; }
Gip-Gip/Sweer
common/ssln_set.c
<filename>common/ssln_set.c /* ssln_set - sets a ssln ARGUMENTS: ssln *dest - the number being set ssln src - the number being set to VARIABLES: */ #include <ssln_set.h> ssln ssln_set(ssln *dest, ssln src) { dest->negative = src.negative; dest->integerSize = src.integerSize; dest->fractionalSize = src.fractionalSize; if(!(dest->integer = realloc(dest->integer, src.integerSize)) || !(dest->fractional = realloc(dest->fractional, src.fractionalSize))) { dest->error = err_errno + errno; return *dest; } memcpy(dest->integer, src.integer, src.integerSize); memcpy(dest->fractional, src.fractional, src.fractionalSize); if(src.literal) ssln_rid(src); return *dest; }
Gip-Gip/Sweer
common/ssln_eEr.c
<filename>common/ssln_eEr.c<gh_stars>0 /* ssln_eEr - creates a ssln which will only used for the error embedded in it ARGUMENTS: natural error - the error to embed VARIABLES: ssln ret */ #include <ssln_eEr.h> ssln ssln_eEr(natural error) { ssln ret = ssln_new(); ret.literal = true; ret.error = error; return ret; }
Gip-Gip/Sweer
common/include/ssln_mod.h
/* ssln_mod.h - includes files needed by ssln_mod.c ENUMS: TYPEDEFS: DEFINITIONS: MACROS: */ #ifndef SSLN_MOD_H #include <ssln_cmn.h> #define FREEALL() {ssln_rid(workingDivisor);} #define SSLN_MOD_H NULL #endif
Gip-Gip/Sweer
common/include/ssln_n2i.h
/* ssln_n2i.h - includes files needed by ssln_n2i.c ENUMS: TYPEDEFS: DEFINITIONS: MACROS: */ #ifndef SSLN_N2I_H #include <ssln_cmn.h> #define FREEALL() {SSLN_CLNLIT(src);} #define SSLN_N2I_H NULL #endif
Gip-Gip/Sweer
common/ssln_i2n.c
/* ssln_i2n - converts integers to the ssln type ARGUMENTS: natural num - the integer being converted VARIABLES: */ #include <ssln_i2n.h> ssln ssln_i2n(natural num) { ssln ret = ssln_new(); natural numn = 0; ret.literal = true; while(num) { ret.integer[numn++] = num & FULLBYTE; num >>= BYTESHFT; if(num && ssln_adi(&ret).error) { return ret; } } return ret; }
Gip-Gip/Sweer
common/include/ssln_div.h
<reponame>Gip-Gip/Sweer /* ssln_div.h - includes files needed by ssln_div.c ENUMS: TYPEDEFS: DEFINITIONS: MACROS: */ #ifndef SSLN_DIV_H #include <ssln_cmn.h> #define FREEALL() {ssln_rid(workingDividend); ssln_rid(workingDivisor);} #define SSLN_DIV_H NULL #endif
Gip-Gip/Sweer
common/ssln_gt.c
/* ssln_gt - compares two SSLNs and sees if the first number is greater than the second number ARGUMENTS: ssln num1 ssln num2 VARIABLES: */ #include <ssln_gt.h> bool ssln_gt(ssln num1, ssln num2) { ssln cmpnum1 = ssln_new(), cmpnum2 = ssln_new(); natural numn = num1.integerSize; ssln_set(&cmpnum1, num1); ssln_set(&cmpnum2, num2); if(ssln_cmp(cmpnum1, cmpnum2) || cmpnum2.integerSize > cmpnum1.integerSize) { FREEALL(); return false; } if(cmpnum1.integerSize > cmpnum2.integerSize) { FREEALL(); return true; } while(numn--) { if(cmpnum1.integer[numn] > cmpnum2.integer[numn]) { FREEALL(); return true; } if(cmpnum2.integer[numn] > cmpnum1.integer[numn]) { FREEALL(); return false; } } FREEALL(); return false; }
Gip-Gip/Sweer
common/include/ssln_n2s.h
/* ssln_n2s.h - includes files needed by ssln_n2s.c ENUMS: TYPEDEFS: DEFINITIONS: MACROS: */ #ifndef SSLN_N2S_H #include <ssln_cmn.h> #define SSLN_N2S_H NULL #endif
Gip-Gip/Sweer
common/include/ssln_i2n.h
<gh_stars>0 /* ssln_i2s.h - includes files needed by ssln_i2s.c ENUMS: TYPEDEFS: DEFINITIONS: MACROS: */ #ifndef SSLN_I2S_H #include <ssln_cmn.h> #define SSLN_I2S_H NULL #endif
Gip-Gip/Sweer
common/ssln_sub.c
<filename>common/ssln_sub.c<gh_stars>0 /* ssln_sub - subtracts the from the first number ARGUMENTS: ssln subtrahend ssln minuend VARIABLES: */ #include <ssln_sub.h> ssln ssln_sub(ssln subtrahend, ssln minuend) { ssln difference, workingSubtrahend = ssln_new(), workingMinuend = ssln_new(); natural numn = INDEXINIT, worknum; bool carry = false; ssln_set(&workingSubtrahend, subtrahend); ssln_set(&workingMinuend, minuend); if(ssln_cmp(workingSubtrahend, workingMinuend)) { FREEALL(); return ssln_i2n(ZERO); } if(workingSubtrahend.negative & (!workingMinuend.negative)) { workingMinuend.negative = false; difference = ssln_add(workingMinuend, workingSubtrahend); difference.negative = true; return difference; } if((!workingSubtrahend.negative) & workingMinuend.negative) { workingMinuend.negative = false; return ssln_add(workingSubtrahend, workingMinuend); } difference = ssln_new(); if(ssln_gt(workingMinuend, workingSubtrahend)) { ssln_set(&difference, ssln_sub(workingMinuend, workingSubtrahend)); difference.literal = true; difference.negative = !difference.negative; FREEALL(); return difference; } ssln_set(&difference, workingSubtrahend); while(++numn < workingMinuend.integerSize || carry) { worknum = CARRYNUM + difference.integer[numn] - carry - (numn < workingMinuend.integerSize ? workingMinuend.integer[numn] : ZERO); carry = !(worknum / CARRYNUM); difference.integer[numn] = worknum % CARRYNUM; } numn = difference.integerSize; while(--numn && !difference.integer[numn]) difference.integerSize --; difference.literal = true; FREEALL(); return difference; }
Gip-Gip/Sweer
common/include/ssln_set.h
/* ssln_set.h - includes files needed by ssln_rid.c ENUMS: TYPEDEFS: DEFINITIONS: MACROS: */ #ifndef SSLN_SET_H #include <ssln_cmn.h> #define SSLN_SET_H NULL #endif
Gip-Gip/Sweer
common/include/ssln_rid.h
/* ssln_rid.h - includes files needed by ssln_rid.c ENUMS: TYPEDEFS: DEFINITIONS: MACROS: */ #ifndef SSLN_RID_H #include <ssln_cmn.h> #define SSLN_RID_H NULL #endif
Gip-Gip/Sweer
common/include/ssln_def.h
/* ssln_def.h - defines things needed by the entire project ENUMS: TYPEDEFS: DEFINITIONS: MACROS: */ #ifndef SSLN_DEF_H #ifndef NULL #define NULL 0 #endif #define ONE 1 #define ZERO 0 #define SSLN_ZERO ssln_i2n(ZERO) #define INDEXINIT -1 #define NUMALLOC 1 #define STRALLOC 1 #define FULLBYTE 0xFF #define BASE 256 #define BYTESHFT 8 #define CARRYNUM 256 #define SSLN_NEG "-" #define SSLN_DEF_H NULL #endif
Gip-Gip/Sweer
common/ssln_div.c
/* ssln_div - divides the dividend by the divisor ARGUMENTS: ssln dividend ssln divisor VARIABLES: */ #include <ssln_div.h> ssln ssln_div(ssln dividend, ssln divisor) { ssln quotent = ssln_new(), workingDividend = ssln_new(), workingDivisor = ssln_new(); natural raise = dividend.integerSize; ssln_set(&quotent, ssln_i2n(ZERO)); ssln_set(&workingDividend, dividend); ssln_set(&workingDivisor, divisor); while(ssln_gt(workingDividend, workingDivisor) || ssln_cmp(workingDividend, workingDivisor)) { while(ssln_gt(workingDividend, ssln_ras(workingDivisor, raise)) || ssln_cmp(workingDividend, ssln_ras(workingDivisor, raise))) { ssln_set( &workingDividend, ssln_sub(workingDividend, ssln_ras(workingDivisor, raise))); ssln_set( &quotent, ssln_add(quotent, ssln_ras(ssln_i2n(ONE), raise))); } raise --; } FREEALL(); quotent.literal = true; return quotent; }
Gip-Gip/Sweer
common/include/ssln_sap.h
/* ssln_mod.h - includes files needed by ssln_mod.c ENUMS: TYPEDEFS: DEFINITIONS: MACROS: */ #ifndef SSLN_SAP_H #include <ssln_cmn.h> #define SSLN_SAP_H NULL #endif
HighStakesCoin/HighStakes
src/qt/newsdialog.h
<gh_stars>1-10 // Copyright (c) 2017-2018 The PIVX developers // Copyright (c) 2019 The HighStakes developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #ifndef BITCOIN_QT_NEWSDIALOG_H #define BITCOIN_QT_NEWSDIALOG_H #include "guiutil.h" #include <QLabel> #include <QMainWindow> #include <QMap> #include <QMenu> #include <QPoint> #include <QPushButton> #include <QSystemTrayIcon> class WebFrame_1; extern uint timestmp_1; extern uint timestmp_2; extern uint timestmp_3; extern uint timestmp_4; extern uint timestmp_5; extern uint timestmp_6; extern uint timestmp_7; extern uint timestmp_8; extern uint timestmp_9; namespace Ui { class NewsDialog; } QT_BEGIN_NAMESPACE class QModelIndex; QT_END_NAMESPACE /** Dialog for requesting payment of bitcoins */ class NewsDialog : public QDialog { Q_OBJECT public: explicit NewsDialog(QWidget* parent = 0); ~NewsDialog(); public slots: protected: private: Ui::NewsDialog* ui; WebFrame_1* iframe_1; WebFrame_1* iframe_2; WebFrame_1* iframe_3; WebFrame_1* iframe_4; WebFrame_1* iframe_5; WebFrame_1* iframe_6; WebFrame_1* iframe_7; WebFrame_1* iframe_8; WebFrame_1* iframe_9; void loadPoster(); signals: public slots : void linkClickedSlot_1(); void linkClickedSlot_2(); void linkClickedSlot_3(); void linkClickedSlot_4(); void linkClickedSlot_5(); void linkClickedSlot_6(); void linkClickedSlot_7(); void linkClickedSlot_8(); void linkClickedSlot_9(); void timerTickSlot_1(); void timerTickSlot_2(); void timerTickSlot_3(); void timerTickSlot_4(); void timerTickSlot_5(); void timerTickSlot_6(); void timerTickSlot_7(); void timerTickSlot_8(); void timerTickSlot_9(); private slots: }; class WebFrame_1 : public QLabel { Q_OBJECT signals : void onClick(); public: /** So that it responds to left-button clicks */ void mousePressEvent(QMouseEvent* event); using QLabel::QLabel; }; //class headerLabel : public QLabel //{ // Q_OBJECT // // signals : // void onClick(); // //public: // /** So that it responds to left-button clicks */ // void mousePressEvent(QMouseEvent* event); // // using QLabel::QLabel; //}; #endif // BITCOIN_QT_NEWSDIALOG_H
HighStakesCoin/HighStakes
src/chainparamsseeds.h
#ifndef BITCOIN_CHAINPARAMSSEEDS_H #define BITCOIN_CHAINPARAMSSEEDS_H /** * List of fixed seed nodes for the bitcoin network * AUTOGENERATED by contrib/seeds/generate-seeds.py * * Each line contains a 16-byte IPv6 address and a port. * IPv4 as well as onion addresses are wrapped inside a IPv6 address accordingly. */ static SeedSpec6 pnSeed6_main[] = { {{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x68,0xf8,0xd7,0x03}, 12319}, {{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x8a,0xc5,0x88,0x73}, 12319}, {{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x8a,0xc5,0x9c,0xf4}, 12319}, {{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x9f,0x59,0x7b,0x18}, 12319}, {{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xb2,0x3e,0x4c,0x3f}, 12319}, {{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xb2,0x3e,0xe9,0x33}, 12319}, {{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xb2,0x3e,0xf4,0x45}, 12319}, {{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xb2,0x80,0x4b,0x27}, 12319}, {{0x26,0x04,0xa8,0x80,0x00,0x02,0x00,0xd0,0x00,0x00,0x00,0x00,0x22,0x79,0x70,0x01}, 12319}, {{0x26,0x04,0xa8,0x80,0x00,0x02,0x00,0xd0,0x00,0x00,0x00,0x00,0x22,0x79,0x90,0x01}, 12319}, {{0x26,0x04,0xa8,0x80,0x0c,0xad,0x00,0xd0,0x00,0x00,0x00,0x00,0x05,0x26,0x00,0x01}, 12319}, {{0x26,0x04,0xa8,0x80,0x0c,0xad,0x00,0xd0,0x00,0x00,0x00,0x00,0x0c,0x51,0x00,0x01}, 12319}, {{0x26,0x04,0xa8,0x80,0x0c,0xad,0x00,0xd0,0x00,0x00,0x00,0x00,0x0c,0x65,0x60,0x01}, 12319}, {{0x2a,0x03,0xb0,0xc0,0x00,0x01,0x00,0xd0,0x00,0x00,0x00,0x00,0x02,0xfd,0x40,0x01}, 12319}, {{0x2a,0x03,0xb0,0xc0,0x00,0x02,0x00,0xd0,0x00,0x00,0x00,0x00,0x02,0x91,0x00,0x01}, 12319}, {{0x2a,0x03,0xb0,0xc0,0x00,0x02,0x00,0xd0,0x00,0x00,0x00,0x00,0x00,0x6d,0x60,0x01}, 12319} }; static SeedSpec6 pnSeed6_test[] = { }; #endif // BITCOIN_CHAINPARAMSSEEDS_H
zabbix-tools/libzbxpgsql
src/libzbxpgsql.c
/* ** libzbxpgsql - A PostgreSQL monitoring module for Zabbix ** Copyright (C) 2015 - <NAME> <<EMAIL>> ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation; either version 2 of the License, or ** (at your option) any later version. ** ** This program is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** ** You should have received a copy of the GNU General Public License ** along with this program; if not, write to the Free Software ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. **/ /* * See: * LibPQ: http://www.postgresql.org/docs/9.4/static/libpq.html * Statistics: http://www.postgresql.org/docs/9.4/static/monitoring-stats.html */ #include "libzbxpgsql.h" #include <dlfcn.h> size_t (*zbx_snprintf)(char *str, size_t count, const char *fmt, ...) = NULL; int (*real_zabbix_check_log_level)(int level) = NULL; int *real_zbx_log_level = NULL; void (*real_zabbix_log)(int level, const char *fmt, ...) = NULL; // Define custom keys static ZBX_METRIC keys[] = /* KEY FLAG FUNCTION TEST PARAMETERS */ { {"pg.modver", 0, MODVER, NULL}, {"pg.connect", CF_HAVEPARAMS, PG_CONNECT, NULL}, {"pg.version", CF_HAVEPARAMS, PG_VERSION, NULL}, {"pg.starttime", CF_HAVEPARAMS, PG_STARTTIME, NULL}, {"pg.uptime", CF_HAVEPARAMS, PG_UPTIME, NULL}, {"pg.prepared_xacts_count", CF_HAVEPARAMS, PG_PREPARED_XACTS_COUNT, NULL}, {"pg.prepared_xacts_ratio", CF_HAVEPARAMS, PG_PREPARED_XACTS_RATIO, NULL}, {"pg.prepared_xacts_age", CF_HAVEPARAMS, PG_PREPARED_XACTS_AGE, NULL}, {"pg.setting", CF_HAVEPARAMS, PG_SETTING, ",,data_directory"}, {"pg.setting.discovery", CF_HAVEPARAMS, PG_SETTING_DISCOVERY, NULL}, // User queries {"pg.query.string", CF_HAVEPARAMS, PG_QUERY, ",,SELECT 'Lorem ipsum dolor';"}, {"pg.query.integer", CF_HAVEPARAMS, PG_QUERY, ",,SELECT pg_backend_pid();"}, {"pg.query.double", CF_HAVEPARAMS, PG_QUERY, ",,SELECT CAST(1234 AS double precision);"}, {"pg.query.discovery", CF_HAVEPARAMS, PG_QUERY, ",,SELECT * FROM pg_database;"}, // Client connection statistics {"pg.backends.count", CF_HAVEPARAMS, PG_BACKENDS_COUNT, NULL}, {"pg.backends.free", CF_HAVEPARAMS, PG_BACKENDS_FREE, NULL}, {"pg.backends.ratio", CF_HAVEPARAMS, PG_BACKENDS_RATIO, NULL}, {"pg.queries.longest", CF_HAVEPARAMS, PG_QUERIES_LONGEST, NULL}, // Server statistics (as per pg_stat_bgwriter) {"pg.checkpoints_timed", CF_HAVEPARAMS, PG_STAT_BGWRITER, NULL}, {"pg.checkpoints_req", CF_HAVEPARAMS, PG_STAT_BGWRITER, NULL}, {"pg.checkpoint_write_time", CF_HAVEPARAMS, PG_STAT_BGWRITER, NULL}, {"pg.checkpoint_sync_time", CF_HAVEPARAMS, PG_STAT_BGWRITER, NULL}, {"pg.checkpoint_avg_interval", CF_HAVEPARAMS, PG_BG_AVG_INTERVAL, NULL}, {"pg.checkpoint_time_ratio", CF_HAVEPARAMS, PG_BG_TIME_RATIO, NULL}, {"pg.buffers_checkpoint", CF_HAVEPARAMS, PG_STAT_BGWRITER, NULL}, {"pg.buffers_clean", CF_HAVEPARAMS, PG_STAT_BGWRITER, NULL}, {"pg.maxwritten_clean", CF_HAVEPARAMS, PG_STAT_BGWRITER, NULL}, {"pg.buffers_backend", CF_HAVEPARAMS, PG_STAT_BGWRITER, NULL}, {"pg.buffers_backend_fsync", CF_HAVEPARAMS, PG_STAT_BGWRITER, NULL}, {"pg.buffers_alloc", CF_HAVEPARAMS, PG_STAT_BGWRITER, NULL}, {"pg.stats_reset", CF_HAVEPARAMS, PG_STAT_BGWRITER, NULL}, {"pg.stats_reset_interval", CF_HAVEPARAMS, PG_BG_STATS_RESET_INTERVAL, NULL}, // Asset discovery {"pg.db.discovery", CF_HAVEPARAMS, PG_DB_DISCOVERY, NULL}, {"pg.namespace.discovery", CF_HAVEPARAMS, PG_NAMESPACE_DISCOVERY, NULL}, {"pg.schema.discovery", CF_HAVEPARAMS, PG_NAMESPACE_DISCOVERY, NULL}, // Alias for pg.namespace.discovery {"pg.tablespace.discovery", CF_HAVEPARAMS, PG_TABLESPACE_DISCOVERY, NULL}, {"pg.table.discovery", CF_HAVEPARAMS, PG_TABLE_DISCOVERY, NULL}, {"pg.table.children.discovery", CF_HAVEPARAMS, PG_TABLE_CHILDREN_DISCOVERY, ",,pg_proc"}, {"pg.index.discovery", CF_HAVEPARAMS, PG_INDEX_DISCOVERY, NULL}, // Asset class sizes {"pg.db.size", CF_HAVEPARAMS, PG_DB_SIZE, NULL}, {"pg.table.size", CF_HAVEPARAMS, PG_TABLE_SIZE, NULL}, {"pg.table.rows", CF_HAVEPARAMS, PG_TABLE_ROWS, NULL}, {"pg.table.children", CF_HAVEPARAMS, PG_TABLE_CHILDREN, ",,pg_database"}, {"pg.table.children.size", CF_HAVEPARAMS, PG_TABLE_CHILDREN_SIZE, ",,pg_database"}, {"pg.table.children.rows", CF_HAVEPARAMS, PG_TABLE_CHILDREN_ROWS, ",,pg_database"}, {"pg.index.size", CF_HAVEPARAMS, PG_INDEX_SIZE, NULL}, {"pg.index.rows", CF_HAVEPARAMS, PG_INDEX_ROWS, NULL}, {"pg.tablespace.size", CF_HAVEPARAMS, PG_TABLESPACE_SIZE, ",,pg_default"}, {"pg.namespace.size", CF_HAVEPARAMS, PG_NAMESPACE_SIZE, ",,pg_catalog"}, {"pg.schema.size", CF_HAVEPARAMS, PG_NAMESPACE_SIZE, ",,pg_catalog"}, // Alias for pg.namespace.size // Database statistics (as per pg_stat_database) {"pg.db.numbackends", CF_HAVEPARAMS, PG_STAT_DATABASE, NULL}, {"pg.db.xact_commit", CF_HAVEPARAMS, PG_STAT_DATABASE, NULL}, {"pg.db.xact_rollback", CF_HAVEPARAMS, PG_STAT_DATABASE, NULL}, {"pg.db.blks_read", CF_HAVEPARAMS, PG_STAT_DATABASE, NULL}, {"pg.db.blks_hit", CF_HAVEPARAMS, PG_STAT_DATABASE, NULL}, {"pg.db.blks_ratio", CF_HAVEPARAMS, PG_DB_BLKS_RATIO, NULL}, {"pg.db.tup_returned", CF_HAVEPARAMS, PG_STAT_DATABASE, NULL}, {"pg.db.tup_fetched", CF_HAVEPARAMS, PG_STAT_DATABASE, NULL}, {"pg.db.tup_inserted", CF_HAVEPARAMS, PG_STAT_DATABASE, NULL}, {"pg.db.tup_updated", CF_HAVEPARAMS, PG_STAT_DATABASE, NULL}, {"pg.db.tup_deleted", CF_HAVEPARAMS, PG_STAT_DATABASE, NULL}, {"pg.db.conflicts", CF_HAVEPARAMS, PG_STAT_DATABASE, NULL}, {"pg.db.temp_files", CF_HAVEPARAMS, PG_STAT_DATABASE, NULL}, {"pg.db.temp_bytes", CF_HAVEPARAMS, PG_STAT_DATABASE, NULL}, {"pg.db.deadlocks", CF_HAVEPARAMS, PG_STAT_DATABASE, NULL}, {"pg.db.blk_read_time", CF_HAVEPARAMS, PG_STAT_DATABASE, NULL}, {"pg.db.blk_write_time", CF_HAVEPARAMS, PG_STAT_DATABASE, NULL}, {"pg.db.stats_reset", CF_HAVEPARAMS, PG_STAT_DATABASE, ",,postgres,,,"}, {"pg.db.xid_age", CF_HAVEPARAMS, PG_DB_XID_AGE, NULL}, // Table statistics (as per pg_stat_all_tables) {"pg.table.seq_scan", CF_HAVEPARAMS, PG_STAT_ALL_TABLES, NULL}, {"pg.table.seq_tup_read", CF_HAVEPARAMS, PG_STAT_ALL_TABLES, NULL}, {"pg.table.idx_scan", CF_HAVEPARAMS, PG_STAT_ALL_TABLES, NULL}, {"pg.table.idx_scan_ratio", CF_HAVEPARAMS, PG_TABLE_IDX_SCAN_RATIO, NULL}, {"pg.table.idx_tup_fetch", CF_HAVEPARAMS, PG_STAT_ALL_TABLES, NULL}, {"pg.table.n_tup_ins", CF_HAVEPARAMS, PG_STAT_ALL_TABLES, NULL}, {"pg.table.n_tup_upd", CF_HAVEPARAMS, PG_STAT_ALL_TABLES, NULL}, {"pg.table.n_tup_del", CF_HAVEPARAMS, PG_STAT_ALL_TABLES, NULL}, {"pg.table.n_tup_hot_upd", CF_HAVEPARAMS, PG_STAT_ALL_TABLES, NULL}, {"pg.table.n_live_tup", CF_HAVEPARAMS, PG_STAT_ALL_TABLES, NULL}, {"pg.table.n_dead_tup", CF_HAVEPARAMS, PG_STAT_ALL_TABLES, NULL}, {"pg.table.n_mod_since_analyze",CF_HAVEPARAMS, PG_STAT_ALL_TABLES, NULL}, {"pg.table.last_vacuum", CF_HAVEPARAMS, PG_STAT_ALL_TABLES, ",,pg_database"}, {"pg.table.last_autovacuum", CF_HAVEPARAMS, PG_STAT_ALL_TABLES, ",,pg_database"}, {"pg.table.last_analyze", CF_HAVEPARAMS, PG_STAT_ALL_TABLES, ",,pg_database"}, {"pg.table.last_autoanalyze", CF_HAVEPARAMS, PG_STAT_ALL_TABLES, ",,pg_database"}, {"pg.table.vacuum_count", CF_HAVEPARAMS, PG_STAT_ALL_TABLES, NULL}, {"pg.table.autovacuum_count", CF_HAVEPARAMS, PG_STAT_ALL_TABLES, NULL}, {"pg.table.analyze_count", CF_HAVEPARAMS, PG_STAT_ALL_TABLES, NULL}, {"pg.table.autoanalyze_count", CF_HAVEPARAMS, PG_STAT_ALL_TABLES, NULL}, // Table IO Statistics (as per pg_statio_all_tables) {"pg.table.heap_blks_read", CF_HAVEPARAMS, PG_STATIO_ALL_TABLES, NULL}, {"pg.table.heap_blks_hit", CF_HAVEPARAMS, PG_STATIO_ALL_TABLES, NULL}, {"pg.table.heap_blks_ratio", CF_HAVEPARAMS, PG_TABLE_HEAP_BLKS_RATIO, NULL}, {"pg.table.idx_blks_read", CF_HAVEPARAMS, PG_STATIO_ALL_TABLES, NULL}, {"pg.table.idx_blks_hit", CF_HAVEPARAMS, PG_STATIO_ALL_TABLES, NULL}, {"pg.table.idx_blks_ratio", CF_HAVEPARAMS, PG_TABLE_IDX_BLKS_RATIO, NULL}, {"pg.table.toast_blks_read", CF_HAVEPARAMS, PG_STATIO_ALL_TABLES, NULL}, {"pg.table.toast_blks_hit", CF_HAVEPARAMS, PG_STATIO_ALL_TABLES, NULL}, {"pg.table.toast_blks_ratio", CF_HAVEPARAMS, PG_TABLE_TOAST_BLKS_RATIO, NULL}, {"pg.table.tidx_blks_read", CF_HAVEPARAMS, PG_STATIO_ALL_TABLES, NULL}, {"pg.table.tidx_blks_hit", CF_HAVEPARAMS, PG_STATIO_ALL_TABLES, NULL}, {"pg.table.tidx_blks_ratio", CF_HAVEPARAMS, PG_TABLE_TIDX_BLKS_RATIO, NULL}, // Index statistics (as per pg_stat_all_indexes) {"pg.index.idx_scan", CF_HAVEPARAMS, PG_STAT_ALL_INDEXES, NULL}, {"pg.index.idx_tup_read", CF_HAVEPARAMS, PG_STAT_ALL_INDEXES, NULL}, {"pg.index.idx_tup_fetch", CF_HAVEPARAMS, PG_STAT_ALL_INDEXES, NULL}, // Index IO statistics (as per pg_statio_all_indexes) {"pg.index.idx_blks_read", CF_HAVEPARAMS, PG_STATIO_ALL_INDEXES, NULL}, {"pg.index.idx_blks_hit", CF_HAVEPARAMS, PG_STATIO_ALL_INDEXES, NULL}, {"pg.index.idx_blks_ratio", CF_HAVEPARAMS, PG_INDEX_IDX_BLKS_RATIO, NULL}, // Null terminator {NULL} }; // Required Zabbix module functions int zbx_module_api_version() { return ZBX_MODULE_API_VERSION_ONE; } void zbx_module_item_timeout(int timeout) { return; } ZBX_METRIC *zbx_module_item_list() { return keys; } /* * zbx_module_uninit */ int zbx_module_uninit() { return uninit_config(); } /* * zbx_module_init */ int zbx_module_init() { void *handle; printf("starting agent module %s", PACKAGE_STRING); if (NULL == (handle = dlopen(NULL, RTLD_LAZY | RTLD_NOLOAD))) { fprintf(stderr, "failed to dlopen() Zabbix binary: %s", dlerror()); return ZBX_MODULE_FAIL; } real_zabbix_check_log_level = dlsym(handle, "zabbix_check_log_level"); /* was available before ZBX-10889 */ real_zbx_log_level = dlsym(handle, "zbx_log_level"); /* is available since ZBX-10889 */ if (NULL == real_zabbix_check_log_level && NULL == real_zbx_log_level) { fprintf(stderr, "failed to find both zabbix_check_log_level() and zbx_log_level," " be aware that module may spam with log messages"); /* not a critical error, we can continue */ } if (NULL == (real_zabbix_log = dlsym(handle, "__zbx_zabbix_log"))) { fprintf(stderr, "failed to find __zbx_zabbix_log(): %s", dlerror()); return ZBX_MODULE_FAIL; } if (NULL == (zbx_snprintf = dlsym(handle, "zbx_snprintf")) && NULL == (zbx_snprintf = dlsym(handle, "__zbx_zbx_snprintf"))) { zabbix_log(LOG_LEVEL_ERR, "failed to find zbx_snprintf() or __zbx_zbx_snprintf(): %s", dlerror()); dlclose(handle); return ZBX_MODULE_FAIL; } dlclose(handle); return init_config(); } /* * Custom key: pg.modver * * Returns the version string of the libzbxpgsql module. * * Parameters: * * Returns: s */ int MODVER(AGENT_REQUEST *request, AGENT_RESULT *result) { int ret = SYSINFO_RET_FAIL; // Request result code const char *__function_name = "MODVER"; // Function name for log file char buffer[MAX_STRING_LEN]; zabbix_log(LOG_LEVEL_DEBUG, "In %s", __function_name); zbx_snprintf( buffer, sizeof(buffer), "%s, compiled for Zabbix %s", PACKAGE_STRING, ZABBIX_VERSION ); // Set result SET_STR_RESULT(result, strdup(buffer)); ret = SYSINFO_RET_OK; zabbix_log(LOG_LEVEL_DEBUG, "End of %s", __function_name); return ret; } /* * Function: pg_exec * * Wrapper for PQexecParams. Only supports text parameters as binary parameters * are not possible in Zabbix item keys. * * Returns: PGresult */ PGresult *pg_exec(PGconn *conn, const char *command, PGparams params) { PGresult *res = NULL; int i = 0, nparams = 0; // count parameters nparams = param_len(params); // log the query zabbix_log(LOG_LEVEL_DEBUG, "Executing query with %i parameters: %s", nparams, command); for (i = 0; i < nparams; i++) zabbix_log(LOG_LEVEL_DEBUG, " $%i: %s", i, params[i]); // execute query with escaped parameters res = PQexecParams(conn, command, nparams, NULL, (const char * const*) params, NULL, NULL, 0); // free up the params array which would have been alloc'ed for this request param_free(params); return res; } /* * Function: pg_scalar * * Executes a PostgreSQL Query using connection details from a Zabbix agent * request structure and fills the given buffer with the value of the first * column of the first row returned. The connection is closed before returning. * * Parameter [request]: Zabbix agent request structure. * Passed to pg_connect_request to fetch a valid PostgreSQL server * connection * * Parameter [result]: Zabbix agent result structure used to set any errors * that may occur. * * Parameter [query]: PostgreSQL query to execute. Query should return a * single scalar string value. * * Parameter [params]: Query parameters * * Parameter [buffer]: Buffer to the filled with the query response * * Parameter [bufferlen]: Size in bytes of the buffer to fill * * Returns: SYSINFO_RET_OK or SYSINFO_RET_FAIL on error */ int pg_scalar(AGENT_REQUEST *request, AGENT_RESULT *result, const char *query, PGparams params, char *buffer, size_t bufferlen) { const char *__function_name = "pg_scalar"; PGconn *conn = NULL; PGresult *res = NULL; int ret = SYSINFO_RET_FAIL; zabbix_log(LOG_LEVEL_DEBUG, "In %s", __function_name); // connect to PostgreSQL conn = pg_connect_request(request, result); if (NULL == conn) goto out; // execute scalar query res = pg_exec(conn, query, params); if(PQresultStatus(res) != PGRES_TUPLES_OK) { set_err_result(result, "PostgreSQL error for query \"%s\": %s", query, PQresultErrorMessage(res)); goto out; } if(0 == PQntuples(res)) { set_err_result(result, "No results returned for query \"%s\"", query); goto out; } // copy result to buffer zbx_strlcpy(buffer, PQgetvalue(res, 0, 0), bufferlen); ret = SYSINFO_RET_OK; out: PQclear(res); PQfinish(conn); zabbix_log(LOG_LEVEL_DEBUG, "End of %s", __function_name); return ret; } /* * Function: pg_get_result * * Executes a PostgreSQL Query using connection details from a Zabbix agent * request structure and updates the agent result structure with the value of * the first column of the first row returned. * * type may be * * Query parameters may be provided as a NULL terminated sequence of *char * values in the ... parameter. * * Parameter [request]: Zabbix agent request structure. * Passed to pg_connect_request to fetch a valid PostgreSQL server * connection * * Parameter [result]: Zabbix agent result structure * * Parameter [type]: Result type to set. May be one of AR_STRING, AR_UINT64 * or AR_DOUBLE. * * Parameter [query]: PostgreSQL query to execute. Query should return a * single scalar string value. Parameters defined using PostgreSQL's * '$n' notation will be replaced with the corresponding variadic * argument provided in ... * * Returns: SYSINFO_RET_OK or SYSINFO_RET_FAIL on error */ int pg_get_result(AGENT_REQUEST *request, AGENT_RESULT *result, int type, const char *query, PGparams params) { int ret = SYSINFO_RET_FAIL; // Request result code const char *__function_name = "pg_get_result"; // Function name for log file char value[MAX_STRING_LEN]; zabbix_log(LOG_LEVEL_DEBUG, "In %s(%s)", __function_name, request->key); // execute scalar query if(SYSINFO_RET_FAIL == pg_scalar(request, result, query, params, &value[0], sizeof(value))) goto out; // Set result switch(type) { case AR_STRING: // string result (zabbix will clean the strdup'd buffer) SET_STR_RESULT(result, strdup(value)); break; case AR_UINT64: // integer result // Convert E Notation if(1 < strlen(value) && '.' == value[1]) { double dbl = strtod(value, NULL); SET_UI64_RESULT(result, (unsigned long long) dbl); } else { SET_UI64_RESULT(result, strtoull(value, NULL, 10)); } break; case AR_DOUBLE: // double result SET_DBL_RESULT(result, strtold(value, NULL)); break; default: // unknown result type set_err_result(result, "Unsupported result type: 0x%0X in %s", type, __function_name); goto out; } ret = SYSINFO_RET_OK; out: zabbix_log(LOG_LEVEL_DEBUG, "End of %s(%s)", __function_name, request->key); return ret; } /* * Function: pg_get_percentage * * Executes a PostgreSQL query on the given table using connection details from * a Zabbix agent request structure and calculates the quotient the given * columns. * * Parameter [request]: Zabbix agent request structure. * Passed to pg_connect_request to fetch a valid PostgreSQL server * connection * * Parameter [result]: Zabbix agent result structure in which the quotient will * will be set or an error message on failure * * Parameter [table]: The PostgreSQL table to query * * Parameter [col1]: The column containing the dividend to be divided * * Parameter [col2]: The column containing the divisor * * Parameter [colFilter]: The column to filter by if desired * * Parameter [filter]: Value to filter by (`where [colFilter] = [filter]`) * * Parameter [type]: Result type to set. May be one of AR_STRING, AR_UINT64 * or AR_DOUBLE. * * Returns: SYSINFO_RET_OK or SYSINFO_RET_FAIL on error */ int pg_get_percentage(AGENT_REQUEST *request, AGENT_RESULT *result, char *table, char *col1, char *col2, char *colFilter, char *filter) { int ret = SYSINFO_RET_FAIL; // Request result code const char *__function_name = "pg_get_percentage"; // Function name for log file int qlen = 0; char query[MAX_STRING_LEN], *c = NULL; zabbix_log(LOG_LEVEL_DEBUG, "In %s(%s)", __function_name, request->key); zbx_snprintf( query, sizeof(query), "SELECT CASE WHEN (%s) = 0 THEN 1 ELSE (%s)::float / (%s) END FROM %s", col2, col1, col2, table ); if (!strisnull(colFilter)) { qlen = strlen(query); c = &query[qlen]; zbx_snprintf(c, (sizeof(query) / sizeof(char)) - qlen, " WHERE %s = $1", colFilter); } ret = pg_get_dbl(request, result, query, param_new(filter)); zabbix_log(LOG_LEVEL_DEBUG, "End of %s(%s)", __function_name, request->key); return ret; } /* * Function: pg_version * * Returns a comparable version number (e.g 80200 or 90400) for the connected * PostgreSQL server version. * * Returns: int */ long int pg_version(AGENT_REQUEST *request, AGENT_RESULT *result) { const char *__function_name = "pg_version"; // Function name for log file char buffer[MAX_STRING_LEN]; long int version = 0; zabbix_log(LOG_LEVEL_DEBUG, "In %s", __function_name); // execute query if (SYSINFO_RET_OK == pg_scalar( request, result, "SELECT setting FROM pg_settings WHERE name='server_version_num'", NULL, &buffer[0], sizeof(buffer) )) { // convert to integer version = atol(buffer); zabbix_log(LOG_LEVEL_DEBUG, "PostgreSQL server version: %lu", version); } zabbix_log(LOG_LEVEL_DEBUG, "End of %s", __function_name); return version; } /* * Log an error to the agent log file and set the result message sent back to * the server. */ int set_err_result(AGENT_RESULT *result, const char *format, ...) { va_list args; char msg[MAX_STRING_LEN]; // parse message string va_start (args, format); zbx_vsnprintf(msg, sizeof(msg), format, args); // log message zabbix_log(LOG_LEVEL_ERR, "PostgreSQL: %s", msg); if (NULL != result) SET_MSG_RESULT(result, strdup(msg)); return SYSINFO_RET_FAIL; } /* * Function: is_oid * * Returns: 1 if the specified string is a valid PostgreSQL OID * * See also: http://www.postgresql.org/docs/9.4/static/datatype-oid.html */ int is_oid(char *str) { char *p = NULL; int res = 0; for(p = str; '\0' != *p; p++) { if (0 == isdigit(*p)) return 0; res = 1; } return res; } /* * Function: is_valid_ip * * Returns: 1 if the specified string is a valid IPv4 or IPv6 address */ int is_valid_ip(char *str) { struct in6_addr in; int res = 0; // test for valid IPv4 address if(1 == inet_pton(AF_INET, str, &(in))) res = 1; // test for valid IPv6 address if(1 == inet_pton(AF_INET6, str, &(in))) res = 1; return res; } /* * Function: strcat2 * * An attempt to improve the performance and usability of strcat. * Buffer sizing is the responsibility of the caller. * * Returns: pointer to the last character of the updated destination string */ char *strcat2(char *dest, const char *src) { if (NULL == dest || NULL == src) return dest; // seek to the end of the dest string while (*dest) dest++; // copy one char at a time from source while ((*dest++ = *src++)); // return the last character return --dest; }
Sparklester/QLauncher
mainwindow.h
<gh_stars>0 #ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include "config.h" namespace Ui { class MainWindow; } class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); private slots: void on_keySequenceEdit_keySequenceChanged(const QKeySequence &keySequence); void on_config_clicked(); void on_accept_clicked(); void on_top_clicked(); void on_left_clicked(); void on_right_clicked(); void on_bottom_clicked(); private: Ui::MainWindow *ui; Config *config_dialog; }; #endif // MAINWINDOW_H
Sparklester/QLauncher
config.h
#ifndef CONFIG_H #define CONFIG_H #include <QDialog> namespace Ui { class Config; } class Config : public QDialog { Q_OBJECT public: explicit Config(QWidget *parent = 0); ~Config(); private slots: void on_top_clicked(); void on_left_clicked(); void on_bottom_clicked(); void on_right_clicked(); private: Ui::Config *ui; }; #endif // CONFIG_H
gravicle/library
Library/Library.h
<reponame>gravicle/library // // Library.h // Library // // Created by Amit on 5/26/17. // Copyright © 2017 <NAME>. All rights reserved. // #import <UIKit/UIKit.h> //! Project version number for Library. FOUNDATION_EXPORT double LibraryVersionNumber; //! Project version string for Library. FOUNDATION_EXPORT const unsigned char LibraryVersionString[]; // In this header, you should import all the public headers of your framework using statements like #import <Library/PublicHeader.h>
om-mani-padme-hum/LTPNG
LTPNG.h
<reponame>om-mani-padme-hum/LTPNG<gh_stars>0 /** * Lowe Technologies PNG Encoder (LTPNG) * * A PNG encoder built to the ISO/IEC 15948:2003 Portable Network Graphics Standard Rev 10 Nov 03 * Supports only 8-bit and 16-bit truecolour PNG images with or without alpha and no filtering. * * @author <NAME> * @version See CPP for revision and revision history */ using namespace std; class LTPNG { public: /** Public properties */ unsigned int file_size; unsigned int max_val; unsigned char bit_depth; unsigned char colour_type; unsigned char filter_type; unsigned int width; unsigned int height; ofstream *image; /** Constructor declaration */ LTPNG(unsigned char, unsigned char, unsigned char); /** Main function declaration */ void create_image(ofstream &, unsigned int, unsigned int, unsigned short *, unsigned short *, unsigned short *, unsigned short *); /** Channel map/ramp function declarations */ static double ramp_n(unsigned int, unsigned int, unsigned int, unsigned int); static double ramp_s(unsigned int, unsigned int, unsigned int, unsigned int); static double ramp_e(unsigned int, unsigned int, unsigned int, unsigned int); static double ramp_w(unsigned int, unsigned int, unsigned int, unsigned int); static double ramp_nw(unsigned int, unsigned int, unsigned int, unsigned int); static double ramp_ne(unsigned int, unsigned int, unsigned int, unsigned int); static double ramp_sw(unsigned int, unsigned int, unsigned int, unsigned int); static double ramp_se(unsigned int, unsigned int, unsigned int, unsigned int); static double pattern_full(unsigned int, unsigned int, unsigned int, unsigned int); static double pattern_half(unsigned int, unsigned int, unsigned int, unsigned int); static double pattern_none(unsigned int, unsigned int, unsigned int, unsigned int); protected: /** Image data pointers */ unsigned char *uncompressed_data; unsigned char *filtered_data; unsigned char *compressed_data; /** Buffer and index counter for holding CRC data */ unsigned char *crc_buf; unsigned int crc_index; unsigned int crc_allocated; /** Table of CRCs of all 8-bit messages. */ unsigned int crc_table[256]; unsigned char crc_table_exists; /** PNG formatting helpers */ void write_png_signature(); void write_header_chunk(unsigned char, unsigned char, unsigned char); void write_data_chunk(unsigned char *, unsigned int); void write_end_chunk(); /** Filter function declarations */ unsigned char filter_byte(unsigned int, unsigned int, unsigned char); unsigned char paeth_predictor(short, short, short); /** CRC function declarations */ void make_crc_table(); void crc_init(); void allocate_crc_size(unsigned char, unsigned char); unsigned int get_crc(); unsigned int update_crc(unsigned int, unsigned char *, unsigned int); /** File I/O helper declarations */ void fwrite_8(unsigned char); void fwrite_16(unsigned short); void fwrite_32(unsigned int); unsigned char get_byte_from_two_bytes(unsigned int, unsigned char); unsigned char get_byte_from_four_bytes(unsigned int, unsigned char); /** zLib function declarations */ void def(unsigned char *, unsigned int, unsigned char *, unsigned int, unsigned int &, int); void inf(unsigned char *, unsigned int, unsigned char *, unsigned int, unsigned int &); };
jjohnson42/python-eficompressor
EfiCompressor.c
<gh_stars>1-10 /** @file Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR> This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at http://opensource.org/licenses/bsd-license.php THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/ #include <Python.h> #include <Compress.h> #include <Decompress.h> /* UefiDecompress(data_buffer, size, original_size) */ STATIC PyObject* UefiDecompress( PyObject *Self, PyObject *Args ) { PyObject *SrcData; UINT32 SrcDataSize; UINT32 DstDataSize; UINTN Status; UINT8 *DstBuf; Py_buffer PyB; Status = PyArg_ParseTuple( Args, "Oi", &SrcData, &SrcDataSize ); if (Status == 0) { return NULL; } if (PyObject_CheckBuffer(SrcData) == 0) { PyErr_SetString(PyExc_Exception, "First argument is not a buffer\n"); return NULL; } if (PyObject_GetBuffer(SrcData, &PyB, PyBUF_SIMPLE) < 0) { PyErr_SetString(PyExc_Exception, "Failed getting buffer for first argument\n"); return NULL; } Status = Extract(PyB.buf, PyB.len, (VOID **)&DstBuf, &DstDataSize, 1); PyBuffer_Release(&PyB); if (Status != EFI_SUCCESS) { PyErr_SetString(PyExc_Exception, "Failed to decompress\n"); goto ERROR; } #if PY_MAJOR_VERSION >= 3 return PyMemoryView_FromMemory((char*)DstBuf, (Py_ssize_t)DstDataSize, PyBUF_READ); #else return PyBuffer_FromMemory(DstBuf, (Py_ssize_t)DstDataSize); #endif ERROR: if (DstBuf != NULL) { free(DstBuf); } return NULL; } STATIC PyObject* FrameworkDecompress( PyObject *Self, PyObject *Args ) { PyObject *SrcData; UINT32 SrcDataSize; UINT32 DstDataSize; UINTN Status; UINT8 *DstBuf; PyObject* ret; Py_buffer PyB; Status = PyArg_ParseTuple( Args, "Oi", &SrcData, &SrcDataSize ); if (Status == 0) { return NULL; } if (PyObject_CheckBuffer(SrcData) == 0) { PyErr_SetString(PyExc_Exception, "First argument is not a buffer\n"); return NULL; } // Because some Python objects which support "buffer" protocol have more than one // memory segment, we have to copy them into a contiguous memory. PyObject_GetBuffer(SrcData, &PyB, PyBUF_SIMPLE); Status = Extract(PyB.buf, PyB.len, (VOID **)&DstBuf, &DstDataSize, 2); PyBuffer_Release(&PyB); if (Status != EFI_SUCCESS) { PyErr_SetString(PyExc_Exception, "Failed to decompress\n"); goto ERROR; } ret = PyBytes_FromStringAndSize((const char*)DstBuf, (Py_ssize_t)DstDataSize); free(DstBuf); return ret; ERROR: if (DstBuf != NULL) { free(DstBuf); } return NULL; } STATIC PyObject* UefiCompress( PyObject *Self, PyObject *Args ) { PyObject *SrcData; UINT32 SrcDataSize; UINT32 DstDataSize; UINTN Status; UINT8 *DstBuf; Py_buffer PyB; Status = PyArg_ParseTuple( Args, "Oi", &SrcData, &SrcDataSize ); if (Status == 0) { return NULL; } if (PyObject_CheckBuffer(SrcData) == 0) { PyErr_SetString(PyExc_Exception, "First argument is not a buffer\n"); return NULL; } if (PyObject_GetBuffer(SrcData, &PyB, PyBUF_SIMPLE) < 0) { PyErr_SetString(PyExc_Exception, "Failed getting buffer for first argument\n"); return NULL; } DstDataSize = SrcDataSize; DstBuf = PyMem_Malloc(DstDataSize); Status = EfiCompress(PyB.buf, PyB.len, (VOID *)DstBuf, &DstDataSize); PyBuffer_Release(&PyB); if (Status != EFI_SUCCESS) { PyErr_SetString(PyExc_Exception, "Failed to compress\n"); goto ERROR; } #if PY_MAJOR_VERSION >= 3 return PyMemoryView_FromMemory((char*)DstBuf, (Py_ssize_t)DstDataSize, PyBUF_READ); #else return PyBuffer_FromMemory(DstBuf, (Py_ssize_t)DstDataSize); #endif ERROR: if (DstBuf != NULL) { free(DstBuf); } return NULL; } STATIC PyObject* FrameworkCompress( PyObject *Self, PyObject *Args ) { PyObject *SrcData; UINT32 SrcDataSize; UINT32 DstDataSize; UINTN Status; UINT8 *DstBuf; PyObject *ret; Py_buffer PyB; Status = PyArg_ParseTuple( Args, "Oi", &SrcData, &SrcDataSize ); if (Status == 0) { return NULL; } if (PyObject_CheckBuffer(SrcData) == 0) { PyErr_SetString(PyExc_Exception, "First argument is not a buffer\n"); return NULL; } if (PyObject_GetBuffer(SrcData, &PyB, PyBUF_SIMPLE) < 0) { PyErr_SetString(PyExc_Exception, "Failed getting buffer for first argument\n"); return NULL; } DstDataSize = SrcDataSize; DstBuf = PyMem_Malloc(DstDataSize); if (DstBuf == NULL) { PyErr_SetString(PyExc_Exception, "Not enough memory\n"); goto ERROR; } Status = TianoCompress(PyB.buf, PyB.len, (VOID *)DstBuf, &DstDataSize); PyBuffer_Release(&PyB); if (Status != EFI_SUCCESS) { PyErr_SetString(PyExc_Exception, "Failed to compress\n"); goto ERROR; } ret = PyBytes_FromStringAndSize((const char*)DstBuf, (Py_ssize_t)DstDataSize); PyMem_Free(DstBuf); return ret; ERROR: if (DstBuf != NULL) { free(DstBuf); } return NULL; } const char DecompressDocs[] = "Decompress(): Decompress data using UEFI standard algorithm\n"; const char CompressDocs[] = "Compress(): Compress data using UEFI standard algorithm\n"; STATIC PyMethodDef EfiCompressor_Funcs[] = { {"UefiDecompress", (PyCFunction)UefiDecompress, METH_VARARGS, DecompressDocs}, {"UefiCompress", (PyCFunction)UefiCompress, METH_VARARGS, CompressDocs}, {"FrameworkDecompress", (PyCFunction)FrameworkDecompress, METH_VARARGS, DecompressDocs}, {"FrameworkCompress", (PyCFunction)FrameworkCompress, METH_VARARGS, CompressDocs}, {NULL, NULL, 0, NULL} }; PyMODINIT_FUNC #if PY_MAJOR_VERSION >= 3 PyInit_EfiCompressor(VOID) { static struct PyModuleDef moduledef = { PyModuleDef_HEAD_INIT, "EfiCompressor", NULL, 0, EfiCompressor_Funcs, NULL, NULL, NULL, NULL }; return PyModule_Create(&moduledef); #else initEfiCompressor(VOID) { Py_InitModule3("EfiCompressor", EfiCompressor_Funcs, "EFI Compression Algorithm Extension Module"); #endif }
Nikhil-Xavier-DS/Self_Driving_Car----Sensor-Fusion-Localization---Control
Self_Driving_Car----Model-Predictive Controller/src/MPC.h
<filename>Self_Driving_Car----Model-Predictive Controller/src/MPC.h<gh_stars>1-10 #ifndef MPC_H #define MPC_H #include <vector> #include "Eigen-3.3/Eigen/Core" #define DT 0.1 #define LF 2.67 #define W_DDELTA 0 #define W_DA 0.0 using namespace std; class MPC { public: MPC(); virtual ~MPC(); vector<double> Solve(Eigen::VectorXd state, Eigen::VectorXd coeffs); vector<double> mpc_x; vector<double> mpc_y; }; #endif