Tuesday, November 13, 2012

A little pause: Class recommendation

Due to my work I had to move from Costa Rica into Houston, US; and with this I couldn't take my robot with me. I'll be in this new location until March 2013, so in the meantime I've been taking an online class of Machine Learning at Coursera (www.coursera.org). .

The class has been truly amazing, the teacher (Andrew Ng) has a great way to explain things without losing focus on the big picture, so you always understand why they are useful for. He also explains everything without assuming you know things, so you don't get lost in the subject. It's been a great experience and I strongly recommend you to take this class; it's like learning Kung-Fu for robots, I have a lot of ideas about how to apply it into my robot.

Also in the meantime, I'm trying to run a half-marathon...  


Monday, September 3, 2012

Inverse Kinematics video

I did a video about the Inverse Kinematics equations for the Arm. I also show there some of the errors I described in my previous post. And all of this is shown with some great dubstep beats... :) 
I'm quite an amateur on video editing, but I hope you like it.




Saturday, July 28, 2012

Correcting displacement errors

Ok here's the deal: after putting the kinematics equations into the robot, theoretically everything was fine, but the robot was smashing into the table, it was having some deep dives heading for destruction. Why the heck was that happening?

My first thought was that maybe the controller was not calculating the right angle values, but after a quick check with a serial monitor, those values were fine. Then I thought that maybe the equations were wrong, so I simulate the different arm positions (below picture) but they were ok.


Yep, I drew the trajectories using a Logo simulator... it was fast and convenient at the time ;) 


With all the directions from controller performing as desired, I realized that some of the servos just weren't capable to go into some positions.

My theory was that it was due to the arm weight and that with larger extensions of the arm, this effect will be greater. To demonstrate that I measured the angles of the joints with several arm extensions. The shoulder servo showed a notorious error increase with larger extensions, elbow showed a relative stable error with a constant value (possible due to some assembly issue). Wrist servo had almost no error.



In summary: I had a shoulder servo that couldn't hold all the arm weight when extended and a elbow with a constant error value.


How to fix this?

On first impression the solution would be to buy a more powerful servo motor for the shoulder, but since I'm saving to buy an apartment, I don't have so much money to throw away things so easily; and the idea is not just to give muscles to the robot, but to make it more efficient.

So, I tried to help the servomotor with some elastic force. First I used the spring that Lynxmotion suggests on their page (and comes with the arm assembly parts), It helped somehow, especially for short and medium extensions, but for large extensions it was not effective. Then I added also a rubber band but the assembly behaved just the same as with only the spring.

Then I thought that if the error in the joint angle behaved always similarly, I could find an equation to describe it, therefore having an error correction equation. I made an X-Y graph with the theoretical values vs the obtained angles, added a trend line and found the equation for it; so next time I would order the servo to go to angle A in order to really go to angle B. I applied this software correction procedure to shoulder and elbow joints.



Shoulder and elbow angle functions



Ultimately, I figured out that reducing the mass of the arm, servos would perform better. So I amputated the arm and removed the wrist rotate upgrade to save some weight  (I prefer more accurate results even by eliminating 1 DOF). This last fixture gave me the best combination of low error values on shoulder and elbow joints.  



Another effect I had was that servos moved so fast that they had a large underdamped movement (that decreasing oscillation when it stops moving), hitting things due to this inaccuracy. 

When you have a motor with this issue, usually you apply a PID control to its movements and tuned it up, but since in a servo motor you do not apply a control signal directly (you just specify the desired position) this option was not feasible.

The technique used in several Arduino forums was to reduce the speed of servo, this is achieved by gradually increasing the desired position sent to the servo.

By using the error correction techniques described above and decreasing the speed of the servos, I was able to obtain smoother and more accurate results, however the best way to achieve more precise and accurate results would be to have some feedback of the joint position going to the controller, having this way a closed loop control for the position. 

In conclusion: I need to get better servos (like the Dynamixel servos) or hack the ones I have to have that position feedback in real time. 


Friday, May 11, 2012

Applying inverse kinematics to the robot


When it comes to programing the logic for your robot to move there are several paths you can take. Usually you start by specifying the position of each servo on every movement of the robot, thus giving the angles of the joints to make the arm gripper go to a certain position. This is called Forward Kinematics.

The disadvantage with Forward Kinematics is that you need to know the angle of every joint on every instant of a movement, therefore as the complexity of the movement increases it also increases the amount of angles you need to know. This characteristic makes long and tedious the duty to program your robot with the intention to go to variable positions. I started programming some moves to the robot in this way, but I quickly realized about how impractical this technique was.

