# Thread: Kinematic simulator in python?

1. ## Re: Kinematic simulator in python?

Yes, the trig seems very fast. I had to add a whole extra IK routine in to back-calculate the foot position from the wheel-on-ground position for skating, so I can ensure that the wheel is always touching the ground whatever angle the leg is at (since the leg angle affects the vertical distance between foot and wheel). I was going to roll the resultant IK into a separate routine for skating, but it's fast enough that I can run the back-calculate and then run the full IK for the foot (which contains some redundant calcs) without any apparent slow down...

I updated the code at http://www.gotrobots.com/grinder/sim...r_simulator.py with the latest code showing wheel-contact IK working in a skating algorithm...

2. Multi-Core Processor
Join Date
Apr 2013
Location
Boston, MA
Posts
260
Images
11
Rep Power
34

## Re: Kinematic simulator in python?

This is cool, i got your project up and running yesterday. I've never used Python before so i'm trying to wrap my head around it, but i'd like to build a simple 3DOF hex model that everyone can use. I'll post it up if/when i get there.

Great tool!

3. ## Re: Kinematic simulator in python?

Originally Posted by TXBDan
This is cool, i got your project up and running yesterday. I've never used Python before so i'm trying to wrap my head around it, but i'd like to build a simple 3DOF hex model that everyone can use. I'll post it up if/when i get there.

Great tool!
Great, can't wait to see it... The technique is actually pretty straightforward and extensible. The idea is that you build all linkages initially along a line, naming each end. Each leg is placed within a frame. Then you calculate the x,y coords of each point and move the end points to these coords. As a final step each leg frame is rotated by the leg angle.

This works great for my linkage assembly; for a more general motor chain assembly each motor will need to be in its own frame but frames can be nested to achieve the desired results.

4. Multi-Core Processor
Join Date
Apr 2013
Location
Boston, MA
Posts
260
Images
11
Rep Power
34

## Re: Kinematic simulator in python?

I got it almost done, but got distracted when my hex kit arrived!

I wanted to be able to test my IK code so my method is pretty convoluted. I'm basically running the leg IK function and then running that servo angle output into a FK function so that i can get the X,Y,Z coords for all of the joints. Then i use those XYZs to update the link cyclinder and sphere positions. It mostly works but my leg frames are messed up and there's a bug in my IK or FK somewhere.

I'm really annoyed by the vpython default XYZ orientation. It's screwing up everything i have in my head. Is there a way to redefine the default orientation behavior?

I'll try to fix it, but for now i'm pretty obsessed with my hex kit

5. ## Re: Kinematic simulator in python?

Originally Posted by TXBDan
I'm really annoyed by the vpython default XYZ orientation. It's screwing up everything i have in my head. Is there a way to redefine the default orientation behavior?
You can try setting a different value of scene.up:
Code:
`scene.up=(0,0,1)`
It might be enough, it might not be... I had a hard time adjusting to the way VPython orients stuff too. This made it better for me.

And BTW you can use this to show the orientation of stuff (I have one in the main scene, then another one in each frame to have a better understanding of what's happening).

Code:
```class vect_base:
def __init__(self, pos=(0,0,0), size=10, number='', parent_frame=None):
if parent_frame == None:
self.coord = frame()
else:
self.coord = frame(frame=parent_frame)
coordinate_pos = vector(pos)
ref_x = arrow(frame=self.coord, pos = coordinate_pos, axis=(size,0,0), shaftwidth=3, color=color.red)
label(frame=self.coord, pos = coordinate_pos+(size*0.8,0,0), text='x'+str(number), box=false, opacity=0.1, height=size)
ref_y = arrow(frame=self.coord, pos = coordinate_pos, axis=(0,size,0), shaftwidth=3, color=color.green)
label(frame=self.coord, pos = coordinate_pos+(0,size*0.8,0), text='y'+str(number), box=false, opacity=0.1, height=size)
ref_z = arrow(frame=self.coord, pos = coordinate_pos, axis=(0,0,size), shaftwidth=3, color=color.blue)
label(frame=self.coord, pos = coordinate_pos+(0,0,size*0.8), text='z'+str(number), box=false, opacity=0.1, height=size)```

6. Multi-Core Processor
Join Date
Apr 2013
Location
Boston, MA
Posts
260
Images
11
Rep Power
34

## Re: Kinematic simulator in python?

There are currently 1 users browsing this thread. (0 members and 1 guests)

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•