Exploration status, things done and to come

Time has passed since my last post… I explored many subjects that are really fascinating to me !

Prolog, Golog and FSA planner project

For example, I integrated the swiProlog engine in DeMIMOI models so that I now can run some Prolog scripts inside my models. This could be interesting to implement logic based reasoning.
And on top of this, I discovered the Golog framework from which the FSAPlanner is derived. This upper level Prolog extension allows for an even crazier reasoning. This is called « planning with loops » in the litterature.
I tried using the planner on my robot arm but with very limited success… It’s not easy to get familiar with the language features and syntax, and even worse for me who have not that much experience with Prolog.

Steering Behaviors

I also made a DeMIMOI model that integrates Steering Behaviors from Craig Reynolds. This is a very interesting concept that allows an entity to move through its environment based on strategies such as seeking, fleeing, wandering, arriving, etc. A set of parameters such as speed, weight, steer force allow to customize the obtained behavior.
While I was programming my own implementation, I was vastly inspired by this source code from Rahul Sindhu. Though I separated the graphics stuff from the math underneath the steering behaviors and also changed the math from 2D vectors to any vector dimension. The latter is a key point because I may need to get a behavior in 3D space or even in 5D for example on my robot arm, with one dimension for each arm joint.

Control Theory models

Then I went back to DeMIMOI models, and focused on implementing some math and signal processing functions such as filters, PID controlers, summers/subractors blocks and so on.
I managed to get a model that is able to drive the AL5C arm by providing commands in sensor units. This allows to drive the arm without having to deal with servomotor driving commands and its correspondance in the feedback (i.e. potentiometer) data range, so no calibration needed.
In parallel I also went back on the DeMIMOI memory model I talked about on a previous post to add what we would call « short term memory ». It simply stores data in the PC RAM, i.e. for a short period of time.
Then I used this model and the math models to build a sample application that makes the robotic arm move the same way I show it manually. I mean, I manually move the arm, and while I’m doing this, the system stores each servomotor position thanks to the potentiometer feedback. Once I finished the desired movement, I ask the robot arm to play the recorded movement.
The model I built for this purpose is as follows :

This diadram shows the DeMIMOI models structure to manage a record/play movement. It shows a structure based on PID's, the same structure is used for each arm joint.

This diagram shows the DeMIMOI models structure to manage a record/play movement. It shows a structure based on PID’s, the same structure is used for each arm joint.

As usual, this picture is extracted from the model itself which is able to produce the Graphviz code of its own architecture.
The potentiometers positions are stored in the DeMIMOI_Memory while I move the arm. Then, the memory pointer is restarted so that it points to the first record. The stored positions are then fed to the control model based on PID controlers which in turn feed the robotic arm servomotors.
The reason for cascading two PIDs is to implement some kind of small stepping process to reach the desired position. The first PIDs (PID1, 3, 5, 7 and 9) are pure proportionnal. The other PIDs are pure integral. The diagram shows the structure configured for playing. For recording, I only update the first two models on the left (AL5C arm sensors and DeMIMOI_Memory0).

The obtained behavior is pretty good and the movements precision is quite impressive ! Well there’s some offsets that I think come from this : the potentiometer data precision is poorer than the servomotor commands. It introduces offsets and errors because of this difference I think.

Current project

So, now I have a robotic arm that is able to move quite precisely using the servomotors feedback units. This way, if I manage to build a behavior model that is able to move the arm to pick up an object, I’ll have a building block this will allow me to reach new possibilities !
My next goal is to build such a model, a model that is able to calculate the position of an object thanks to the webcams information. This part will be the subject of my next post, as I prefer making a specific post for that (pretty big) subject.

Some news on my DeMIMOI library

First of all, I wish everyone coming to this blog a happy new year ! Should this year be healthy and make your projects come true !

It’s been a while now since I published the code of my DeMIMOI core library. I had some time to make some improvements and add some more features to make it even more attractive to me, so possibly for anyone willing to give it a try too.

I thought well when I hoped this platform would help me easily build systems and make a bigger one by connecting smaller ones. I successfully managed to use the library with neural networks (special thanks to Accord.Net and AForge.Net). For example I made DeMIMOI models of a NARX (Nonlinear AutoRegressive eXogenous) neural network and a ARX regression model (AutoRegressive eXogenous).
These models can mimic almost any dynamic system mostly because they have a backward link that make their outputs at time t-1 one of their inputs.
Using the DeMIMOI library this backward link is easy to model and to code since it’s just a connection between an input and an output that, in code, is translated by a myModel.Outputs[0][0].ConnectTo(myModel.Inputs[0][0]) for example. The data flow is then automatically managed by the DeMIMOI core.

I also started to put a database manager in a DeMIMOI model which can currently connect to a Mongo database. So I can save and retrieve data to build models or to act as some kind of a memory… Well it’s still in development now but the main features are already up ! I mean at least reading data from a pre-existing database. One step at a time right ?

To give you a better idea of what I’m talking about and what I’m doing, I’ll show you a picture of the system I’m currently working on.

First of all, let me just explain the background.

While coding the DeMIMOI ARX and NARX models, I wanted to build models that can learn the behavior of the servomotors of my AL5C robotic arm.
On a previous attempt last year, I had the arm moving freely and randomly while an application was recording at each time step the angle values from the potentiometers of each servo (thank you so much Phidgets !).

The results have been stored in a database that I can read using my DeMIMOI memory manager. Those data can then be sent to the ARX and NARX models, and also be used by the learner models to fit them to the servo behavior.

