第一次写的一个舵机小狗,程序还处于特别幼稚的阶段,希望大佬们不喜勿喷。我做的小狗腿部是由两个舵机进行控制,是一个四边形的结构,由两个自由度。
我先建立一个坐标系,然后定义好小狗的脚尖的轨迹,通过脚尖x,y轴的位置算出舵机的转角,最后通过转角反应pwm占空比。
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)
|