If your intention is to go into more complex projects, you really don't want to program every position of every joint; you just want to tell your robotic arm (or any robotic chain) "go to X,Y,Z position". Well, that technique is called Inverse Kinematics, were you just specify the desired position of the arm gripper and the robot logic calculates the angle of every joint in order to accomplish that gripper position.

Using this technique allows you to escalate your code for higher levels of complexity, but you need to obtain the inverse kinematics equations for your robot; those are the equations that will give the joint angles (and thus servo positions) when you just input the final gripper position.
To obtain those Inverse Kinematics equations you need to image your robot arm as a series of geometric figures and use geometry principles to obtain the desired angles. I will explain how I did it for my robotic arm, but it varies according to the type of robot and the number of Degrees Of Freedom (DOF) it has.

First I started by dividing the arm assembly into the below figures, then I specified which values will be constants (in this case the lengths from joint to joint and the desired final position) and which angles will be my desired output (in this case the shoulder, elbow and wrist angles).

Geometric figures on my robotic arm


Now it comes the math-fun part: you can use the Law of Cosines to obtain the angles of a triangle by knowing the length of its sides. So we can obtain the elbow angle with the following formula:

Where c is obtained using the known sides of the triangles and Pythagoras' theorem:

Also by Law of Sines we can obtain angles A and B:

With A and B we can get the angles of the wrist (m) and shoulder (h):

Finally, I substitute the sides of the arms and the desired extension (E) on those formulas and I used them on some routines on the Arduino controller that specifies where to extend the arm. Also I created other routines for raising the arm, rotating the base, opening/closing the wrist and rotating the gripper.

By using these routines, I was able to scale my code into simpler instructions, something like: raise, rotate A degrees, go to B extension, raise, rotate C degrees, go to D extension and so on.

Note that these formulas use always the gripper perpendicular to the ground and on a 2-Dimensional space, places around the ground. Next steps will be to create these inverse kinematics equations for a 3-D space. 

Wednesday, March 14, 2012

Building the Robotic Arm


Building the mechanical part of the robot is one of the funniest part of projects, it’s just like building LEGOs when you were younger, but with tougher parts and tools.

Since I bought a robotic arm kit from Lynxmotion, there are detailed instructions on their webpage. You just need to follow the instructions, but pay extra attention to the pictures because not all the details are covered on the text; I had to disassemble parts several times to fix things I found they need to be in other way. Also you need to have some basic tools like screwdrivers, clippers, wrenches and allen keys. With all this, it’s just a matter of expending time on the building process and you will have a nice piece of hardware for further developments.


One interesting feature during that process is that you start to realize what are going to be some of the limitations your hardware will have and some of the challenges you will face. For example, I soon appreciated how rigid servomotors are, I mean the word actuator is literal, they just act on the way you order them to act; there's no sense of intelligence at all compared to when a animal moves a limb. Also I realized how much weight each articulation have to handle and how easy is for some servos to get stressed if too much weight is carried during many time.

One important outcome was that I discovered I want to explore more about proprioception, which is the perception of your body parts, its weight, force, position. I think that increasing this type of intelligence on robots would result into projects that could be applied to a wider range of situations.


Wednesday, February 8, 2012

Playing with Arduino


