第一次寫的一個舵機小狗,程序還處于特別幼稚的階段,希望大佬們不喜勿噴。我做的小狗腿部是由兩個舵機進行控制,是一個四邊形的結構,由兩個自由度。
我先建立一個坐標系,然后定義好小狗的腳尖的軌跡,通過腳尖x,y軸的位置算出舵機的轉角,最后通過轉角反應pwm占空比。
四足小狗.jpg (3.64 MB, 下載次數: 58)
下載附件
2019-7-11 09:40 上傳
STM32單片機源程序如下:
#include "led.h"
#include "delay.h"
#include "sys.h"
#include "pwm.h"
#include "usart.h"
#include "math.h"
u16 set1_0;//pwm占空比(u16)
u16 set2_0;
u16 set1_1;
u16 set2_1;
u16 set1_2;
u16 set2_2;
u16 set1_3;
u16 set2_3;
float output1_0;//pwm占空比(float)
float output2_0;
float output1_1;
float output2_1;
float output1_2;
float output2_2;
float output1_3;
float output2_3;
float pai=3.141592653;
float x0=-2;//x軸位置
float y0=8;
float x1=2;
float y1=8;
float x2=2;
float y2=8;
float x3=-2;
float y3=8;
float h1_0;//腳尖到原點的距離
float h2_0;
float h1_1;
float h2_1;
float h1_2;
float h2_2;
float h1_3;
float h2_3;
float a0;//腳尖和原點的連線與y軸無偏角時舵機角度
float a1;
float a2;
float a3;
float a1_0;//舵機的角度
float a2_0;
float a1_1;
float a2_1;
float a1_2;
float a2_2;
float a1_3;
float a2_3;
float b0;//腳尖和原點的連線與y軸的偏角
float b1;
float b2;
float b3;
int i;
int dir0=1;
int dir1=2;
int dir2=2;
int dir3=1;
void foot_0(float x,float y)//腿1的舵機角度計算
{
全部資料51hei下載地址:
四足機器人直行.7z
(194.79 KB, 下載次數: 21)
2019-7-12 04:31 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|