Introduction: API for a Web Controlled Robot
"These materials and the information contained in this instructable are provided by students enrolled at Software of Places (www.softwareofplaces.com) Class at PUC-Rio University. The content represented here is the student’s final project for class evaluation porpoise published by the student and is solely the responsibility of the page author. Statements made and opinions expressed are strictly those of the author and not of PUC-Rio University."
That is our instructable to provide a base hardware and API for a Robot Office Assistant. The main idea is provide a web controlled API that control a remote robot. We use some hardware and software parts relying on Intel Galileo or Intel Edison.
We not aim to provide yet another web controlled little car, but we do as well! However it´s just a proof of concept. The idea around it is to explain how to use that and how to extend that. Creating your robot base as a car, you can insert your own modules like arms, cams, sensors, screens etc.
The following image illustrates the approach to provide our Robot. We intent to use Intel Edison/Galileo to control all hardware by using it´s NodeJS API that runs multiple code blocks handling that. This is capable to run our brief code to control movement and you can insert your own features.
Step 1: Hardware - Base
First of all, we need to choose our brain. It will be responsible not just control the hardware but also to be the be an enabler for a remote and web controlled API. We are using an Intel® Edison with an Arduino Breakout Kit. Probably it is available on your preferred maker store or you can check it out on https://www.sparkfun.com/products/13097
We picked up Intel Edison because it is capable to piggyback on all Arduino based and wide available hardware interfaces, it is capable to provide a network powered Linux environment and it has enough processing power for further applications. In three words: Flexible, Powerful and Connected.
If you don’t have an Edison or even a Galileo you still can do that. You can use your Raspberry Pi, Arduino, and others. However, some assembler details would be necessary. Check the following link to check the full hardware list: http://cylonjs.com/documentation/platforms/ . We will return to this point later when we speak about Cyclon.
Step 2: Hardware - "The Wheels"
After choose your robot brain, you need to choose how it will move around. This is the easiest part. You will need at least two brushed motors and a chassis. You can create your own with just two brushed motors and some wood or you can buy one as we did. We picked up a 4WD Robot Chassis available here: http://www.hobbyking.com/hobbyking/store/__26250__4WD_Robot_Chassis_KIT_.html
If you don´t wnat to buy that, you can choose yours and assembly that. Just use two brushed motors to stay compliance.
Step 3: Hardware - Motor Wiring
If you are new on hardware assembly a trick part is how to wire the motors to the motor drive. In our case we will use two motors from the same side as one single motor and link to the motor driver. A useful tip is soldering the wires on the motors using a same colors standard and different cable colors to debug the order easily. You can find 4 pairs of cables with different colors easily inside an old used network patch cord.
So, to help yourself, you could copy and connect everything like us. Just pick each pair and solder like this suggested order before you assembly the entire car base.
Step 4: Hardware - Motor Driver
The motor driver is the circuit responsible to provide power to the motors, steer their direction and speeds. That is the component between your brain (Edison) and your wheels (the little red car). There are many drivers and similar Arduino shields. In our case we picked up a very often used L298N dual H-bridge shield.
There many shields completely compatible using a L298N, we bought our one here:http://www.dx.com/p/l298n-stepper-motor-driver-con...
You should fix it in the car. Than add a couple of wires to power up the circuit (red to positive and black for negative). Use the VMS for the positive wire, so you could use several kind of batteries. Im my case, I used 12v batteries.
Then wire the motors wires exactly like the second and third image. Note on second image, left motors assembled white and colored wires together, so as right side. As said previously, both motors from a side acts as one motor, so you could use just one if you wish.
Note on second picture there are some jumper cables plugged on IN1, IN2, IN3, etc... You can use any order, but YOU MUST declare it on source code. There are some variables to do that, don't worry, remember that and everything will be fine.
Step 5: Software - Bases
Regarding base software, we mean the software responsible to move the robot base upon commands. So it is the execution portion of our API. We consider that you already prepared your Edison to program with. You can find several tutorials here on Instructables to get started with Edison. Please, test your Edison/Galileo with some templates, tests with LEDs would be enough.
Is possible to access Edison/Galileo straight in order to control attached hardware as your wishes or use standard APIs or mixes both. To control the moviments we choosed and API called Cylon (http://cylonjs.com/). We did that just because it makes easer port to other boards different from Intel.
This project just uses digital pins signals, a very simple interface to motor driver.
Step 6: Software - Source Code and Instalation
Now you are ready to install the basic software to control your robot! Of course it just move around, but we will show how to improve that.
First you need to download that from github:https://github.com/brunoolivieri/SoP or download the attached file SoP-master.zip.
Second you open the download on your Intel XDK IoT Edition and upload that. So, that is fine!
Step 7: Software - How to Use
I order to test the software you can use your web browser to command the robot moviments. Get your Edison/Galileo IP number and test some commands and have fun!
Check it out regular commands:
Move forward: http://YOURIPADDRESS:3000/api/robots/JohnnyTwo/commands/forward
Move Backward: http://YOURIPADDRESS:3000/api/robots/JohnnyTwo/commands/backward
Turn left: http://YOURIPADDRESS:3000/api/robots/JohnnyTwo/commands/turnLeft
Turn right: http://YOURIPADDRESS:3000/api/robots/JohnnyTwo/commands/turnRight
Step 8: Software - How to Hack
Beyond to use the code to control de robot base, you can push that. You can use these commands:
APIs Methods full list:
API low level json with methods query:
Command to bypass API commands and method you can access Cylon directaly:
Step 9: Software - How to Extend
Once you used our code you can improve it and share it again. To modify the moviments kinematics itself you need to to modification on JohnnyTwo methods. If you need to insert more hardware, like arms or sensors, you have three options:
a) Extend JohnnyTwo methods adding more logics, more hardware connections or both. That would run inside the same thread called JohnnyTwo above Cylon abstration.
b) Create your thread above Cylon.
c) Coding without CylonJS.
Step 10: Final Remarks
I hope next students from Software of Places (SoP) - INF2790 discipline and everybody that reaches this Instructable can use that on the future.
Software is Everywhere!!!
We have a be nice policy.
Please be positive and constructive.