ハロー ブログ

日々のつぶやき @c2c2c2c221

ESP32連動

ESP32devで左足を動かす。

既存スケッチそのままで動かす。

 

f:id:c2c2c2c2:20230314085001j:image

Arduinoによるロビ2の下半身の制御

 

歩行4S.RM4.txtのC言語変換

 

プログラムの機能を理解する プログラムの仕様を理解することが必要です。これにより、C言語に変換するために必要なデータ構造やアルゴリズムが把握できます。
プログラムの構造を分析する プログラムの構造を分析し、必要な変数や関数、ループ、条件分岐などを把握します。これにより、C言語での実装に必要な変数や関数、ループ、条件分岐などが把握できます。
C言語での実装を行う 分析したプログラムの構造に基づいて、C言語での実装を行います。必要に応じて、新しい変数や関数を定義することが必要になります。また、C言語での文法や標準ライブラリを適切に使用することが必要です。
テストを実施する 実装したC言語のプログラムをテストし、元のプログラムと同じ結果が得られることを確認します。必要に応じて、修正や改良を加えます。

 

とりあえず、人手で変換します。

できたらケーブルおよび UARTを2ch化する。

変換後

 

 

byte torque_on_data[] = {0xFA, 0xAF, 0x01, 0x00, 0x24, 0x01, 0x01, 0x01, 0x24}; //トルクONコマンド
byte position_data[] = {0xFA, 0xAF, 0x01, 0x00, 0x1E, 0x04, 0x01, 0x00, 0x00, 0x64, 0x00, 0x7E}; // ポジションコマンド

void memcpy(byte* buf, byte* data, int n) // データ転送

{

int sum = 0;

for(int i = 0; i < n; i++){

buf[i] = data[i];

}

}

void checksum(byte* data, int n) // チェックサムの設定

{

int sum = 0;

for(int i = 2; i < n - 1; i++){

sum = sum ^ data[i];

}

data[ n-1 ] = sum;

}

void servo_move(int mem_a[], int speed){

byte data[12];

int move_speed = (speed * 100) / 60;

memcpy(data, position_data, 12); //回転データ転送

for (int j = 0; j < 20; j++)

{

data[2] = j +2 ;

memcpy(&data[7], &mem_a[j], 2); //変更位置設定

memcpy(&data[9], &move_speed, 2); //移動時間設定

checksum(data, 12); //チェックサム計算

Serial2.write(data,12); //変更位置まで回転

}

delay(move_speed * 13); //移動時間待つ

}

