I really wanted to try was designing a robotic arm completely from scratch. There are many open-source designs available, but I thought it would be gratifying if I could design, build, and program one from nothing (and it was).
I will talk about both the design and programming phases. But I will focus more on the programming side since it is not just controlling servo angles.
Here is a link to video of final project in action - https://www.mathworks.com/videos/how-to-control-a-robotic-arm-from-a-remote-location-using-iot-1538564659095.html.
I used Simulink to program an Arduino MKR1000 which is the MCU controlling the robotic arm. I then added the ability to control the robot arm from practically anywhere through ThingSpeak, an open IoT platform with MATLAB analytics.
Hardware Needed
- 15” x 20” 1/8-inch plywood
- Arduino MKR1000
- 5x GS9025MG servo
- 2.1mm breadboard friendly DC barrel jack
- 6 V DC barrel jack power supply
- Jumper wires
- 3x 2n2222a Transistors
- 10x M2 nuts
- 10x M2 x 10 screws
- 40x M3 nuts
- 40x M3 x 25 screws
Software used
- MATLAB
- Simulink
- MATLAB Support package for Arduino hardware
- Simulink Support package for Arduino hardware
- MATLAB Support package for ThingSpeak
I wanted to keep the cost of parts low, so I designed this for hobby servos, specifically the GS-9025MG model. This meant that the final weight and size was limited. This was because micro servos could not exert much torque, and as a result, cannot lift heavy lever arms.
I tried prototyping with 1/4 inch plywood, which proved to be too heavy for the servos. I reduced the length of the arms and used 1/8 inch plywood, and that fixed the servo control issue. I drew up the design using Fusion 360, and downloaded the design as a.dxf file, which I then laser cut.
Also, supplying continuous DC voltage from a wall outlet proved necessary because the current drawn from battery packs was very high and drained them very quickly.
Regarding controlling the motors, the Arduino MKR1000 has 4 PWM pins, but I needed 5 to control the 5 servos. I got creative and used one PWM pin to control 2 servos and a digital pin to toggle between the two servos and control one at a time.
Here is the circuit describing that:
Here is the wiring of the servos to the Arduino:
There were two parts of the programming, the prototypingphase where I assembled it and got the servos to command to a certain location, and the precise control phase where I was able to command a location to theservo using ThingSpeak.
PrototypingUsing sliders and constant blocks I was able to command the servos on the Arduino to move to certain angles. I used this model to find out the biases between the commanded angle and the actual angles of the arm, as well as the range of allowable angles for each servo.
The blocks with the gear on them are the PWM write blocks for commanding the serve to a certain angle between 0 and 180.
I used inverse kinematics for an arm in 2D planar motion to solve for the angles necessary to move the arm to an XY coordinate. I found that this link explains the kinematics rather well: https://appliedgo.net/roboticarm/
Precise ControlAlthough this looks more complicated than the other one, the logic is still the same. The output blocks are still the servo write blocks with the gears. The input blocks are now not the slider/constant block inputs but are being read from the ThingSpeak channel. I will elaborate later on using ThingSpeak. The inputs are the X and Y position of the arm, which using the loc2angles MATLAB function block are converted to commanded angles for the arm.The angles2loc block at the top of the model is just a way of monitoring the system to make sure the servo angles translated to the correct input position using forward kinematics. One of the cool tools from Simulink that I used in this project is External Mode. This allowed me to monitor the system while it was running on the Arduino itself.
The blocks with the gray cloud on them are the ThingSpeak read block built into the Simulink support package for Arduino. I input the channel ID, the data field number I want to retrieve, and the API read key, and it outputs the data from that channel and field. Don’t worry, if you are unfamiliar with any of those terms, I will elaborate soon.
Using ThingSpeak: Creating and Using a Channel1. Go to https://thingspeak.com/
2. Click ‘sign in’ in the top right corner, and login using your free MathWorks account.
3. On the dashboard page click ‘New Channel’
4. Fill in the data like below. The data shown is all you need to fill in.
5. Click ‘Save channel’ at the bottom
6. You have now created a ThingSpeak channel
7. In the MATLAB command window or using the MATLAB mobile app, you can enter commands that look like:thingSpeakWrite(chID, [0.6963.94 -12 0 0], 'WriteKey', APIKEY, 'Fields', [1 2 3 4 5]);
This writes new data to the specified fields in the ThingSpeak channel. You can change the values in the second argument of the function call to change the value of the corresponding field. After changing the values, the channel data should look like this:
When you finish with setting up the ThingSpeak channel, you can either run the model on the Arduino in external mode, or by deploying to the hardware. In the Simulink model, go to ‘Model Configuration Parameters’ by clicking on the small gear in the top menu panel, select ‘Hardware implementation’ and make sure the ‘Hardware Board’ is the Arduino MKR 1000.Under ‘Target Hardware Resources’ in the same tab, click on WiFi properties and enter the WiFi credentials to access the network.
Click the green run button to run the model in external mode or the blue deploy button to deploy it to hardware.
Once the model is running, you can write new data to the fields in the ThingSpeak channel from MATLAB or MATLAB mobile on your phone and watch how it moves your robot arm!
Code
Comments