Here are some preliminary instructions on how to get your Mechaduino up and running.
ASSEMBLY:You will need to mount the magnet to the back of the motor shaft. Note: the magnet must be diametrically magnetized, as opposed to axially magnetized. The magnet may naturally stick to the shaft, but we recommend a dab of epoxy or super glue to hold it in place. The magnet should be fairly centered, but the calibration routine will correct for minor misalignment.
The Mechaduino PCB must be mounted so that the magnet is directly under the encoder chip (Very close but not touching. See the AS5047 datasheet for details). We replaced the standard motor hardware with M3 threaded rods and short standoffs to mount on our Mechaduinos, but there are other ways this could be done.
When wiring your motor up to the Mechaduino board, please make sure that one phase is connected to ouputs 1&2, and the other phase is connected to phases 3&4.
You will need to make sure your Mechaduino has the latest Arduino Zero bootloader. If you are getting a Mechaduino as a reward from our Kickstarter, it will already have this! Otherwise you will need an Atmel-ICE or similar SWD programmer...
Next you need to install the firmware:
The Mechaduino firmware can be compiled/edited/uploaded using the popular Arduino IDE: https://www.arduino.cc/en/Main/Software
Once you have Arduino installed, you will need to add Arduino Zero support. Open the Arduino IDE, navigate to Tools>Board:...>Board Manager and install the latest "Arduino SAMD (32-bits ARM Cortex-M0+)" .
At this point you you can connect your Mechaduino via USB. It will appear as an Arduino Zero. (If it does not appear, please make sure any drivers have finished installing, then try hitting the reset button or disconnecting/reconnecting the hardware...see note below)
Download the latest Mechaduino_01 multi-file firmware, open it in the Arduino IDE, compile it, and upload to your Mechaduino.
Apparently the arduino zero drivers do not always automatically install. Please take a look at these instructions:
I have had issues where it will show up in the device manager, but not as a COM port (as an unidentified device). If this is the case, the bootloader is present, but the drivers have not installed properly.
The first thing you will need to do is run the encoder calibration routine.
With the Mechaduino connected to your computer, open a serial monitor (115200 baud) in the Arduino IDE. You will need to provide V+ to the Mechaduino to power the motor drivers (needed to calibrate). Type "s" and press enter a couple times to verify that everything is working. The Mechaduino should step like a stepper. It is currently in open loop mode. press "d" and the stepping direction will change.
Now, make sure nothing will touch the Mechaduino shaft during calibration. Type "w" to start the calibration routine (... may change the letter soon). The Mechaduino will now step through all full steps to calibrate the encoder. When the routine is done, a very long lookup table (16,384 entries) will be printed to the serial terminal. These are the calibrated angles at each encoder count. You will need to copy these into the Parameters.cpp file here:
Note: you can easily select the whole lookup table from the serial monitor by clicking on the next line and dragging the cursor up.
Save, compile, and re-upload the firmware to your Mechaduino. you are all calibrated.
As long as you have "serialCheck();" in your main loop, you can use the following built in commands to control the mechaduino from a serial monitor:
s - step
d - dir toggle
w - encoder cal routine
y - enable controller interrupts
n - disable controller interrupts
r - enter new setpoint
x - position mode
v - velocity mode
t - torque mode
q - parameter query (prints current parameters)
e - reads encoder diagnostic register
p - print [step count] , [assumed angle] , [encoder reading] **this needs to be updated to include calibrated values
...see serialCheck() in Utils for more details
TUNE CONTROL LOOP:
At this point you may need to tune the controller gains. By default, the position and velocity loops have PID controllers with parameters that can be edited in Parameters.cpp:
PID values will vary a lot depending on the motor you use and the load you have connected to your motor. There are lots of resources online that discuss PID tuning, but here are some simple pointers:
-Start with a low proportional gain and no integral or derivative action. If the motor seems to buzz or behave erratically, then your Kp is probably too high. Try setting kp low enough that the motor behaves like a fairly compliant spring about the setpoint.
-Slowly increase kp to improve the stiffness of the control. Adding integral action can remove steady state errors. Derivative action can also be added in to improve performance.