The best part for this elephant is installed two sensors to detect the trunk and the head movement, so that we can program this to avoid the motor over-driving the head and trunk to induce unnecessary damaged. Calibration is very important for machine and robot, identify the zero (or required) position, so that they can be working within the expected range and accuracy. The calibration will run every time when the elephant start because we got unknown starting position of the head and trunk. Once, it dance, it will be always the same.
As you can see above, there are two sensors installed – color sensor and touch sensor.
During the head is moving up, the color sensor is detecting the color in it’s front. When the elephant raises it’s head up to the limit, a red color should be detected. So, we did the coding as below.
When we setup a robot, we actually need to do some manual work to understanding your robot. Prior we wrote this calibration program, we analysis the movement of the head to understand the moving direction and the stroke of the head, keep those as preset ‘parameter’ – we got ‘head (D) down’ is ‘-800’.
Then, we start the program in a loop by detecting the color sensor until it detect ‘red’. Before the red color being detect, the motor controlling the head keep moving up for every 10 degree, so that the head will not be crushed.
Once red color detected, the movement will stop and the motor degree count reset to the ‘zero’ position, so that we can control the elephant with a range of 0 to -800.
Same as what we done for the head calibration, we also need to do some manual work to understand the moving direction and the stroke of the trunk, we got ‘trunk (B) down’ is ‘900’.
Using exactly the same coding for the calibration but change the detective sensor from color sensor to touch sensor because touch sensor was installed when the trunk move up and it will hit the touch sensor.
Again, once the touch sensor is touched, stop the raising trunk and reset the degrees count, set this as ‘zero’ position.
Build instruction and the program
We created the program from scratch without referring any example, you can download from below.