Friday, September 28, 2012

Ogre3D : Making a robot arm

Game Engines is a course all about programming through and through. The teachings of this course is to understand the core building blocks to create engines in an efficient manner. Besides learning how to build engines, we at the same time learn how to use and modify existing ones to suit our needs.

Like any course this one requires homework which is done in a different manner than most schools. You are awarded "XP" points for completing a homework question, which builds up until you reach enough that you are allowed to do the midterm, and later the final exam. I started off with a simple one so as to get points more easily and start myself off easy.

All of the code we do is used by using an engine compiled and built by our professor and TA, along with the open source "Ogre3D" engine. I'll briefly go through the steps I took into understanding and creating the question I decided to do, which was to build a robot arm.


About Nodes and Skeletons

The robot arm itself is supposed to be like a skeleton, able to move its arm and fingers around such as a human would do. With Ogre3D the task isn't so bad thanks to some of its features. First of all to create a skeleton you need to have whats known as a hierarchy of nodes. Nodes essentially act as our joints and are the basic building blocks you need to make a skeleton. You want to strategically place these nodes where the joints of your body would normally be.


A Skeleton, each dot represents a node, a joint like a bone in the body




We begin with one node, the root node from which all other nodes will come from. This is usually the center of the body, from which stems towards arms, legs, hands, feet, etc. For the robot arm, we have our root node as the base of the arm instead of worrying about an entire skeleton. From there, we have nodes that act as "child nodes" to our root node, located at the arm. Now that we have a "parent node" to our child node, it means that whatever happens to our parent node, it will do the same to any child node it has. So if we rotate it around, we rotate everything under it too.

The highest node is at 1, and works its way down to the others. It branches off at 2, where 3A, 3B, 3C, 3D are all children of 2. If 2 moves, they all do.

Since we have an arm, we have a child node acting as a joint for the hand itself, then joints for the fingers. These become children of children of children, which means, if we move our parent node in the arm, it will move all of those joints. This is how we are going to make our robot arm, by making these joints and having child nodes.

Ogre3D Process

Ogre3D has a lot of useful tools, one of them is a hierarchy system involving the use of nodes. It's already built in for us which makes this process for us not as difficult as it could have been (making a hierarchy system is not easy). We have our scene manager, which controls everything we have in the environment at the time. Inside the scene manager we are allowed  to create nodes under it. A root node is automatically created, starting in the middle of the area.

With this in mind we can begin creating nodes which are children of the root node. We begin by making cubes, so as to give us a visual of where we are placing our nodes exactly. We also make cubes that will act as the "mesh" (Skin) of our arm as well. Each of these will require a node as well to designate their current location. How this works is that our cube is attached to a node, and instead of the cube having to be called to find its position, we can use the node its assigned to to find it.

Here is a pre-visualisation of the hand with the node hand we used from earlier.

Our goal is to place nodes where joints should normally be. We make our arm first, creating the cube for it with its own node. We then position a node directly on the tip the arm so that it can act as the joint position we need. This new joint node is then turned into a child of our ARM portion. From there, we create a new cube to represent our hand portion, making it a child of our joint between the arm and hand. From there it's simply a matter or repeating this process and finding the right position to put our joint nodes. It may sound a bit complicated but it's actually pretty simple, it's just a matter of placement.


The Final arm in the program

From there all that was required was to ensure that the joints were in the right place and then code it so that our keyboard would be able to rotate every joint as required.

Mistakes

This was still a learning process as I had gone through some mistakes while doing this program. For one, I did not have those joint nodes located between each CUBE. Instead I simply had all the cubes required, so the arm, hand, finger, etc. What I did was rotate just these cubes in place, which made the hand look like it was moving unnaturally. The reason was because the center of rotation is located in the middle of the cube, not at the edge. It would cause a strange looking hand that really had no joints.


Red represents where the nodes where that I was rotating. Green is where I put new nodes in order for the arm to rotate properly.

This is where I was told I needed to put more nodes. What this really translated to was that I needed to put actual joints in between the cubes representing the different parts of the arm. These are important because now instead the center of rotation would be located right between the arm and hand part, exactly where it needed to be to make a natural looking rotation. Once I realized this it was just a matter of knowing where to put the joint.

Conclusion

So here we have it, my working robot arm, now with actual joints instead of fake ones and rotating properly. I won't put all my code up since it's just a good learning experience for others to do and it's honestly not that hard once you know what to do.

1 comment:

  1. Thanks for sharing, nice post! Post really provice useful information!

    Giaonhan247 chuyên dịch vụ vận chuyển hàng đi mỹ cũng như dịch vụ ship hàng mỹ từ dịch vụ nhận mua hộ hàng mỹ từ website nổi tiếng Mỹ là mua hàng amazon về VN uy tín, giá rẻ.

    ReplyDelete