void setup() {

byte data[12];

Serial.begin(115200);

Serial2.begin(115200); //115200bpsでポートを開く

delay(500); //0.5秒待つ

Serial.write("Start!");

for (int i = 0; i < 20; i++)

{

torque_on_data[2] = i+2; //サーボID

checksum(torque_on_data, 9); //チェックサム計算

Serial2.write(torque_on_data,9); //サーボトルクON

}

delay(1000); //1秒待つ

//

int mem_w [] = {

0x0000,0x0000,0x0000,0x0064,0x0000,0x0064,0x0000,0x0064,0x0000,0x0064,0x0000,0x0064,0x0000,0x0064,0x0000,0x0064,0x0000,0x0064,0x0000,0x0064,0x0000,0x0064,0x0000,0x0064,

0x0000,0x0064,0x0000,0x0064,0x0000,0x0064,0x0000,0x0064,0x0000,0x0064,0x0000,0x0064,0x0000,0x0064,0x0000,0x0064,0x0000,0x0064,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,

0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,

0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,

0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,

0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000

};

servo_move(mem_w,0x0014);

//

//

// 

int mem_w2[] = {

0x0000,0x0064,0xff73,0x0064,0xff78,0x0064,0x0003,0x0064,0xffa1,0x0064,0x00be,0x0064,0xff8d,0x0064,0x00e6,0x0064,0xff4c,0x0064,0x0014,0x0064,0x009b,0x0064,0xfffc,0x0064,

0xfffd,0x0064,0x0014,0x0064,0x003c,0x0064,0x0092,0x0064,0x0007,0x0064,0xfff5,0x0064,0x004e,0x0064,0x0000,0x0064,0xffc3,0x0064,0x0000,0x0064,0x0000,0x0064,0x0000,0x0064,

0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x00aa,0x004b,0x0000,0x00aa,0x004b,0x0000,0x0000,0x0000,

0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,

0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,

0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000

};

//0x0031

//

servo_move(mem_w2,0x0031);

// 

int mem_w3[] = {

0x0000,0x0064,0xff83,0x0064,0xff6a,0x0064,0x0000,0x0064,0xff9c,0x0064,0x00be,0x0064,0xff8d,0x0064,0x033e,0x0064,0xfb55,0x0064,0xfe7a,0x0064,0x0050,0x0064,0xffb2,0x0064,

0xffbe,0x0064,0x0019,0x0064,0x0037,0x0064,0x0119,0x0064,0xffce,0x0064,0xfff9,0x0064,0x0095,0x0064,0x0001,0x0064,0xffbc,0x0064,0x0000,0x0064,0x0000,0x0064,0x0000,0x0064,

0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x00aa,0x004b,0x0000,0x00aa,0x004b,0x0000,0x0000,0x0000,

0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,

0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,

0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000

};

//0x0012

//

servo_move(mem_w3,0x0012);

// 

int mem_w4[] = {

0x0000,0x0064,0xff8d,0x0064,0xffb5,0x0064,0x0000,0x0064,0xffb5,0x0064,0x008c,0x0064,0xffc9,0x0064,0x02b2,0x0064,0x0000,0x0064,0x01ea,0x0064,0x0050,0x0064,0xff40,0x0064,

0xfec9,0x0064,0xffb5,0x0064,0x0064,0x0064,0x01f8,0x0064,0xffc3,0x0064,0xfff6,0x0064,0x014e,0x0064,0x0001,0x0064,0x00b7,0x0064,0x0000,0x0064,0x0000,0x0064,0x0000,0x0064,

0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x00aa,0x004b,0x0000,0x00aa,0x004b,0x0000,0x0000,0x0000,

0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,

0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,

0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000

};

//0x000f

//

servo_move(mem_w4,0x00f);

// 

int mem_w5[] = {

0x0000,0x0064,0xffc4,0x0064,0xffe2,0x0064,0x0000,0x0064,0x0005,0x0064,0x0028,0x0064,0x0019,0x0064,0x014f,0x0064,0x0000,0x0064,0x0136,0x0064,0xffec,0x0064,0xff61,0x0064,

0xfec9,0x0064,0xff97,0x0064,0x002d,0x0064,0x0244,0x0064,0xffc3,0x0064,0xfff5,0x0064,0x01bb,0x0064,0x0002,0x0064,0x00b6,0x0064,0x0000,0x0064,0x0000,0x0064,0x0000,0x0064,

0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x00aa,0x004b,0x0000,0x00aa,0x004b,0x0000,0x0000,0x0000,

0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,

0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,

0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000

};

//0x000a

//

//

servo_move(mem_w5,0x00a);

// 

int mem_w6[] = {

0x0000,0x0064,0x0065,0x0064,0x006e,0x0064,0x0000,0x0064,0x007d,0x0064,0xff4c,0x0064,0x0091,0x0064,0x0082,0x0064,0x0000,0x0064,0x0064,0x0064,0xff7e,0x0064,0xffa0,0x0064,

0xffeb,0x0064,0xff6f,0x0064,0x0015,0x0064,0x014b,0x0064,0x001d,0x0064,0xfffb,0x0064,0x0079,0x0064,0xffb7,0x0064,0x0047,0x0064,0x0000,0x0064,0x0000,0x0064,0x0000,0x0064,

0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x00aa,0x004b,0x0000,0x00aa,0x004b,0x0000,0x0000,0x0000,

0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,

0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,

0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000

};

//0x0032

//

//

servo_move(mem_w6,0x032);

// 

int mem_w7[] = {

0x0000,0x0064,0x0073,0x0064,0xfcb8,0x0064,0x04ce,0x0064,0x0186,0x0064,0xffb2,0x0064,0x009b,0x0064,0x00aa,0x0064,0xffff,0x0064,0x0069,0x0064,0xff5b,0x0064,0xffe9,0x0064,

0xffea,0x0064,0xffb0,0x0064,0x002d,0x0064,0x0079,0x0064,0xffb3,0x0064,0xfff4,0x0064,0xffd6,0x0064,0x005b,0x0064,0xff7e,0x0064,0x0000,0x0064,0x0000,0x0064,0x0000,0x0064,

0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x00aa,0x004b,0x0000,0x00aa,0x004b,0x0000,0x0000,0x0000,

0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,

0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,

0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000

};

//0x0012

//

//

servo_move(mem_w7,0x012);

// 

int mem_w8[] = {

0x0000,0x0064,0x0037,0x0064,0xfcf4,0x0064,0x000a,0x0064,0xfe17,0x0064,0xffaf,0x0064,0x0073,0x0064,0x007d,0x0064,0x0002,0x0064,0x005f,0x0064,0xff74,0x0064,0x0055,0x0064,

0x0106,0x0064,0xffab,0x0064,0x0032,0x0064,0xfef8,0x0064,0x0023,0x0064,0xffe7,0x0064,0xfda4,0x0064,0xffd9,0x0064,0xff29,0x0064,0x0000,0x0064,0x0000,0x0064,0x0000,0x0064,

0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x00aa,0x004b,0x0000,0x00aa,0x004b,0x0001,0x0000,0x0000,

0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,

0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,

0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000

};

//0x000f

//

//

servo_move(mem_w8,0x00f);

// 

int mem_w9[] = {

0x0000,0x0064,0xfffb,0x0064,0xfea2,0x0064,0x0000,0x0064,0xfeca,0x0064,0xfff1,0x0064,0x003e,0x0064,0x003c,0x0064,0x0000,0x0064,0x000a,0x0064,0xffc4,0x0064,0x0070,0x0064,

0x0106,0x0064,0x0041,0x0064,0x0014,0x0064,0xfefe,0x0064,0x0027,0x0064,0xffe0,0x0064,0xfda7,0x0064,0xffd7,0x0064,0xff29,0x0064,0x0000,0x0064,0x0000,0x0064,0x0000,0x0064,

0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x00aa,0x004b,0x0000,0x00aa,0x004b,0x0000,0x0000,0x0000,

0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,

0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,

0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000

};

//0x000b

//

//

servo_move(mem_w9,0x00b);

// 

int mem_w10[] = {

0x0000,0x0064,0xff6f,0x0064,0xff74,0x0064,0x0000,0x0064,0xff92,0x0064,0x0096,0x0064,0xff9c,0x0064,0xffa6,0x0064,0x0000,0x0064,0xff97,0x0064,0x00b4,0x0064,0x0080,0x0064,

0x0053,0x0064,0xffba,0x0064,0x001e,0x0064,0x0121,0x0064,0x0023,0x0064,0xffe4,0x0064,0x0033,0x0064,0x0072,0x0064,0xff29,0x0064,0x0000,0x0064,0x0000,0x0064,0x0000,0x0064,

0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x00aa,0x004b,0x0000,0x00aa,0x004b,0x0000,0x0000,0x0000,

0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,

0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,

0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000

};

//0x0032

//

//

servo_move(mem_w10,0x00b);

}

void loop() {

}