qnapのtimemeachineバックアップで、ようやく旧ファイルの削除発生。残り領域20GB切ったあたりで、旧ファイルの削除発生して容量が40GBぐらいまで増えてます。
admin
la vie libre
M5stackとかだと、VScode使うとアドオンでPlatformIO入れればビルドツールにもなりますが、それ以外のプロジェクトだとやはり専用のビルドツールが必要だと思う。RaspberryPIも開発はパソコン上でやるのが効率的なわけだし、クロスプラフォームで統一的に使えるツールとしてはCMakeが便利そうなので、これを使ってみます。
以下の実行環境はMacBookです。
インストールしたのはGUI版とCUI版ですが、実用的にはCUI版の方が使いやすそうだから、実際に使ったのはそちら。
<ディレクトリ構造>
<header.hpp>
2行目は実装されていません。
void show_val(int val);
void show_val();
extern int val_e;
<header.cpp>
#include "header.hpp"
#include <iostream>
using namespace std;
int val_e = 98;
void show_val(int val){
cout << "val = " << val << endl;
}
<main.cpp>
#include "header.hpp"
#include <iostream>
using namespace std;
int main(){
show_val(19);
cout << "val_e " << val_e << endl;
}
作業はbuildディレクトリを作成してその中で行います。
<CMakeLists.txt>
cmake_minimum_required(VERSION 3.22)
project(build_sample CXX)
add_executable(main main.cpp)
例を参考に、こんなmake条件を設定しています。ソースファイルは2個あるのでそれを指定、ヘッダーファイルはソース中で#includeされるから設定不要。
<実行コマンド>
configure & generate
% cmake ..
-- The CXX compiler identification is AppleClang 13.0.0.13000029
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: ~~~~~省略~~~~~/build
build
ディレクトリを一階層上に移動して、
% cmake --build .
Consolidate compiler generated dependencies of target main
[ 33%] Building CXX object CMakeFiles/main.dir/header.cpp.o
[ 66%] Linking CXX executable main
[100%] Built target main
作成された、実行ファイルmainを実行(./main)するときちんと実行できました。
% ./main
val = 19
val_e = 98
P.S. 2022/11/6
ディレクトリの移動は必ずしも必須ではなくてコマンドのパラメータ次第で、buildディレクトリに移動しなくともビルドはできます。
覚書から、
https://qiita.com/tchofu/items/69dacfb93908525e5b0b
% cmake [<options>] -S <path-to-source> -B <path-to-build>
-例-
% cmake -S . -B build // @upper dir of the build dir
% cmake –build <dir> –target <tgt>… [<options>] [– <build-tool-options>]
-例-
% cmake –build build // @upper dir of the build dir, <dir> is build
admin
割とギリギリ(95%)設定していましたが、そこに到達。アラームが出るだけでバックアップされないわけではないのですが、アラームが目障りなので、しきい値を100%に変更。timemachineのアルゴリズムでは最古を削除してから追加と言われているので、どうなるのかはあと十日ぐらい経過すればわかるはず。ディスク全体ではまだ2割以上の空き領域は確保できているから、パーフォーマンス的には問題ないだろうと思う。
admin
C++のVScode環境でほぼハマるのが、コンパイラーのバージョン互換問題。ほぼ3年毎にメジャーチェンジがあるので、新しい機能はデフォルトのままでは動かない。
具体的にはラムダ式がデフォルト設定ではダメでした。error以外にもwarningがそれ以前には出ていましたが、とりあえず前には進めるから放置してました。
を参照して、① コンソール入力可能にするのはメニューから設定して、② コンパイラーバージョン設定はcode-runnerのsettings.jsonファイル中の最後部分、”code-runner.runInTerminal”: true以下に点線で挟まれた部分を追加。ただし、以下の太字($fileName)のところは参照内容から変更してます。
M5stackにつながるカメラにそれほどの選択肢はありませんが、これは面白そうです。A.I機能がビルトインされてて購入時点で使えるとのことなので、画像認識系のアプリを簡単に作成するには便利そうです。
https://www.switch-science.com/catalog/7160/
Linux系らしいので、多少モディファイするのも難易度は高くはなさそうです。
(画像はスイッチサイエンスのwebから)
admin
M5stackには色々な機能が含まれているので、順次の機能確認でまずはBLE機能を使ってみます。
ソースはPlatformIOのライブラリでBuil-in中のESP32 BLE ArduinoのRevealから見えるBLE_scanから持ってきています。ライブラリーにM5stack追加とソースに
#include <m5stack.h> はM5stack使う時には必ず追加必要です。
#include <m5stack.h> // this is needed to the original source code.
/*
Based on Neil Kolban example for IDF: https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/tests/BLE%20Tests/SampleScan.cpp
Ported to Arduino ESP32 by Evandro Copercini
*/
#include <bledevice.h>
#include <bleutils.h>
#include <blescan.h>
#include <bleadvertiseddevice.h>
int scanTime = 5; //In seconds
BLEScan* pBLEScan;
class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
void onResult(BLEAdvertisedDevice advertisedDevice) {
Serial.printf("Advertised Device: %s \n", advertisedDevice.toString().c_str());
}
};
void setup() {
Serial.begin(115200);
Serial.println("Scanning...");
BLEDevice::init("");
pBLEScan = BLEDevice::getScan(); //create new scan
pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster
pBLEScan->setInterval(100);
pBLEScan->setWindow(99); // less or equal setInterval value
M5.begin(); //Init M5Core.
M5.Power.begin(); //Init Power module.
M5.Lcd.fillScreen(BLACK); //Set the screen background color to black.
M5.Lcd.setTextColor(GREEN , BLACK); //Sets the foreground color and background color of the displayed text.
M5.Lcd.setTextSize(2); //Set the font size.
M5.Lcd.setCursor(0, 70);
M5.Lcd.printf("pow on");
}
void loop() {
// put your main code here, to run repeatedly:
BLEScanResults foundDevices = pBLEScan->start(scanTime, false);
Serial.print("Devices found: ");
Serial.println(foundDevices.getCount());
Serial.println("Scan done!");
pBLEScan->clearResults(); // delete results fromBLEScan buffer to release memory
delay(2000);
}
monitor_speed = 115200
を追加して実行させると、メッセージを吐き出しますが以下はその一部です。
Devices foundが0というのは不思議ですが。
admin
何の略語か気にしたことはなかったけれども、ラテン語の“pro bono publico”(公共善のために)ということなのだ。
bonoはbonum(中性名詞)のablative(日本語だと奪格)、同じくpublicoはpublicus(形容詞)のablativeで、前置詞pro(この場合はforが適切か)は後にくる名詞はablativeであることが前提だからそのように格変化。ラテン語が英語化しているものは多いけれどもその中のひとつ。
admin
二つ前の記事でIMUとサーボモーターを連動させたので、構造部分を作成してM5stackの直立状態を保持できるような姿勢制御を作ってみました。
前回からの変更点はサーボ制御部分のみです。
#include <imu.h>
int servopinx=2; // dio port definition for X axis
int servopiny=5; // dio port definition for Y axis
int pulsewidth; // pwm on time
int repeat=1; // number of pwm write cycle repetition
int ax; // angle for servo motors
int ay;
int az;
float p_accX; // to hold IMU read data
float p_accZ;
int p_angX; // to hold servo motor angles
int p_angZ;
boolean first = true; // check if it is first cycle or not.
//
void servo(int myangle, int motor) // servo motor pwm contorol. motor 0 : servoponx , motor 1 : servopiny
{
for (int i = 0; i < repeat; i ++) // i is used to keep a moving time, since this source does not use the library.
{
int port;
if (motor == 0){
port = servopinx;
}
else{
port = servopiny;
}
pulsewidth=map(myangle,0,180,500,2500);
digitalWrite(port,HIGH);
delayMicroseconds(pulsewidth);
digitalWrite(port,LOW);
delay(20-pulsewidth/1000);
}
}
void init_sm()
{
servo(90, 0);
servo(90, 1);
p_angX = 90;
p_angZ = 90;
delay(600);
}
void setup()
{
setup_imu();
pinMode(servopinx,OUTPUT);
pinMode(servopiny,OUTPUT);
}
void loop()
{
loop_imu();
if (first == true){
init_sm(); // initialize to 90 degree
first = false;
}
// the angle change is needed? & the change is reflected? & check the angle limit
if (accX < -0.05 && abs(p_accX - accX) > 0.02 && p_angX < 180){ p_angX ++; } else{ if (accX > 0.05 && abs(p_accX - accX) > 0.02 && p_angX > 0){
p_angX --;
}
}
if (accZ < -0.05 && abs(p_accZ - accZ) > 0.02 && p_angZ < 180){ p_angZ ++; } else{ if (accZ > 0.05 && abs(p_accZ - accZ) > 0.02 && p_angZ > 0){
p_angZ --;
}
}
p_accX = accX; // set to the previous values
p_accZ = accZ;
servo(p_angZ , 0); // drive the servo motor
servo(p_angX , 1);
delay(1);
M5.Lcd.setCursor(0, 114);
M5.Lcd.printf("%3d %3d ", p_angX, p_angZ);
}
imu.hには変更ありません。
今回はM5stackを垂直で使うので、二次元を水平に保つのはX軸とZ軸になるので、IMUからの読み出しデータはそれらを使います。
M5stackが移動するときには重力加速度以外の加速度も加算されますが、このアプリではそれを勘案する必要はないでしょう。多少動きがオーバーシュートするのはそのせいかもしれませんが。
写真は以下の通り。
サーボーモーターの電源入れない状態でM5stackを動かしているので、画面のアングル表示は変な値になっています。初期値がどうであっても、最後は収束しますが。
コードと3dプリンタ用のstlファイルは、
https://github.com/chateight/servo_
に置いてあります。M5stack追従のロジックは改善の余地があるように思います。
M5stack本体との接続は、DIO2,5とGNDの三本だけ。
admin
先週末にアップデートしましたが、以下が挙動不審。
① 毎日早朝のリフレッシュブートが実行されない
② timemachineの定時バックアップが実行されない
スケジューラーはTimeMachineEditor使ってます。
アップデートしてないAirはちゃんと動いているようだから、おそらくOSアップデートでの問題だろうと思う。まあ過去の経験からそのうち修正されるでしょう。
admin