Break Down Major Tasks in peng-zhihui GitHub Project: Robotic Arm

Zhihui’s ultra-mini robotic robot project.

Video introduction: [Homemade] I built a mechanical arm of Iron Man! [Hardcore].

Video : I made a DUMMY ROBOTIC ARM from scratch! – YouTube

Information Note (Updated on 22-2-9)

  • Added 3D model design source files.
  • Added gripper hardware design file and LED light ring PCB
  • Added wireless spatial positioning controller PCB file
  • Wireless teach pendant Peak hardware and software project added (as submodule)
  • The hardware design file for REF has been added
  • Added DummyStudio host computer
  • Added firmware source code for Dummy core controller (instructions see below)
  • Added 42 stepper motor driver hardware engineering
  • Added 20 stepper motor driver hardware engineering
  • Added firmware source code for 42/20 stepper motor drives
  • Added command-line debugging tool reftool (based on OdriveTool framework)
  • Added model files for the carrying suitcase

This is the complete design scheme of the original robotic arm in the video, the cost and production difficulty of the solution are relatively high, so students who want to reproduce it suggest waiting for the Dummy Youth Edition that I will release later, which will have the following improvements:

  1. The whole machine redesigned the structure and switched to 3D printing as a manufacturing solution (the original was aluminum CNC), which greatly reduced manufacturing costs
  2. The small cycloid pinwheel reducer designed by myself replaces the original harmonic reducer, which greatly reduces the cost of parts
  3. All software and firmware are common to the original and function exactly the same
  4. Add my own design PC computer and mobile APP (strive to add user initialization settings guidance)
  5. Improve the wiring method of the original motor driver, the original power trace adopts the form of welding, which is not easy to install and disassemble, and the youth version behind will use a 4P connector (power + CAN bus) connection
  6. The cost of the whole machine strives to be within 2000
  7. Most importantly, someone will find a nanny-level video tutorial!

About structural design

The original design in my video uses +Harmonic, of which the latter costs more (the second-hand I bought is about 600 yuan a piece), so in order to allow everyone to reproduce this project as much as possible, I will add a + low-cost solution later.步进电机谐波减速模组自制摆线针轮减速器3D打印

At present, the cycloid reducer has been designed and is being verified, and it is expected to use PC (or acrylic) cutting combined with 3D printing production, the accuracy has decreased, but the functions remain the same, and the hardware cost of the whole machine hopes to be controlled within 2000,<> yuan.

The designed cycloid reducer can be found in my other warehouse: peng-zhihui/CycloidAcuratorNano

About circuit modules

In order to achieve the main manipulator motion control function, the core of the circuit is actually 4 boards:

  • REF core board
  • REF backplane (i.e. the controller board inside the picker base)
  • Stepper motor drive
  • Peak teach pendant

The first two of them and Peak I have open source, and I refer to it when designing the stepper driver: https://github.com/unlir/XDrive This project, which is an open source closed-loop driver of a friend of mine, is based on STM32. The driver is divided into open source version and closed source version, the closed source version is based on discrete MOSFET performance is extremely powerful and very complete, the open source version of the ADC+ chopper driver chip, with basic functions, without CAN protocol.

I redesigned the PCB circuit of the driver (this project uses 20 and 42 steps respectively, and the 57 file is just for your extended use), added hardware support for the CAN bus, and completely refactored the original core code, providing compiled binary files that can be burned directly:

The main improvements are as follows:

  1. The code is refactored using C++11, many high-level language features are introduced, and the underlying part is mixed in C without affecting the code performance
  2. The hardware dependencies are completely decoupled, which can be easily ported to MCUs on other platforms in the future, and the redundant code is removed and the structured logic is clearer
  3. Added custom templates for CAN protocol and UART protocol
  4. Added parameter storage for analog EEPROM, which can save data without power
  5. Added any position set to zero, and guaranteed zero within half a circle in both directions (instead of one-way zeroing)
  6. Fully compatible with STM32-HAL libraries, configuration code can be generated directly using STM32CubeMX
  7. Other improvements, you only need to pay attention to the files under the UserApp folder for secondary development

The use of Ctrl-Step driver is relatively simple, after downloading the firmware, the first power-on motor will be encoder calibration, if successful, the next time after power-on press button 1 will enter closed-loop mode, through CAN or serial port to send instructions can control the motor, the description of the instructions see the source code folder and:UserAppinterface_can.cppinterface_uart.cpp

The role of other keys:

  • Press and hold both buttons at the same time to power up, the encoder calibration will be performed automatically, and if the first calibration fails, it can be recalibrated
  • Press button 1 to switch between closed loop enablement/closed loop incapacitation
  • Press and hold button 1 to restart the board
  • Press button 2 to clear the locked-rotor protection
  • Press and hold button 2 to reset the target value to zero (e.g. if it is in position mode, the position will be zeroed)

Other functions should be set through code or communication protocol, such as setting home zero pointPID parameters, CAN node ID, various motion parameters, etc., you can study the code yourself.

Of course, another way is that you can also use the GRBL class driver to drive the robotic arm, the problem with this scheme is that the GRBL firmware coupling is relatively strong (after all, it is not designed for robotic arms but CNC applications) is not easy to expand, and the pulse form of control makes the wiring extremely inelegant (each joint has to pull the wire to the controller separately, resulting in a long trace of the last few joints).step/dir

And I use an integrated closed-loop way to connect all motors in series, take the CAN bus so that the overall wiring only needs four wires (two positive and negative power supply, two CAN signal lines), in addition, the bus model allows the motor to work in 、、、 mode, and the pulse mode can only work in position and trajectory mode, and cannot be complex control.力矩速度位置轨迹

Peak, I have already open sourced the hardware and software, you can go to the SubModules folder and read the README instructions over there.

