How to control multi AX-12A servo motors by using Dynamixel shield

That code was for my own board so that it has a different DXL_DIR_PIN than yours, I am sure. Which controller are you using? You can try this free Kindle sample to learn more about Arduino and ROBOTIS hardware:

https://www.amazon.com/Using-ARDUINO-ROBOTIS-Systems-Ngoc-ebook/dp/B0BPXGQ6YX

Right now, the DXLs Goal Positions are defined by the array goal_position[2] = {450, 550}; . Whereas, goal_position[0] is the first and common GP of both DXLs (=450) and goal_position[1] is the second and common GP of both DXLs (=550). So you will have to “rethink” the design of this goal_position array, and to make goal_position[0] points to DXL 1 only and goal_position[1] points to DXL 2 only, etc…

See the following post, where I used a different kind of Sync Read Write packet (deprecated by ROBOTIS, but I like it better) where every time that Function loop() iterates, it chooses a random GP value for each DXL.

goal_position[i] = (uint16_t) random(0,1023); // when applied to your set up with AX12s

You should be able to modify that approach for your needs.