|It is true that with the code we have left now I see much more clearly where I can and I must control the torque (I guess between the lines (130-142)), but I still do not know exactly what loop or code to use ...|
I've been testing with the dxlSetRunningToruqeLimit (...), I mean, a Macro to set running torque limit for the servo. but I do not think it's what I need, I do not need to fix it from the beginning, I need to know if a limit is exceeded or not, and I think it should be better an if or a while, than when I saw that I exceeded the torque limit ( put by me), the robot stopped ...but I still have not quite hit ...
I don't really know what dxlSetRunningTorqueLimit is supposed to do. Since you seemed to have dismissed it anyway, I will too.
What I think you are saying is, while the servos are moving, if a specific torque value is reached, they should stop moving and do something else--maybe return to the rest position or something like that.
I think you need to check the torque every time a servo moves. It looks like dxlSetGoalPosition is the only way to move the servos, and this command is only found in lines 140, 190 and 196. After each of those lines, check the torque on the servo that just moved and if it is too great, handle the error.
I can't tell you how to code up the error handling because I don't really know what you want it to do. You need to design the logic of what you want it to do. You need to decide:
(1) What happens when torque hits max when going to initial positions (in go_to_position)
(2) What happens when torque hits max when moving to registered movements (in loop)
(3) What happens when torque hits max when returning to rest positions (in go_to_position)
It really is a design process, not merely slapping code into what you currently have. For instance, one set of options might be (1) would cause the servos to return to rest positions, but (3) would cause the whole program to simply terminate. [Note: (3) should not merely cause servos to return to rest because that's what's causing the error in the first place.] If this were the case, error handling for go_to_position would have to be outside the function, meaning go_to_position would have to return an error value.
If the error handling for (1) and (3) were the same, you could do the error handling inside the function. Depending on what the error handling entails, go_to_position may still need a return value.
Once you come up with a torque-limit error handling design, you will have a better idea of how to complete your implementation.
Why not start with adding a debug printout of each torque value after each movement? Simplify your test to 1 servo and 10 movements again just to make sure you can read torque values correctly. Once you can, try adding your error-handling design and see where you get.