版权声明:原创 https://blog.csdn.net/qq_41058594/article/details/84677734
本系列是基于pygame和tensorflow对双足机器人进行正逆运动学分析,由于迫于考试的压力,明天就要考大物和概统…今天先简单写了一个二维平面内的三自由度的模型,用pygame画的,这是第一篇,往后还会继续补充的!
import pygame
from pygame.locals import *
import sys
import numpy as np
import tensorflow as tf
#定义窗口长宽
Screen_width = 500
Screen_heigh = 500
#初始化游戏
pygame.init()
#初始化窗口
Screen = pygame.display.set_mode([Screen_width,Screen_heigh],0,32)
#初始化窗口标题
pygame.display.set_caption('机器人运动学分析')
#本例代码中的颜色全局变量
White = (255,255,255)
Blue = (0,0,255)
Black = (0,0,0)
#机器人类
class Robot_body(pygame.sprite.Sprite):
#描述机器人的固定端
def __init__(self,screen):
pygame.sprite.Sprite.__init__(self)
self.screen = screen
def Robot(self,R_color,R_position,R_radius,R_width):
self.R_color = R_color
self.R_position = R_position
self.R_radius = R_radius
self.R_width = R_width
R_Circle = pygame.draw.circle(self.screen,self.R_color,\
self.R_position,\
self.R_radius,self.R_width)
#绘制第一个自由度A1,即一个关节
def Random(self,color,start,end,A_radius,A_width):
self.color = color
self.start = start
self.end = end
self.A_radius = A_radius
self.A_width = A_width
A_Line = pygame.draw.line(self.screen,self.color,self.start,self.end,2)
A_Circle = pygame.draw.circle(self.screen,self.R_color,\
self.end,\
self.A_radius,self.A_width)
class Claw():
pass
#定义数学公式:
#圆周运动计算公式
def Draw_Circle():
pass
#类的实例化
robot = Robot_body(Screen)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit()
#Robot(Screen)
#背景颜色
Screen.fill(Blue)
#绘制机器人
robot.Robot((255,255,0),(250,100),20,20)
#绘制机器人自由度A1
A1 = robot.Random((0,0,0),(250,100),(300,200),20,20)
#绘制机器人自由度A2
A2 = robot.Random((0,0,0),(300,200),(150,250),20,20)
#更新屏幕
pygame.display.update()
等考完试,我继续把numpy模块,tensorflow,matplotlib模块加上,在进行机器人学中正逆运动学分析!这是个大工程得慢慢来…先考试再说。欢迎大家留言就错或者优化!感谢!!!
这是运行结果: