先週末にアップデートしましたが、以下が挙動不審。
① 毎日早朝のリフレッシュブートが実行されない
② timemachineの定時バックアップが実行されない
スケジューラーはTimeMachineEditor使ってます。
アップデートしてないAirはちゃんと動いているようだから、おそらくOSアップデートでの問題だろうと思う。まあ過去の経験からそのうち修正されるでしょう。
admin
la vie libre
先週末にアップデートしましたが、以下が挙動不審。
① 毎日早朝のリフレッシュブートが実行されない
② timemachineの定時バックアップが実行されない
スケジューラーはTimeMachineEditor使ってます。
アップデートしてないAirはちゃんと動いているようだから、おそらくOSアップデートでの問題だろうと思う。まあ過去の経験からそのうち修正されるでしょう。
admin
M5stackの加速度計(重力加速度)とサーボモーターを組み合わせることで、M5stackの姿勢をフォローするものを作ります。
M5stackの加速度測定数値は結構揺らぎがあるので、平滑化と有効ビットの削減をおこなっています。
<servo.cpp>
#include <imu.h>
int servopinx=2; // dio port definition
int servopiny=5;
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 comp = 1.1; // compensate not to show minus value
float adj = 30; // adjuct the angle with map() function not to exceed the range upper limit 180 & eliminate the noise
float p_accX = 0.5;
float p_accY = 0.5;
float p_accZ = 0.5;
boolean first = true; // check if it is first cycle or not.
float smooth = 0.6; // smoothing the angle value. it causes a delay time to the angle change.
//
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 setup()
{
setup_imu();
pinMode(servopinx,OUTPUT);
pinMode(servopiny,OUTPUT);
}
void loop()
{
loop_imu();
if (first == true){ // smoothing
p_accX = accX;
p_accY = accY;
p_accZ = accZ;
first = false;
}
else{
p_accX = p_accX*smooth + accX*(1-smooth);
p_accY = p_accY*smooth + accY*(1-smooth);
p_accZ = p_accZ*smooth + accZ*(1-smooth);
}
ax = map((int)((p_accX+comp)*adj), 0, 66, 0, 180); // translate acc values to the range 0 to 180
ay = map((int)((p_accY+comp)*adj), 0, 66, 0, 180);
az = map((int)((p_accZ+comp)*adj), 0, 66, 0, 180);
M5.Lcd.setCursor(0, 114);
M5.Lcd.printf("%3d %3d %3d ", ax, ay, az);
servo(ax , 0); // drive the servo motor
servo(ay , 1);
delay(5);
}
本来的なヘッダーファイルの使い方とは多少異なりますが、M5stack IMUの加速度数値を読み取るルーチンです。
<imu.h>
/*
*******************************************************************************
* Copyright (c) 2021 by M5Stack
* Equipped with M5Core sample source code
* Visit the website for more information:https://docs.m5stack.com/en/core/gray
*
* describe:MPU6886 example.
* date:2021/7/21
*******************************************************************************
*/
#define M5STACK_MPU6886
#include <m5stack.h>
float accX = 0.0F; // Define variables for storing inertial sensor data
float accY = 0.0F;
float accZ = 0.0F;
void setup_imu(){
M5.begin(); //Init M5Core.
M5.Power.begin(); //Init Power module.
M5.IMU.Init(); //Init IMU sensor.
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.
}
void loop_imu() {
M5.IMU.getAccelData(&accX,&accY,&accZ); //Stores the triaxial accelerometer.
// Accelerometer output is related
M5.Lcd.setCursor(0, 70);
M5.Lcd.printf("accX, accY, accZ");
M5.Lcd.setCursor(0, 92);
M5.Lcd.printf("%5.2f %5.2f %5.2f G", accX, accY, accZ);
}
やりたいことにはもう一工夫がいるので、それを追加して3Dプリンタで構造を作れば完成型になります。
P.S.
傾き(θ)に対して重力加速度はリニアではなく、重力加速度からarcsin()で傾きを計算しないといけないわけですが、大まかな振る舞いを見るには直線性は無視しても構わないと思います。
P.S.2
Switch Science記載のサーボモーターのピン番号は間違っている(PowとSig入れ違い)ので、正しいピン番号を記載しておきます。
admin
IMUとservo機能を連携させようとしますが、ソースファイルを一個にするのは汚い管理なので、機能ごとに分割します。
この時にArduino IDEだとバックエンドで無意識に処理をしてくれますが、VScodeを使う時にはほぼcの作法に従う必要があります。つまり、
・他のソースを使う時には、xxx.hとしてインクルードする。
今回のケースではservo.cppからimu.hを呼び出しています。
しかし、imu.hの組み込みで”M5にIMUは見つからないよ”とコンパイルエラーになります。
で調べると、
と、
https://github.com/m5stack/M5Stack/blob/master/src/M5Stack.h
にあるようにimu.hの先頭部分は、
従ってservo.cppからは、#include <M5Stack.h>を削除してimu.hの記述を使うようにするとうまくいきました。二重インクルードはこの場合にはエラーにならず、最初の#include <m5stack.h>が有効になるからでしょう。
== top of the servo.cpp ==
//#include <m5stack.h> // M5stack needs this module
#include <imu.h>
== top of the imu.h ==
#define M5STACK_MPU6886
#include <m5stack.h>
ということなので、Arduino IDEと違ってVScodeは普通のc開発に近いよということでした。
admin
サーボモーター(LFD-01M)到着したので早速動作確認。制御は標準的なPWM方式。PWMの周波数も標準的な50Hzです。
接続はモーターへの電源、そしてM5stackからのPWM制御信号です。GNDの共有を忘れずに。当然モーターの電源は大電流なので外部電源で5Vを使います。PWMは多くの他の信号がそうであるように3.3V振幅ですが、入力はどうせC-MOSだろうから問題なし。
https://coskxlabsite.stars.ne.jp/html/for_students/M5Stack/RCServo/RCServo.html
PWMピンは上記を参照してDIOの2ピン目を使用。
動作確認用のソースはHiwonderのwebページからですが、サーボモーター用のライブラリは使ってません。存在しないのかもしれませんが、直接コードを書く方が動作の理解には助けになります。
https://drive.google.com/drive/folders/1Bgf1HGrfhB8N8XIxlRpz-U9_2oxVurDv
Arduino用なので多少の修正が必要なのと、画面表示がないと電源オンもわからないのでメッセージを出すようにしてます。ライブラリを使わないと、動作時間制御もコードで指定(この場合には20ms*20 = 400ms)しています。試しに9行目の20を10にすると90度ぐらいしか回転しません。
/*******舵机测试程序*******
* Arduino型号:Arduino UNO
**************************/
#include <m5stack.h> // M5stack needs this module
int servopin=2;
int pulsewidth;
void servo(int myangle)
{
for (int i = 0; i < 20; i ++) // i is used to make moving time, since this source does not use library.
{
pulsewidth=map(myangle,0,180,500,2500);
digitalWrite(servopin,HIGH);
delayMicroseconds(pulsewidth);
digitalWrite(servopin,LOW);
delay(20-pulsewidth/1000);
}
}
void setup()
{
pinMode(servopin,OUTPUT);
M5.begin();
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.
}
void loop()
{
M5.Lcd.setCursor(0, 70);
M5.Lcd.printf("servo_motor drive");
servo(0);
delay(500);
servo(180);
delay(500);
}
駆動波形はこんな感じ。
動作時の動画は、
となります。180度以上振れてるようなので、キャリブレーションは必要そうです。
admin
M5stack grayでサーボモーター使ったアプリ作ってみるためにオーダー。
ホビー用のサーボモーター選択肢は多いけれども、金属ギアを使ったものを前提にすると概ね価格レンジはこれ以上という感じ。二軸必要だから2個オーダー。
https://www.switch-science.com/catalog/7133/
admin
SMR方式の解説読んでも本質的なところが不明でなぜ、shingle(瓦)方式ができるのか理解できなかったけれども、seagateのページ見てようやく理解。
一番のポイントは以下の通り、書き込みヘッドが密度向上のネックだから。
”現在の技術では、データを読み取れる面積と、書き込める面積を比較すると、前者のほうが狭く、書き込み用ヘッドの精度がHDD記録密度のボトルネックとなっています。”
以下の説明図からそれが汲み取れます。書き込みヘッドに比べて読み取りヘッドがトラック間隔を狭くできるから、というのがSMR方式が成り立つわけです。書き換えはSSDと似たようなことをやる必要があるから、インテリジェンスが必要なファイルです。
この先は垂直記録方式でさらに容量拡大していくだろうというのもFlashメモリと同じかもしれない。
admin