About the core firmware

The firmware core of this robotic arm is kinematic attitude solving, this piece I am still sorting, and it will be packaged more perfectly for open source, which has been open source, and many parameters that are now written will be designed to be configurable, so that everyone can migrate to the robotic arm of their own design after learning with this project; At the same time, I ported the firmware from the LiteOS framework to the more familiar FreeRTOS to facilitate secondary development.

Firmware instructions for REF:

The firmware mainly includes several functional modules:

  • BSP driver: On-board various hardware drivers such as OLED, IMU, LED, buzzer, non-volatile storage, etc
  • 3rdParty libraries: Includes U8G2’s graphics library and Fibre’s serialization/deserialization library
  • Core: ST’s official HAL library
  • Driver: ARM’s CMSIS driver
  • Midwares: FreeRTOS support package
  • Robot: The core robot library, including various algorithms and driver code
  • UserApp: Upper-level application, you can develop other applications based on the API interface I provide
  • Among them, OLED is ported using Arduino’s U8G2 library, which can easily simulate various debugging and system information, and because of STM32’s hardware I2C and BUG, the software I2C driver screen is used here, and the measured frame rate is higher than that of hardware I2C.

DummyRobotThe class is the complete definition of Dummy, and when initializing, you need to set the stepper motor drive information and its own DH parameters:

The drive information includes: CAN node ID, whether it is reversed, reduction ratio of the reducer, and motion limit range.

The meaning of the DH parameter is as follows:

The configuration of the robotic arm needs to meet the Pieper criterion (the robot’s three adjacent joint axes intersect at one point or the three axes are parallel) to obtain an analytical solution, so you can modify it according to the structure of Dummy, and then replace the DH parameter yourself to port my code.

About position memory, and power-on zero point calibration:

Since the position of the absolute encoder is only valid in one turn, the industrial robotic arm is generally encoded at the output end in order to obtain the absolute position after deceleration, but the accuracy is reduced by 30 times (reduction ratio), so it is more reasonable to do dual encoders or low-power encoders + batteries; The dual encoder in my project affects the compact design, so I used a more ingenious way: use the current loop driven by the motor to control the directional movement without zero point after power-up, confirm the thick zero point (the infinite switch returns to zero) after hitting the limit of the robotic arm, and then fine-adjust the zero point according to the position of the singleturn absolute encoder. The zero point in this method is error-free and almost unaffected by the machining accuracy, because it is the effective accuracy range of absolute encoders within 12 degrees (360/30).

Peak’s firmware description:

Peak is based on the X-Track project, you can go to the Peak repository to view.

About the upper computer

The software simulation in the video is based on RoboDK, and I developed the Driver that connects to Dummy in the video (the driver part of the official document is introduced, the original version is based on the TCP network interface, I modified it to a serial port and compatible with the dummy protocol). However, since this software is chargeable, I have also developed my own host computer based on Unity3D, which has been released in the repository.

The host computer is currently not planned to be open source, because there are still many functions to be added, I also hope to finally make a general software similar to RoboDK, you can also use it in the future to make your own robotic arm, of course, the software will definitely be free.

About the control algorithm

First of all, the kinematics part has been realized, the positive and reverse solutions are calculated by traditional DH parameters, the positive solution (joint angle to find the end position) is the only solution is easier to do, the reverse solution (terminal pose to find the joint angle) will involve multiple solutions (generally 8), the algorithm I use here is to solve the config used by the 6 joint changes in the previous pose and the target pose The smallest of the <> joint change angles as the inverse solution. This ensures that the robot arm always switches attitude with the smallest angle.

Then the joint angle to the motor driver input signal conversion piece, I use a trapezoidal acceleration and deceleration curve for speed position planning. For example, in the MoveJ command, when receiving a joint angle motion command, the controller will perform a differential calculation of the motion angle, get 6 differential angle of motion, and then take the largest angle θ of the 6 differential angles, and calculate the time required for the motion θ angle according to the set JointSpeed parameter (consider the acceleration and deceleration), use this time as the motion parameter of the remaining 5 motors to calculate their respective acceleration and deceleration speed & maximum speed, and then 6 motors synchronize the movement according to the calculated parameters. Synchronization and smoothness are guaranteed.

The other six motors are connected using a CAN bus, each receiving information from two ID numbers (own ID, ID number 0), which is used for information broadcasting and synchronization. After receiving the motion command, the motor stores the information in a shadow register, and starts to move after receiving the broadcast synchronization signal, which can further ensure the synchronization of the motor.

Finally, the kinetic part is still under development, and this piece has not been fully realized for the time being. The kinematic and dynamic algorithms described above are highly recommended to read the book “Introduction to Robotics”, which is very detailed.


Frequency at which instructions are sent
How the instruction is executedCan be interrupted by new commandsThere is a pause between commandsSuitable for the scenario
SEQ (Sequential Instruction)Random, low (<5Hz)FIFO queues execute sequentiallynotYesSend several key point poses at once and wait for execution in turn to ensure that the key points arrive; However, there is a certain pause due to the process of deceleration to 0 between the key points; Suitable for applications such as visual gripping, palletizing, etc.
INT (Real-Time Instruction)Random, unlimited frequencyInstruction override, immediate executionbenotFor real-time control, new instructions will overwrite the executed instructions and get an immediate response; However, if a series of instructions are sent at once, the effect will be to execute only the last one; Suitable for scenarios such as motion synchronization.
ToDoTRJ (Trajectory Tracking)Fixed, high (200Hz)Automatic interpolation, fixed cycle executionnotnotSuitable for applications that require accurate trajectory tracking with slower speeds; Example scenarios such as 3D printing, sculpting, painting, etc.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.