Software for the Adafruit Motor Hat library for python is installed with the following commands in a shell (you have already install this for the motor lab):
# Activate your environment
cd ~/pythonBME210
source env/bin/activate
# clone library
git clone https://github.com/adafruit/Adafruit-Motor-HAT-Python-Library.git
cd Adafruit-Motor-HAT-Python-Library
sudo python3 setup.py install
You will also need the meArm code from my repository: https://github.com/uutzinger/meArmPi
# Activate your environment
cd ~/pythonBME210
source env/bin/activate
# clone library
git clone https://github.com/uutzinger/meArmPi.git
We have two kinds of Motor Hats. They differ by the address of the Motor Hat which is either 0x6F or 0x60. You can change the address the same way you changed it for the air sensors in our previous lab. The MotorHat requires 5V (better is 5.2V) from an additional power supply to the two input screw in terminals in order to work. You should set the max current to 300mA.
You can use the calibrate.py code code as a test example. Please make sure that you do not drive the motors to the end positions so that they will not collide with the mechanical stops. It is best to test one motor at a time and to adjust the positions until you determined the maximum and minimum for each motor. The pulse signal should be at 50Hz (20mS) and 1mS pulse with is full counter clockwise, 1.5mS center location and 2mS full clockwise.
PLEASE BE CAREFUL WHEN RUNNING THE CALIBRATE.PY.
THE END POSITIONS DIFFER FOR EACH SETUP. IF YOUR MOTOR HITS THE END POSITIONS (ARM HITTING WOOD INSIDE YOUR MEARM) YOU MIGHT BREAK THE MOTOR GEARS OR YOU MIGHT BREAK YOUR ARM OR YOU HEAT UP THE MOTOR.
WHEN YOU SET A POSITION FOR THE FIRST TIME, YOU SHOULD START AT THE MIDDLE (e.g. 1500)
THEN SLOWLY INCREASE OR DECREASE THE POSITION UNTIL THE MOTOR NO LONGER CREATES A VISIBLE CHANGE.
MINIMUM POSITION IS 500
MAXIMUM POSITION IS 2500
FOR RARE OCCASIONS YOU CAN TRY 400 and 2600
IF YOUR POWER SUPPLY INDICATES MAXIMUM CURRENT, OR THE VOLTAGE DROPS TO LESS THAN 4.9V, YOU HAVE SET A POSITION YOUR MOTOR CAN NOT PHYSICALLY REACH.
Please be aware that you will need to configure the software to match the angles of your installed motors. Those calibration values need to be entered into the meArm.py file.
After you completed calibration you can test it using the Demo.py program
You will need to run the Calibrate.py program and select each of the 4 motors and move them to 3 positions. The positions are shown in the spreadsheet below as well as the images. You will want to work on one motor at a time.
You will need to measure the angles as show in the picture below. It is easy to measure 0 and 90 degrees, You can use your phone and install a level program or you use a protractor.
To start this exercise, work with one motor first. For example your base motor. Disconnect the other motors from the motor hat.
Change the calibrate.py for base motor operation.
Move to middle position (apporx 1500) and observe that arm position. MAKE SURE THE ARM CAN ROTATE WITHOUT PULLING OUT THE WIRES OR KNOCKING OFF THE PI. We have extension cables.
Measure the 3 suggested positions by increasing and decreasing the position numbers. Make small changes unless you are sure your motor can reach the position.
Now use your shoulder Motor
This motor can not move as far as your base motor. (CHECK INSTRUCTIONS IN RED ABOVE)
Disconnect any other motors. This will make it easier.
Start with middle position (1500). This should move the first arm segment close to 90 degrees up from horizontal. Adjust it until its vertical. If you can not reach a horizontal position because you would need to use a number larger than 2500 or smaller than 500 you should talk to instructors. You will need to remove the axle screw and pop the plastic piece off carefully. Set the motor to 1500 and pop it back in when the arm is pointing upwards (90 deg).
Make the value larger until you reach the flat position which is when your first arm segment is close to parallel to the surface. Make sure the other segments are not blocking the movement (adjust elbow by hand if elbow motor is not energized). In this position your arm likely reaches below the surface. You might need to put your meArm on top a box.
If you can not reach horizontal position because you would need a value larger than 2500 you should talk to instructors. You will need to remove axle screw and reposition the plastic piece.
Make the motor value smaller until you reach a position where the first arm segment points backwards (larger than 90 degrees).
Now work on the elbow
Some process as for shoulder.
The angle is measured between the second arm segment and horizontal. If the second segments points downwards the angle is negative. If it points upwards it is positive. You need a much shorter range of motion but you need to be able to move the motor so that the plastic piece and the wood attached to it can reach almost the bottom of the cage. If you can not reach a position where the plastic and wood piece reach that position because you would need a number larger than 2500 you should talk to instructors. Its difficult to remove the axel screw. In this situation, I remove the side plate from the cage with the motor still attached and I remove the screw that links the first wood piece to the second piece in the linkage. Then I pop the plastic piece off and move the motor to 2500 and I pop it back on with a position where it will touch the base plate. Later I will make sure I do not move the motor all the way to 2500 right away as it could hit the bottom.
The gripper calibration is tricky. In the picture below I measure the angle of the plastic piece by looking from underneath the gripper and I measure towards horizontal. If plastic piece is horizontal, the angle is 0. Rotating it counter clock wise will close the gripper. Such angle is negative and in my case its about -45 degrees. To open the gripper completely I rotate the motor clock wise to about 100 degrees.
Once you measured 3 positions for base, shoulder and elbow the spreadsheet will tell you how accurate you were. The red gain (slope) value should be close to +/-130. You can decide to continue if they are +/- 20 off or you can remeasure the angles.
You can hand tune the values because the gain/slope for each motor should be the same (around 130). You can set the second red value (offset/zero) so that the errors become small (values in last column). This last step of hand optimization will get you very good calibration values.
The values that meArm.py needs are sweepMin and SweepMax. With hand opimization its the ones above the red values.
The meArm.py also needs the red angle values which are in radians (the values are computed from your entries in degrees).
Make sure that the values you enter match my order. If the smaller value is listed first, then your smaller value also needs to be the first number. You can find the original file on this website below and on github for meArm.py.
Finally, to open and close the gripper you need to search closeGripper and openGripper routine in meArm.py. You need to replace the 0.0 value with the angle in radians that matches closed and pi with the value that matches the open position in radians (red values in table).
Elbow about -80, -45, -5
Base about +45, zero, -45
Shoulder about +135, +90, +45
Gripper +90, -20, (make sure you put the correct angles from the spread sheet in radians into closeGripper and openGripper function in meArm.py)
In your version of the spreadsheet the order of the numbers needs to match my numbers. For example the number used to move the shoulder backwards is smaller and to move it forward to be parallel to the base is larger. The angles also need to match with their signs.
The middle position of the shoulder is about 1500 +/- 300 and then the first arm element should point upwards. If that is not the case check above if you need to pop off the plastic piece and readjust the meArm. With too much force the wood will brake.
At 1500 +/- 200 for the baseplate motor the arm should point forward. I have seen several base motors where the wrong screw was used to attach the handle to the axle. If you have metal motor you need machined screws.
I have also seen plastic pieces that did not fit onto the motor axle. Unfortunately there are two sizes and two colors of plastic pieces as well as plastic pieces for the larger motors. Most of them will be the correct ones but they should snap onto the motor axle. It is possible to remove the plastic piece and the axle screw without needing to disassemble the meArm.
At approx 1500+/-300 for the elbow the second element of the arm should be horizontal. Redajusting the elbow is difficult because your can not easily reach the axle screw. You would need to remove the plate to which the motor is attached and the screw that attaches the first wood element on the motor to the 4 bar linkage. Its best to ask instructor how to do that.
Please make sure your meArm moves freely when no motors are plugged in. Do not over tighten the screws.
Work on one motor at a time. Do not plug in all the motors at once for calibration.
Make sure motors are not pushing against a solid object otherwise they burn out.
The claw is difficult to calibrate. When viewing like in the image above, the angle of the motor axle is measured in respect to the horizontal. When Its closed, the angle is negative and the axle connector is pointing upwards and when its open its positive and the axle connector points downwards.
The red values in the spreadsheet in the first column should be close to 132 or -132. I would accept 150 and 110 but you might want to remeasure the angles if they are too far off. The other red value will be different for every meArm.
meArm.py needs to be updated to include your calibration values. It is for example the sweepMinBase and sweepMaxBase that you enter into the meArm.py file. Also you need to enter the angles in radians which are the other values in red in the table.
The values you measure for closed and open gripper need to be also entered. The function closeGripper(self): uses self.pwm.setPWM(self.gripper, 0, self.angle2pwm("gripper", 0.0)) where 0.0 is the angle for closed in radians. That is not correct and needs to be changed to -0.79 or similar as taken from the spreadsheet for the angle in radians for a closed gripper. The same applies for openGripper.