Learning how to use an Arduino board is a straight forward process if you follow the tutorials on Arduino page (http://arduino.cc/en/Tutorial/HomePage). You just need some basic programming skills and some basic electronic knowledge; the tutorials put everything on a very simple way.

The Arduino Environment is a higher level code based on C++ for microcontrollers; there are many libraries that cover the low level setup. For example if you use the PWM (Pulse With Modulation) library, you just have to specify the duty cycle of it; frequency of the signal is a fixed value, you can't change it easily unless you go the C++ code. This implies that Arduino code is less flexible but it also makes it a lot (really a lot!) easier to use.

After doing a lot of the examples on the tutorials, my objective was to control the servo motors to be used on my robot. So I used the servo library from Arduino to control the position of 1 servo by manipulating a potentiometer, then the same for 2 servos and then for all the 5 servos.

As I mentioned on the previous post, the Arduino Uno board can source up to 2 servos; so for sourcing all the 5 servos I used an external 5V power supply. Be careful that if you use a wall adapter power supply, not to buy any cheap one because it can be very inaccurate on the voltage it says to provide.

Then I created a costume sequence with the servos, that's a bit trickier since you have to code each servo position separately, thus you have to know where every servo should be at every moment of the sequence. This exercise is very useful since it's something pretty similar than controlling the robotic arm in an open loop project.

You can take a look at how the servos worked on the following video:


Next step will be to build the mechanical part of the robot and create some sequence for it, so that the arm can show off.


Friday, January 20, 2012

Choosing my first robot


Where to start when robotics field is so wide? Where to start with so many kinds of robots and possibilities?

Step #1: Establish my criteria.

I started by asking myself: Do I want to build from scratch my robot or do I want to buy a built one? After some deep thinking and reading a lot of people’s experiences on the web, I went to the conclusion that for the first robotic project it's better to buy at least the robot hardware, creating it would take a lot of time and at most probably you want to start putting into the robot some logic right away.  
I remember from the time I was in college the painful debugging sessions when you have a low quality hardware structure, having to adjust electrical control and software with after every mechanical adjustment. So during my research I placed strong emphasis on looking for a sturdy and robust mechanical hardware that would give me reproducible and stable results.
Finally, another positive characteristic about buying the structural hardware in that way is that I can concentrate myself on getting familiar with the electrical hardware (servo motors, sensors, and controller).  Later I can have a project regarding mechanical part, but not now.


Next question was: What Kind of robot do I want? Also a though question, the type of robot to use would define some of the challenges I would face (e.g. equilibrium for walking robots). Keeping in mind that this is my first robot I didn't want to go for the most complex type of robot right away, I better master a medium range type of robot and then I will go on to most complex ones.
I decided for a robotic arm since it's a medium complexity structure that has a wide range of possibilities. A lot of studies have been done with this type of robot which can support my learning process and it’s still very used for investigation of intelligent systems.

Step #2: Choose mechanical hardware.

With all my criteria established, I surfed the web looking robot sites. For structural hardware and motors I decided myself for a Lynmotion Robotic Arm Kit (www.lynxmotion.com) like the one in the picture below. These modular kits have a strong finish in aluminum and they have very good reviews on different websites.



Step #3:  Choose a controller.

Lynxmotion offers a control solution for its robotics arm, but I was not very attracted to it since I was looking for a control solution that is more widespread and standardized, giving me the possibility of exchanging experiences and projects (one of current challenges in robotics field is standardization). If you would like the software solution they provide you will face the same issue, it's a customized solution that works well for this specific robot (besides it is a little expensive), it lets you move the robot, create sequences and even some type of closed loops projects; but it keeps you limited to that, there's no option for communication to other PCs, mobile phones, or other controllers. At the end point I'm looking for something without those boundaries, I know it may imply developing interfaces and logic for the robot by me, but that's exactly what I'm looking for!
During the last year I have been hearing everywhere about Arduino boards, the open source hardware project. I went and checked the specs and those boards had the capabilities to control servomotors and receive feedback from sensors (there are many videos about it on youtube), there are even lots of libraries for all kind of projects, makings things like motor control easier so you don't have to do everything from scratch (not doing what it's already done, thus focusing on new things). That's the kind of collaborating platform I was looking for; Arduino is widely used and has a large community of contributors.


In particular I went for the Arduino Uno Board (the basic board, see below picture) for the same reasons I choose a robotic arm. I have worked with microcontrollers in the past but with this board you already have everything you need for the microcontroller to work and Arduino have a programming environment based on C/C++ where you don't have to program in low level C for microcontrollers, for example you don't have to configure crystal (oscillator) frequency and deal with any bug about it. This board can supply current for one or two servo motors, but as the Arduino site states, if you are going to use more motors (that's my case) you have to source them from a different power supply. It's important to separate sources from logic and power to avoid weird issues (leading to painful debugging).

I got my Arduino board and robotic Arm a couple of weeks ago, so happy to finally have the hardware here. I have been playing a little bit with the Arduino board; my next post will be about it. 

Monday, January 9, 2012

Motivation


First of all a little background about me: I have been a technology fan during all my life. I have a BS in electronic engineering and I worked for semiconductor industry for 5 years. Now I'm working on automation of processes for several industries.

Why do I want to write a blog about my experience with robots? Well I'm a robotics enthusiast, I’m always looking videos, reading webs, papers and anything related to robots; but now my intention is to pass from being a fan to become a real developer, and I want to document that journey here. I do believe that documenting is crucial in knowledge building, it also increments exposure and consequently networking with fellow enthusiasts.

What is my one year objective? Initially I want to become confident on current robot tools and techniques, starting with hobby parts and controls, then moving to more advanced projects and finally creating cutting edge projects (hopefully documenting them through papers and submitting them in well-known forums). Sometimes projects may look simple to the naked eye but I do want to embrace them with a research orientation, focusing on obtaining well documented and reproducible results rather than how visible the robot may look.

What is my long term objective? On the next years I want to pursue a post graduate degree on robotics with a research emphasis. Then my dream is to get a job in robotics, uniting my passion to my career. Someday I read that if you are doing what you love, success comes for default; so I’m looking forward to go through that path.

I kindly invite you to follow me through my posts and feel free to send a message for any question or suggestion (onecuriousrobot@gmail.com).

Best regards,

Juan Carlos Brenes
onecuriousrobot@gmail.com