A YouTube video was the first time I encountered url_for feature. I couldn't understand what it was, for what it is. And today, I began to read the official manual
Let's say we need to a number of dynamic html page. The page need to be changed based on data from outside. Without template, we need to make a static HTML page in manual way. "template" gives an easy way to replace page's content in a very simple way. it feels like a mail merge feature in a word processor.
As we want to make a dynamic page, we need to use this feature "template"
(I am following this Flask tutorial)
This instruction shows how to deal with template, url_for in Flask.
How to use "template"?
import class
in order to use "template", firstly we need to import a class named "render_template" in python file.
fromflaskimportFlask,render_template
preparing a HTML file in "templates" folder
I prepared "hello.html" inside of templates folder.
templates/hello.html
<!DOCTYPE html><html><head><metacharset="utf-8"><title></title></head><body><h1>This is hello world</h1></body></html>
I love to make a "Happy Robot" such as Drinky, or Hungry Robot. This is also my favorite development because this will be another version of Dancing Robot.
What will do a final result look like?
I will record robot movement for some second or minute by using robot body itself. Motors can return their position value in a very short time. Data will be saved in PC storage.
The robot load the saved data and move in a timely base. The movement will be almost same as recording movement.
My windows PC is a main controller. Every communication signal is through USB port. It will be easy to move its development environment to Raspberry pi or so.
Hardware frame consists of 3D printed frames which are made by myself. I will share every part.
In short, this robot is going to dance really well.
What is different from another dancing robots?
Point To Point Motion (Animation)
In order to make a dancing performance for robots, robot engineer makes a lot of scene like an animation. This needs a lot of energy and effort. Each scene consists of set of angle values. Let's say we want to make a waving hand motion in the old way. You need to make a robot hands move left and then read all angle value at the moment. And then you make the robot hands move right and read angle values again. When you finish this work, you will get two scenes. Now, motion control software will run the motion based on the scenes. We can give time period between two scenes in order to make delay or speed.
With this way, If you want to make 4 minutes performance, you may have to do this unpleasant work for one or two weeks. This is not fun. Following videos are made by this old way.
On the other hand, there is another way to make motion data. This is a kind of motion capture. I am going to move the robot by my hand. Every certain millisecond, robot obtains each joint value and store it on storage. And later, I will send the data to motors then, the motors move exactly what I made them move. Motion Capture makes the robot movement very natural. You can see following videos I made.
Making hardware with 3D Printer
Study and Test Dynamixel SDK
Read angle values from motors
Save them in a PC storage
Play the data
Building a window application
I felt some annoying latency when I tried to communicate with a smart actuator (AX12) through Serial Communication. A single round trip time takes around 15 ms. As I wanted to make a robot with 21 motors, the total latency is so much for the project. 15 * 21 = 315 ms. It is under 4 FPS. The main reason why I do the project is recording motions from the robot. So, FPS is so important for me but it was too less than I expected. I faced a big problem.
I tested and tried this and that, I've found a solution at last.
Following result shows frequency only for 1 motor. It is around 60 Hz. It is too slow. If I use 20 motors, it would be lower than 4 Hz
(Consider I use windows 10)
Solution
I reduced the latency value in
Device Manager - Ports (Com & LPT) - USB Serial Port (COMxx) - Port Settings - Advanced... - BM Options - Select lower setting to correct response problem - Latency Timer (msec): - Select 1
And DONE!
Result
It goes higher! 500 Hz!!! I am so happy with this frequency. I don't know why windows set the latency default as 16 ms.
Every Robotis Dynamixel servo motors has feedback feature. We can read its status data such as current angle, speed or temperature. When you make a robot and teach them how to move, we have to give them a number of sets of angle data for each motors. In order to make the motion set, we have to know current angle value for each. What if there is no way to read their angle? We may have to calculate or measure many times. It is not efficient.
On the other hand, Robotis Dynamixel returns when they are asked to return their status. All we have to do is to save all the angle values to a proper storage. In this way, we can capture the motion set. Normally, small humanoid robot moves based on the motions on the timely based. It is really similar to a way to make an animation. A lot of scenes are changed in a specific time period. Like this method, we can teach our robots how to move.
I opened SDK example named "read_write.py". The file was for MX series. In order to use AX series, I needed to change some detail.
Change Serial Com Port Information
Of course I need to change Com Port number and the baudrate number. I already set up the AX12's baudrate as 1000000. My pc allocated the USB2Dynamixel to COM4.
Check the instruction table
Because I want to read "present position" of the motors, I checked which number is for the present position. The address is 36. So, I am going to request the AX12 to return value from address 36. If everything is good, the AX12 will dispatch value from its address 36 and return them to me. Ass you can see, the size of value is 2 byte. So, consequently, we need to request AX12 to dispatch 2 bytes from address 36.
The request look like this.
"Hey AX12 ID number 1, read 2 bytes of data from your address table 36. "
Then AX12 ID number 1 will return present position. When the packet received well, I will request the other AX12 (ID number 2) to dispatch the data in the same way.
"Hey AX12 ID number 2, read 2 bytes of data from your address table 36."
The, the AX12 will return present position value.
In this way, there must be time difference between motors because the reading moment time must be different. Robotis gives a synchronized method named Bulk Read. Unfortunately, AX12 doesn't have Bulk Read feature.
Result
I am able to read motor's position more than 2 motors at the same time (actually, there is time difference though).
Faced a problem
I faced a big problem. There are so big time delay. It takes at least 15 ms for reading. Because I will make a robot with 21 motors, it will take 15 * 21 = 315 ms for every single frame which means 3 fps (frames per second). That is too low. I need at least 24 fps. I tried to figure out and found a solution at last. I will post it later. https://eunchanpark.blogspot.com/2018/08/how-to-reduce-serial-communication.html
Because a robot need to move their motors all the same time especially for a joint robot. Let's think about that you want to push a door. You will reach out your hand by unfolding your arm and shoulder at the same time. If there is time gap between shoulder and arm, you cannot push the door properly. A normal RC servo motor is connected main controller in parallel way which means you can control them together at the same time. But, Dynamixel, on the other hand, shares their data line. There must be time gap between each other because every instruction is carried by communication. Some motors get data packet earlier than others. If the motors move as soon as they get data packet, we may have serious problem. We can say this as asynchronized.
How can make them synchronized? Robotis gives two ways to fix this problem.
Features we will use
1. Reg Write and Action - keeping instruction and waiting for Action instruction.
Let's say there are 3 bus drivers and a boss. The boss just give them their destination. They will wait until boss say "Action"
Boss: Here is your destinations. A goes a city, B goes b city and C goes c city. Wait until I say "Action"
Bus Divers: Okay.
(waiting...)
Boss : Action!
Bus Drivers: (go now at the same time) http://emanual.robotis.com/docs/en/dxl/protocol1/#reg-write
2. Sync Write - keeping instruction, waiting until the packet finished
Boss : I am going to give you destinations. Everyone has to wait for I finish this announcement. As soon as I finish this statement, go yours immediately. A driver goes a, B driver goes b and C driver goes c. Let's go!
Drivers : (go now at the same time) http://emanual.robotis.com/docs/en/dxl/protocol1/#sync-write
Let's Try!
In this post, we are going to use "Sync Write". Because it is more intuitive in my opinion.
I changed some code for AX12. The original code was for MX series. I somehow don't understand why Robotis gives the example as Protocol_2.0 version. Anyway, if you read the code, you will understand it. Sync write only set the start address of the instruction table. You can write parameters from the starting address. It is somehow tricky but efficent. I think that is one of why the goal position address and the goal speed address is adjacent to each other.
Robotis Dynamixel is not a normal servo motor. In order to control them, we need to send proper packet through serial communication. This is a kind of barrier for the beginners to make a code because there is something to study. You will need to calculate a checksum byte, find instruction code in the manual and so on. But, don't worry, there is a well-made SDK which is given by Robotis. The only one problem is that the documentation is written by professional. So, I am going to share the way as detailed as possible. If you just follow a few steps, Dynamixel would say "hello world"
As the drawing, if you get ping Succeeded, then everything is ready to use. Let's move the AX12. In order to run AX12, we need to use read_write.py file. I just changed Com Port and Baud rate but there was some problem. The motor didn't react at all. I fount the problem in the instruction table. we need to change code like this
We also need to change here because AX12 returns only 2 Bytes.
Because the control table address was different. So, we need to change address.
Let's play with this code!
Conclusion
Personally, I hope there is more detailed information for the series. Robotis has a lot of Dynamixel series. I have to make a instruction table for AX12 in order to use every features of AX12. Next time, I will share you some more code for AX12.
If you want to make an awesome robot, If you want to know how awesome robot physically moves and what motors do they use, you are very welcome to here. You may know what servo motor is.
Today, I am going to talk about Robotis Dynamixel which is basically a servo motor but it is super smarter then other servo motors.
Motors - Rotational or Angular
Basically, there are two kind of motors. rotational and angular. A rotation motors are for just turning something like fan, wheel and blender. We just expect them to run. We only control speed or power. On the other hand, an angular motors are for operating a particular angle for specific purpose such as joints for robots, flap for airplane or so. servo is a kind of angular motor.
Servo Motors - Normal Servo or Smart
In order to use a normal servo motor, we only need to give them power and signal. Normally, we can control motor's angle by sending PWM signal to them. There are so many well made library and instruction for it. I used to use servo motors for making a simple robots. These are the robots.
Servo motors are originally used for RC planes or cars. That is why they called as RC servo motor.
Smart Servo Motors - Dynamixel
in order to make more complex robots such as humanoid robot which has a lot of joint, you better use a smart actuator. It has a lot of functions you may need. It saves time and effort. One of popular motor manufacturer among smart actuators field is Robotis. There are a lot of lineup from toy size to industrial size. Dynamixel is their product series name.
I have made a lot of robots by using Dynamixel. These are the robots.
Now, I am going to talk about why you will want to use Dynamixel rather than normal servo motors.
5 Reasons why you want to use Robotis Dynamixel
1. Cable
Normally, robot has a lot of motors in serial. Let's think about our body. From a body to a finger, some of them are linked each other. Robot is also linked one frame to another frames.If you use RC servo motors for joint robot, you will meet a problem with a lot of cables. Because RC servo motors have to be connected with a main controller which gives PWM signal to them. So, If you link 5 motors in serial way, motor lines are gathered. Sometimes it occurs problems.
One the other hand, Dynamixel can be connected with each other. in order to make them move, we only give them proper data packet though communication line. It is very similar to I2C communication. Every Dynamixel has programmable address. It reduces cables dramatically. All you have to do is to give each Dynamixel different address.
2. Hardware
In order to use a motor for your purpose, you will need to fix motors to frames firmly and securely. Normally RC servo has only 2 wholes on wings and it is enough for RC car and plane. But 2 wholes are not enough if you want to make a serial joint robot such as humanoid robot. Because the robot need to be lined each other. There will be Internal or external force to the frames. If they are not fixed securely, they are easily broken down. Dynamixel has a lot of holes which can bear nut for screws. It is very handy, useful and secure.
One more thing I want to talk about hardware is that it has one more fix point on the other side. Both RC servo and Dynamixel generates movement and deliver it through the final gear on the surface of it. If you fix your external frame with only this final gear, the robot is easily broken down because the final gear is only designed for rotational movement. If the external frame moves vertically against the axis, it breaks your motor or frame itself. There are two ways to solve this problem. To use a thrust bearing like a excavator or to fix using one more point. Robotis gives 2 solutions altogether, you can either use thrust bearing or use one more fixing point for it. Normal servo doesn't have backside hall but Dynamixel has it. This makes different.
3. Feedback from motor
This is one of the best feature of Dynamixel. RC servo is straightforward and easy to control but we can't read its status. We just can order them to move to specific angle. Sometimes we need to know about current angle, temperature or speed. Reading current angle dramatically helps me to record robot's pose. Let's imagine that we want to make a dog robot. In order to make the dog walk, we need to make some motion sets. With RC servo motors, we have no choice but to try to move each motors one by one and note output values for it. If there are 20 motors for legs, we need to try this work for every single motors. On the other hand, with Dynamixel, we can read current angle status in a very simple way. When the motor gets a reading-value-instruction, they return their status right away. In this way, we can capture every single motor's angle in very short time. All you have to do is just to save the values for your purpose.
4. Controller & SDK
When you want to use a RC servo motor, you must need to use a microcontroller such as an Arduino which can give PWM signal to a servo motor. It is somehow easy to control servos in short time. However, if you want to move the motors beautifully, you will need to calculate a complex math formula. And you will need more powerful computing processor, you will need to develop again.
On the other hand, you can control Dynamixel by using computer through USB device. Your PC can control the motors directly so you can apply this to your another project such as image processing or so. There are so many mini-size computer around the world in these days.
Robotis gives SDK and some example code for Linux, Windows and Mac users. I am going to make my project using Python on Windows by the way.
5. Consistancy
When I made a humanoid robot with RC servo, I got some serious problem with it. Sometimes some motor ran out because they are consumable parts. The problem is that every time I changed the motors, the default angle between old one and new one are way much different. I needed to adjust angle physically logically. This made me frustrated.
Robotis Dynamixel can adjust its default angle offset in logical way. We can send offset instruction with adjust angle value. Then, the motor moves like previous motor. By the way, I've never used this function because there are all same. Actually I didn't know the feature. I just replaced and done!
Conclusion
Dynamixel has a lot of features you may like. As a heavy robot maker, these are the best things that I can say confidently. If you want to make a simple robot with under 10 motors, you may use RC servo motors. If you want to make a joint robot with over 10 motors, I strongly recommend you to use Dynamixel. If you are a beginner, AX12A is the cheapest option. AX12A is a steady seller over 15 years. If you want to try, link is here. https://amzn.to/2Pa6FXk
Follow this instruction and make your own LED (Neopixel : WS2812B) light!
Welcome again. This tutorial gives you a simple way to make the beautiful light in few hours. All you need is just to download 3d cad file I shared and print them by using 3d printer. It is okay if you don't code. In this tutorial, we are going to use a ready-to-go LED controller and a remote controller.
Just in case you want to know, my wife designed this model by using TinkerCad and Fusion360. She made some blocks and cut some edges. Grouping them and exported the modeling files into Fusion360. Fusion360 has a function called "Shell" which is suit for this project. we need to put LED light into the model.