For this purpose, I coded the system which is described by the following diagram :

DeMIMOI NARX and ARX learning Lynxmotion AL5C servoBy the way, this image has been created using the GraphViz code that is automatically generated by the DeMIMOI collection that holds all the blocks of the system.
That’s a feature I’m quite proud of since it allows me to quickly check if what I coded is what I expected the system to be !

On the left of the diagram is the memory manager that reads the servo values from a Mongo database. The data produced is then fed to the ARX model and its teacher. They don’t need extra data processing, as opposed to the NARX model.

Indeed, the NARX model is made of a neural network that needs normalized data. That’s why you can see that the data coming from the memory block is also fed to a normalizer block that converts the raw data to a [-1, 1] range before being sent to the NARX and its teacher. Then the data coming out of the NARX model is denormalized to revert it back to its original data space.

On the ARX and NARX models you can clearly see the backward link that connects the output to the input. This link makes the network seamlessly recurrent. And again, in term of coding, it’s nothing harder than creating the link !

You also may have noticed the three probes that display some data values. This was for me to quickly check what are the model ouputs (simulated) compared to the real output (measured on the real system). On that run, the ARX is better than the NARX, but I currently didn’t push any analyze further to explain this…

My next work will now be focused on analyzing the results deeper, maybe working on the so called BPTT neural network (ouch ! it hurts !) or maybe even trying to make some kind of automated learning shell that would be able to test multiple models and parameters and then select the best one…
I know ! It seams like there’s going to be a huuuuge mountain to climb… I fight this feeling by telling me that I already climb quite a big part that it would be even worse to stop now !

I’ll let you know of my progress in a while. And do not hesitate to say hi or comment on this ! I’d be curious to know what it feels like for someone external !

Lynxmotion SSC32/AL5x Robotic Arm Library

It’s been a long time I did not post anything on my blog… I’ve been quite busy during the past few months !

I did not do any major development so far and I decided to slowly come back to my experiments by publishing some of my code. It’s been a while now that I thought it would be cool I publish my code for the Lynxmotion AL5x and its SSC32 board.
I was quite surprised to see that there’s no existing library for these devices.
I made some improvements on the code I wrote some time ago, mostly to support more SSC32 features and to have a better, cleaner and commented code.

So there you go guys, the Lynxmotion library is on my Github account : https://github.com/remyzerems/Lynxmotion

As you can see from the Github page, the main key features are driving servos, input/output access, SSC32 enumeration and of course AL5x joints driving.

Hope this will be in a way useful to somebody !

Servo position feedback

In my previous article I wrote I modified the servos to get the position feedback. I’m going to give you some information on how to do it.

Before you start, you should be aware that modifying your servos will break the warranty so if you do it, do it at your own risk. This operation requires a lot of patience and you must be thorough when you do it not to make short circuits which may burn irremediably your servos.

The full procedure is well described in the following links :

On my configuration, I connected two wires as shown in the first link. I think this hack is better than the second one because first of all, if you make your measurements on another card (which I do), you won’t have to find a way to get the cards ground together. Secondly, it makes a real measurement of the volt directly at the source of the potentiometer. And finally it may be better for electromagnetic immunity.

I also managed to use the seal to pass both cables (original cable + feedback). To do so, I just used a cutter to give the seal some more room to allow the bigger height caused by the new wires.Servo seal and cablesIn the picture you can see what it finally gives… It looks good ! If you see well, you may have noticed that there’s 6 wires ! Yes indeed, but there’s the red one which is not connected but let there for spare purposes and for esthetism too.

The cable composed of white, red and black wire is the 3002 cable from Phidgets. I connected the black one on the Ground signal (same signal as the black wire from the original cable) and the white one to the servo’s wiper. I soldered the wires as close as possible from the potentiometer to avoid losses and perturbations.

The final results are very satisficing and quite comparable to those obtained by this guy : http://www.youtube.com/watch?v=ygX7sQM2gq0.

Hope this will help people !


Here is another helpful publication : http://learn.adafruit.com/analog-feedback-servosMoreover, Adafruit is selling servos with embedded feedback position ! No more need to hack your servo to reach the holy grail !

The project / Le projet

My goal for this project is to explore AI techniques through diverse experiments. AI is really fascinating so in my spare time I like to try some stuff on this theme…
To do so, I bought the following items :

I first bought the AL5C robot and made some experiments on Neural Networks, but quickly realised I needed some feedback information from the arm (servos positions, video…).

That’s what the Phidgets stuff are for. I’ll make a specific post on how to modify the servos in order to get the position feedback and wire it to the Phidget card.

For the programming stuff I decided, as I’m familiar with, to use :

  • Microsoft Windows XP (well not the best choice ever but, must be compatible with newer ones)
  • Microsoft Visual Studio 2010
  • Aforge.Net and Accord.Net which are really good C# libraries to work with AI.
  • Virtual Machine to hold the whole configuration in a kind of nutshell (isolated from my everyday computer)

I first started with a nice but a little bit mathematic book : Apprentissage statistique from Deyfus. For French speaking people, there’s a good online pdf to read here : http://www.math.univ-toulouse.fr/~besse/pub/Appren_stat.pdf.

The advantage of this reading is that it allowed me to get the basics of some themes like neural network or data preprocessing.

So here is the current state of my customized robot arm :

The robot armTo better understand what the system is, here is the block diagram of my current configuration :

Block diagram of the robot arm