Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: Init.cpp
- Revision:
- 9:d1fc0805ec7d
- Child:
- 10:0a4bf8c82493
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Init.cpp Wed Oct 14 13:44:32 2015 +0000
@@ -0,0 +1,137 @@
+#include "mbed.h"
+#include "Global.h"
+#include "Init.h"
+#include <string>
+#include <iostream>
+
+std::string Init::strbuf;
+
+void Init::getSerial(){
+ osEvent evt = Global::queue.get();
+ if(evt.status == osEventMessage){
+ char temp = evt.value.v;
+ strbuf.push_back(temp);
+ if(temp == '\n'){
+ std::string::size_type spaceIndex = strbuf.find(" ");
+
+ if (spaceIndex != std::string::npos) {//数値データがあるコマンド(" "がある場合)
+ char *gomi;
+ std::string command = strbuf.substr(0, spaceIndex);
+ double num = strtod(strbuf.substr(spaceIndex+1, strbuf.size()-2).c_str(), &gomi);//strbuf.size()-1には'\n'が入っている
+ printf("coms=%s, num=%f\n", command.c_str(), num);
+ setting(command, num);
+
+ }else{//数値データがないコマンド(" "がない場合)
+ std::string command = strbuf.substr(0,strbuf.size()-2);
+ setting(command);
+ }
+ //ここで,ニュートラル情報をLocalFileに保存
+ Global::filewrite();
+ strbuf.clear();
+ }
+ if(strbuf.size() > 30)strbuf.clear();
+ }
+}
+
+
+void Init::setting(std::string command, double num){
+ if(command == "eleneu"){
+ Global::setneutralpitch(num);
+ }else if(command == "elemax"){
+ Global::setmaxpitch(num);
+ }else if(command == "elemin"){
+ Global::setminpitch(num);
+ }else if(command == "rudneu"){
+ Global::setneutralyaw(num);
+ }else if(command == "rudmax"){
+ Global::setmaxyaw(num);
+ }else if(command == "rudmin"){
+ Global::setminyaw(num);
+
+ }else if(command == "eleneudeg"){
+ Global::setneutralpitchdegree(num);
+ }else if(command == "elemaxdeg"){
+ Global::setmaxpitchdegree(num);
+ }else if(command == "elemindeg"){
+ Global::setminpitchdegree(num);
+ }else if(command == "rudneudeg"){
+ Global::setneutralyawdegree(num);
+ }else if(command == "rudmaxdeg"){
+ Global::setmaxyawdegree(num);
+ }else if(command == "rudmindeg"){
+ Global::setminyawdegree(num);
+
+ }else if(command == "elemaxplay"){
+ Global::setmaxpitchplayratio(num);
+ }else if(command == "eleminplay"){
+ Global::setminpitchplayratio(num);
+ }else if(command == "rudmaxplay"){
+ Global::setmaxyawplayratio(num);
+ }else if(command == "rudminplay"){
+ Global::setminyawplayratio(num);
+ }else if(command == "eletrim"){
+ Global::settrimpitchrate(num);
+
+ }else{
+ printf("Invalid Input\n");
+ }
+}
+
+void Init::setting(std::string command){
+ if(command == "eleneu"){
+ Global::setneutralpitch(Global::getpitch());
+ }else if(command == "elemax"){
+ Global::setmaxpitch(Global::getpitch());
+ }else if(command == "elemin"){
+ Global::setminpitch(Global::getpitch());
+ }else if(command == "rudneu"){
+ Global::setneutralyaw(Global::getyaw());
+ }else if(command == "rudmax"){
+ Global::setmaxyaw(Global::getyaw());
+ }else if(command == "rudmin"){
+ Global::setminyaw(Global::getyaw());
+
+ }else if(command == "eleneudeg"){
+ Global::setneutralpitchdegree(Global::getpitchdegree());
+ }else if(command == "elemaxdeg"){
+ Global::setmaxpitchdegree(Global::getpitchdegree());
+ }else if(command == "elemindeg"){
+ Global::setminpitchdegree(Global::getpitchdegree());
+ }else if(command == "rudneudeg"){
+ Global::setneutralyawdegree(Global::getyawdegree());
+ }else if(command == "rudmaxdeg"){
+ Global::setmaxyawdegree(Global::getyawdegree());
+ }else if(command == "rudmindeg"){
+ Global::setminyawdegree(Global::getyawdegree());
+
+ }else if(command == "show"){
+ showParam();
+
+ }else{
+ printf("Invalid Input\n");
+ }
+}
+
+void Init::showParam(){
+ printf("------Servo Parameter------\n");
+ printf("elevatorNeutral = %f\n", Global::getneutralpitch());
+ printf("elevatorMax = %f\n", Global::getmaxpitch());
+ printf("elevatorMin = %f\n", Global::getminpitch());
+ printf("rudderNeutral = %f\n", Global::getneutralyaw());
+ printf("rudderMax = %f\n", Global::getmaxyaw());
+ printf("rudderMin = %f\n", Global::getminyaw());
+ printf("----Controller Parameter----\n");
+ printf("elevatorNeutral = %f\n", Global::getneutralpitchdegree());
+ printf("elevatorMax = %f\n", Global::getmaxpitchdegree());
+ printf("elevatorMin = %f\n", Global::getminpitchdegree());
+ printf("rudderNeutral = %f\n", Global::getneutralyawdegree());
+ printf("rudderMax = %f\n", Global::getmaxyawdegree());
+ printf("rudderMin = %f\n", Global::getminyawdegree());
+ printf("------Controller Play------\n");
+ printf("elevatorMaxPlay = %f\n", Global::getmaxpitchplayratio());
+ printf("elevatorMinPlay = %f\n", Global::getminpitchplayratio());
+ printf("rudderMaxPlay = %f\n", Global::getmaxyawplayratio());
+ printf("rudderMinPlay = %f\n", Global::getminyawplayratio());
+ printf("-------Trim Parameter-------\n");
+ printf("elevatorTrimRate = %f\n", Global::gettrimpitchrate());
+}
\ No newline at end of file