An important aspect of our project was the programming of our processor in order to have a functional robot. In this page, all the aspects of the software development will be discussed and subdivided in five parts: the potentiometer, the accelerometer, the servomotors, the final motion code, and the theoretically working but untested code using the accelerometer.
The first obstacle we encountered was the uploading of a program to our processor. An Arduino board was used, but the detailed explanations (given on their website) as to how to use it to upload a program on to an external processor gave no result at all. After many hours of unsuccessful tests, another approach was used: the processor of the Arduino was removed, and replaced by ours. Every time we wanted to modify the program, the processor had to be removed from our PCB, placed on the Arduino for the uploading, and then placed back on our PCB. This method was not very convenient but was the only one that worked.
Our methodology was to first develop programs for each part, that will be detailed below, and then to assemble the different parts. These programs were developed using the Arduino Language (available here) and open source programs available on the internet.
The easiest code that we had to write was the one for the potentiometer, since in the examples code given by Arduino there is an example of the control of a servomotor with a potentiometer.
Since this code is really simple and was not used ultimately, as said in the design page, we will not describe it.
The communication between our board and the accelerometer was set using a serial port interface (SPI). First, we had to understand how to enable the SPI communication. Fortunately for us, Arduino provides an example illustrating the use of this type of connection.
Once the communication was established, we had to transfer information. To do so, we had to look at the datasheet of our accelerometer (available here). The general principle is the following: a 16 bits word is sent to the accelerometer, containing all the information about the requested data (detailed in comments in the code). Then, the accelerometer sends back a 16 bits word, containing the desired information.
This is the key code of our robot. Indeed, if we are able to control the servomotors accurately and with the right timing, then the desired movement will be achieved.
Two ways were available to control our servomotors: either by producing a PWM "by ourselves", or using the Servo library given by Arduino. The latter was chosen.
The first thing to do is to know the range of action of our servomotors. To do so, we checked their datasheets (available here and here), and sweep tests were conducted.
An encountered problem, that made us lose a tremendous amount of time, is that if a position out of the servomotor's range is imposed, the servomotor does not respond at all, instead of going to the nearest position as the requested one. For instance, if the servo motor is at position 50, the maximum position of the servo is 160, and it is asked to go to 180, it will not go to 160, but will not move at all. For this reason, and since the extreme values are not exactly the one given in the datasheet, we wasted much time, thinking there was a problem in the connections or in the PCB.
Ultimately, after number of tests, we established that the range of the small servomotors was from 20 to 160, and the range of the large servo motor from 25 to 160.
In order to obtain reproducible results, we had to make an initialisation program bringing the servomotors to the desired initial position. As you can see on the program given below, we place the gripper's servo at 90, which is the middle range value, and the central servomotor to 25 which is his minimal value. Those values are going to be explained a little farther below.
Once the servomotors are at the right initial position, the next step is to make the robot move. The corresponding code is given below.
How does it work?
First, we close the two grippers and in order to counter the gravity force, we need a high torque so we ask the servomotor to reach the 80 degree position (keep in mind that in our initial close configuration the angle value is 90). As the gripper is already closed when the servo is in position 90, it will try to close it further to go to 80, and as a result, the gripper will be tightly closed. Then, after 3.5 seconds (this value was arbitrarily chosen) the gripper on the left will open, then the central motor will fully rotate and finally, at the right time (determined experimentally), the opened gripper will close. The code is then repeated for the second movement, but this time, it is the other gripper that has to open and close. In order to cross the ladder, a counter is used and once the end of the ladder is reached, we place an infinite loop, in which the two grippers remain closed.
As you can see we place a time variable called "time", which allows us to use the appropriate delay between two actions.
Movement CodeIn the global code given below, the use of the accelerometer was implemented. Theoretically, if we find the right value for the x and y references (xcmd and ycmd), this code should work, but due to lack of time, we were not able to test it.
You can see in this code that we have a safety measure. Indeed if there is an error with the SPI transfer or the data given by the accelerometer, if the timing is reached then the gripper will close, this allows the robot to cross the ladder even with an accelerometer problem.
Overall Code