質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.46%
C++

C++はC言語をもとにしてつくられた最もよく使われるマルチパラダイムプログラミング言語の1つです。オブジェクト指向、ジェネリック、命令型など広く対応しており、多目的に使用されています。

Raspberry Pi

Raspberry Piは、ラズベリーパイ財団が開発した、名刺サイズのLinuxコンピュータです。 学校で基本的なコンピュータ科学の教育を促進することを意図しています。

Q&A

解決済

1回答

879閲覧

Navio2の傾きを知りたい

wage_wage

総合スコア3

C++

C++はC言語をもとにしてつくられた最もよく使われるマルチパラダイムプログラミング言語の1つです。オブジェクト指向、ジェネリック、命令型など広く対応しており、多目的に使用されています。

Raspberry Pi

Raspberry Piは、ラズベリーパイ財団が開発した、名刺サイズのLinuxコンピュータです。 学校で基本的なコンピュータ科学の教育を促進することを意図しています。

0グッド

0クリップ

投稿2021/06/03 07:14

Navio2がどのくらい傾いているか調べたいのですが、下記のプログラム(Navio2/C++/Examples/AccelGyroMag.cpp)を実行しても結果で数値が表示されません。どのように改善すれば該当プログラムの116行目

printf("Gyr: %+8.3f %+8.3f %+8.3f ", gx, gy, gz);

を表示できますか?

実行プログラム

C++

1/* 2Provided to you by Emlid Ltd (c) 2015. 3twitter.com/emlidtech || www.emlid.com || info@emlid.com 4Example: Read accelerometer, gyroscope and magnetometer values from 5inertial measurement unit: MPU9250 or LSM9DS1 over SPI on Raspberry Pi + Navio. 6Navio's onboard sensors are connected to the SPI bus on Raspberry Pi 7and can be read through /dev/spidev0.1 (MPU9250), /dev/spidev0.3 (acc/gyro LSM9DS1) 8and /dev/spidev0.2 (mag LSM9DS1). 9To run this example navigate to the directory containing it and run following commands: 10make 11./AccelGyroMag -i [sensor name] 12Sensors names: mpu is MPU9250, lsm is LSM9DS1. 13For print help: 14./AccelGyroMag -h 15*/ 16 17#include "Common/MPU9250.h" 18#include "Navio2/LSM9DS1.h" 19#include "Common/Util.h" 20#include <unistd.h> 21#include <string> 22#include <memory> 23 24std::unique_ptr <InertialSensor> get_inertial_sensor( std::string sensor_name) 25{ 26 if (sensor_name == "mpu") { 27 printf("Selected: MPU9250\n"); 28 auto ptr = std::unique_ptr <InertialSensor>{ new MPU9250() }; 29 return ptr; 30 } 31 else if (sensor_name == "lsm") { 32 printf("Selected: LSM9DS1\n"); 33 auto ptr = std::unique_ptr <InertialSensor>{ new LSM9DS1() }; 34 return ptr; 35 } 36 else { 37 return NULL; 38 } 39} 40 41void print_help() 42{ 43 printf("Possible parameters:\nSensor selection: -i [sensor name]\n"); 44 printf("Sensors names: mpu is MPU9250, lsm is LSM9DS1\nFor help: -h\n"); 45} 46 47std::string get_sensor_name(int argc, char *argv[]) 48{ 49 if (get_navio_version() == NAVIO2) { 50 51 if (argc < 2) { 52 printf("Enter parameter\n"); 53 print_help(); 54 return std::string(); 55 } 56 57 // prevent the error message 58 opterr = 0; 59 int parameter; 60 61 while ((parameter = getopt(argc, argv, "i:h")) != -1) { 62 switch (parameter) { 63 case 'i': return optarg; 64 case 'h': print_help(); return "-1"; 65 case '?': printf("Wrong parameter.\n"); 66 print_help(); 67 return std::string(); 68 } 69 } 70 71 } else { //sensor on NAVIO+ 72 73 return "mpu"; 74 } 75 76} 77//============================================================================= 78int main(int argc, char *argv[]) 79{ 80 81 if (check_apm()) { 82 return 1; 83 } 84 85 auto sensor_name = get_sensor_name(argc, argv); 86 if (sensor_name.empty()) 87 return EXIT_FAILURE; 88 89 auto sensor = get_inertial_sensor(sensor_name); 90 91 if (!sensor) { 92 printf("Wrong sensor name. Select: mpu or lsm\n"); 93 return EXIT_FAILURE; 94 } 95 96 if (!sensor->probe()) { 97 printf("Sensor not enabled\n"); 98 return EXIT_FAILURE; 99 } 100 sensor->initialize(); 101 102 float ax, ay, az; 103 float gx, gy, gz; 104 float mx, my, mz; 105//------------------------------------------------------------------------- 106 107 while(1) { 108 sensor->update(); 109 sensor->read_accelerometer(&ax, &ay, &az); 110 sensor->read_gyroscope(&gx, &gy, &gz); 111 sensor->read_magnetometer(&mx, &my, &mz); 112 printf("Acc: %+7.3f %+7.3f %+7.3f ", ax, ay, az); 113 printf("Gyr: %+8.3f %+8.3f %+8.3f ", gx, gy, gz); 114 printf("Mag: %+7.3f %+7.3f %+7.3f\n", mx, my, mz); 115 116 usleep(500000); 117 } 118}

実行結果

C++

1Enter parameter 2Possible parameters: 3Sensor selection: -i [sensor name] 4Sensors names: mpu is MPU9250, lsm is LSM9DS1 5For help: -h

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

WoodenHamlet

2021/06/03 07:28

argc, argv のコマンドライン引数の値はどうなっていますか?
guest

回答1

0

ベストアンサー

実行方法には

./AccelGyroMag -i [sensor name]

と書いてありますが、[sensor name] のところに何を入れて実行しましたか?

投稿2021/06/04 00:26

yuki23

総合スコア1448

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

wage_wage

2021/06/04 01:08

lsmをいれてます -iを入れるのをわすれてました。ありがとうございます!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.46%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問