- 积分
- 6
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2014-6-20
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
# -*- coding: cp936 -*-
from visual import *
import serial
import string
import math
import thread
from time import time
import time
grad2rad = 3.141592/180.0
ser_buffer=[]
# Main scene
scene=display(title="AHRS",background=(0.8,0.8,1))
scene.range=(12,12,12)
#scene.forward = (0,-1,-0.25)
scene.forward = (1,0,-0.25)#观察角度
scene.up=(0,0,1)#场景方向
# Second scene (Roll, Pitch, Yaw)
scene2 = display(title='AHRS',x=0, y=0, width=500, height=200,center=(0,0,0), background=(0.8,0.8,1))#背景
scene2.range=(1,1,1)
scene.width=500
scene.y=200
scene2.select()
#Roll, Pitch, Yaw
cil_roll = cylinder(pos=(-0.4,0,0),axis=(0.2,0,0),radius=0.01,color=color.red)
cil_roll2 = cylinder(pos=(-0.4,0,0),axis=(-0.2,0,0),radius=0.01,color=color.red)
cil_pitch = cylinder(pos=(0.1,0,0),axis=(0.2,0,0),radius=0.01,color=color.blue)
cil_pitch2 = cylinder(pos=(0.1,0,0),axis=(-0.2,0,0),radius=0.01,color=color.blue)
#cil_course = cylinder(pos=(0.6,0,0),axis=(0.2,0,0),radius=0.01,color=color.blue)
#cil_course2 = cylinder(pos=(0.6,0,0),axis=(-0.2,0,0),radius=0.01,color=color.blue)
arrow_course = arrow(pos=(0.6,0,0),color=color.cyan,axis=(-0.2,0,0), shaftwidth=0.02, fixedwidth=1)
#Roll,Pitch,Yaw labels
label(pos=(-0.4,0.3,0),text="Roll",box=0,opacity=0,color=color.red)
label(pos=(0.1,0.3,0),text="Pitch",box=0,opacity=0,color=color.blue)
label(pos=(0.55,0.3,0),text="Yaw",box=0,opacity=0,color=color.black)
label(pos=(0.6,0.22,0),text="N",box=0,opacity=0,color=color.black)
label(pos=(0.6,-0.22,0),text="S",box=0,opacity=0,color=color.black)
label(pos=(0.38,0,0),text="W",box=0,opacity=0,color=color.black)
label(pos=(0.82,0,0),text="E",box=0,opacity=0,color=color.black)
label(pos=(0.75,0.15,0),height=7,text="NE",box=0,color=color.black)
label(pos=(0.45,0.15,0),height=7,text="NW",box=0,color=color.black)
label(pos=(0.75,-0.15,0),height=7,text="SE",box=0,color=color.black)
label(pos=(0.45,-0.15,0),height=7,text="SW",box=0,color=color.black)
L1 = label(pos=(-0.4,0.22,0),text="-",box=0,opacity=0,color=color.red)
L2 = label(pos=(0.1,0.22,0),text="-",box=0,opacity=0,color=color.blue)
L3 = label(pos=(0.7,0.3,0),text="-",box=0,opacity=0,color=color.black)
# Main scene objects
scene.select()
# Reference axis (x,y,z)
arrow(color=color.green,axis=(1,0,0), shaftwidth=0.02, fixedwidth=1)
arrow(color=color.green,axis=(0,1,0), shaftwidth=0.02 , fixedwidth=1)
arrow(color=color.green,axis=(0,0,-1), shaftwidth=0.02, fixedwidth=1)
label(pos=(0,0,0.8),text="AHRS",box=0,opacity=0)
label(pos=(1,0,0),text="X",box=0,opacity=0)
label(pos=(0,1,0),text="Y",box=0,opacity=0)
label(pos=(0,0,-1),text="Z",box=0,opacity=0)
#body parts
joint_0=sphere(pos=(0,0,0),radius=0.2, color=color.red)
joint_1=sphere(pos=(0,0,1),radius=0.2, color=color.red)
joint_2=sphere(pos=(0,0,2),radius=0.2, color=color.red)
joint_3=sphere(pos=(0,0,3),radius=0.2, color=color.red)
joint_4=sphere(pos=(0,0,4),radius=0.8, color=color.red)
joint_5=sphere(pos=(0,-2,3),radius=0.2, color=color.red)
joint_6=sphere(pos=(0,-2,1),radius=0.2, color=color.red)
joint_7=sphere(pos=(0,-2,-1),radius=0.2, color=color.red)
joint_8=sphere(pos=(0,2,3),radius=0.2, color=color.red)
joint_9=sphere(pos=(0,2,1),radius=0.2, color=color.red)
joint_10=sphere(pos=(0,2,-1),radius=0.2, color=color.red)
joint_11=sphere(pos=(0,-1,0),radius=0.2, color=color.red)
joint_12=sphere(pos=(0,-1,-3),radius=0.2, color=color.red)
joint_13=sphere(pos=(0,-1,-6),radius=0.2, color=color.red)
joint_14=sphere(pos=(0,1,0),radius=0.2, color=color.red)
joint_15=sphere(pos=(0,1,-3),radius=0.2, color=color.red)
joint_16=sphere(pos=(0,1,-6),radius=0.2, color=color.red)
bone_01=cylinder(pos=(0,0,0), axis=(0,0,1), radius=0.1, length=1, color=color.cyan)
bone_12=cylinder(pos=(0,0,1), axis=(0,0,1), radius=0.1, length=1, color=color.cyan)
bone_23=cylinder(pos=(0,0,2), axis=(0,0,1), radius=0.1, length=1, color=color.cyan)
bone_34=cylinder(pos=(0,0,3), axis=(0,0,1), radius=0.1, length=1, color=color.cyan)
bone_35=cylinder(pos=(0,0,3), axis=(0,-1,0), radius=0.1, length=2, color=color.cyan)
bone_38=cylinder(pos=(0,0,3), axis=(0,1,0), radius=0.1, length=2, color=color.cyan)
bone_56=cylinder(pos=(0,-2,3), axis=(0,0,-1), radius=0.1, length=2, color=color.cyan)
bone_67=cylinder(pos=(0,-2,1), axis=(0,0,-1), radius=0.1, length=2, color=color.cyan)
bone_89=cylinder(pos=(0,2,3), axis=(0,0,-1), radius=0.1, length=2, color=color.cyan)
bone_910=cylinder(pos=(0,2,1), axis=(0,0,-1), radius=0.1, length=2, color=color.cyan)
bone_011=cylinder(pos=(0,0,0), axis=(0,-1,0), radius=0.1, length=1, color=color.cyan)
bone_014=cylinder(pos=(0,0,0), axis=(0,1,0), radius=0.1, length=1, color=color.cyan)
bone_1112=cylinder(pos=(0,-1,0), axis=(0,0,-1), radius=0.1, length=3, color=color.cyan)
bone_1213=cylinder(pos=(0,-1,-3), axis=(0,0,-1), radius=0.1, length=3, color=color.cyan)
bone_1415=cylinder(pos=(0,1,0), axis=(0,0,-1), radius=0.1, length=3, color=color.cyan)
bone_1516=cylinder(pos=(0,1,-3), axis=(0,0,-1), radius=0.1, length=3, color=color.cyan)
roll=0
pitch=0
yaw=0
while 1:
words=hex_angle()
if len(words)>2:
yaw=words[0]*grad2rad
pitch=words[1]*grad2rad
roll=words[2]*grad2rad
left_arm.axis=(cos(pitch)*cos(yaw),-cos(pitch)*sin(yaw),sin(pitch))
left_arm.up=(sin(roll)*sin(yaw)+cos(roll)*sin(pitch)*cos(yaw),sin(roll)*cos(yaw)-cos(roll)*sin(pitch)*sin(yaw),-cos(roll)*cos(pitch))
cil_roll.axis=(0.2*cos(roll),0.2*sin(roll),0)
cil_roll2.axis=(-0.2*cos(roll),-0.2*sin(roll),0)
cil_pitch.axis=(0.2*cos(pitch),0.2*sin(pitch),0)
cil_pitch2.axis=(-0.2*cos(pitch),-0.2*sin(pitch),0)
arrow_course.axis=(0.2*sin(yaw),0.2*cos(yaw),0)
L1.text = str(float(roll/grad2rad ))
L2.text = str(float(pitch/grad2rad ))
L3.text = str(float(yaw/grad2rad ))
ser.close()
|
|