How can I measure current in an operating Dynamixel?

Issue:
I want to measure the torque of each Dynamixel in operation. To do so, I realized that I need to measure the current, and currently, I am trying to measure the current for each Dynamixel.

Therefore, I installed the Dynamixel SDK on Ubuntu 22.04, modified an example, and created a code to measure the current using Python in VScode. However, the measured current values were extremely large, and I couldn’t figure out what these values meant despite considering various possibilities. Below, I have posted the code I wrote and the resulting measurements. These results are the current values measured during the movement from the second goal position to the third goal position.

If anyone knows what the numbers for “present current” mean or how to convert them, I would appreciate your help.

Unfortunately, due to a 32,000 character limit, the code will be posted in the next message.

link:

-----------------------------------------------------Result----------------------------------------------------
[ID:011] PresentCurrent:000 [ID:012] PresentCurrent:65532 [ID:013] PresentCurrent:65498 [ID:014] PresentCurrent:65508
[ID:011] PresentCurrent:000 [ID:012] PresentCurrent:65530 [ID:013] PresentCurrent:65492 [ID:014] PresentCurrent:65507
[ID:011] PresentCurrent:000 [ID:012] PresentCurrent:65532 [ID:013] PresentCurrent:65494 [ID:014] PresentCurrent:65506
[ID:011] PresentCurrent:000 [ID:012] PresentCurrent:65534 [ID:013] PresentCurrent:65489 [ID:014] PresentCurrent:65509
[ID:011] PresentCurrent:008 [ID:012] PresentCurrent:65534 [ID:013] PresentCurrent:65478 [ID:014] PresentCurrent:65530
[ID:011] PresentCurrent:002 [ID:012] PresentCurrent:001 [ID:013] PresentCurrent:65465 [ID:014] PresentCurrent:65526
[ID:011] PresentCurrent:006 [ID:012] PresentCurrent:000 [ID:013] PresentCurrent:65456 [ID:014] PresentCurrent:65529
[ID:011] PresentCurrent:011 [ID:012] PresentCurrent:000 [ID:013] PresentCurrent:65434 [ID:014] PresentCurrent:65533
[ID:011] PresentCurrent:65540 [ID:012] PresentCurrent:65537 [ID:013] PresentCurrent:65431 [ID:014] PresentCurrent:131070
[ID:011] PresentCurrent:131076 [ID:012] PresentCurrent:196608 [ID:013] PresentCurrent:65423 [ID:014] PresentCurrent:196605
[ID:011] PresentCurrent:262149 [ID:012] PresentCurrent:262146 [ID:013] PresentCurrent:4294967171 [ID:014] PresentCurrent:327676
[ID:011] PresentCurrent:393223 [ID:012] PresentCurrent:393216 [ID:013] PresentCurrent:4294967166 [ID:014] PresentCurrent:393210
[ID:011] PresentCurrent:524294 [ID:012] PresentCurrent:524288 [ID:013] PresentCurrent:4294901626 [ID:014] PresentCurrent:524284
[ID:011] PresentCurrent:655367 [ID:012] PresentCurrent:655360 [ID:013] PresentCurrent:4294836098 [ID:014] PresentCurrent:655355
[ID:011] PresentCurrent:786437 [ID:012] PresentCurrent:786432 [ID:013] PresentCurrent:4294705031 [ID:014] PresentCurrent:786429
[ID:011] PresentCurrent:851976 [ID:012] PresentCurrent:917504 [ID:013] PresentCurrent:4294508430 [ID:014] PresentCurrent:917496
[ID:011] PresentCurrent:983046 [ID:012] PresentCurrent:1048576 [ID:013] PresentCurrent:4294311821 [ID:014] PresentCurrent:1048573
[ID:011] PresentCurrent:1114119 [ID:012] PresentCurrent:1114112 [ID:013] PresentCurrent:4294115215 [ID:014] PresentCurrent:1179641
[ID:011] PresentCurrent:1245190 [ID:012] PresentCurrent:1245184 [ID:013] PresentCurrent:4293918611 [ID:014] PresentCurrent:1310713
[ID:011] PresentCurrent:1376262 [ID:012] PresentCurrent:1441791 [ID:013] PresentCurrent:4293722001 [ID:014] PresentCurrent:1441788
[ID:011] PresentCurrent:1507335 [ID:012] PresentCurrent:1507328 [ID:013] PresentCurrent:4293590932 [ID:014] PresentCurrent:1572862
[ID:011] PresentCurrent:1638404 [ID:012] PresentCurrent:1703934 [ID:013] PresentCurrent:4293394321 [ID:014] PresentCurrent:1638396
[ID:011] PresentCurrent:1769478 [ID:012] PresentCurrent:1703936 [ID:013] PresentCurrent:4293263248 [ID:014] PresentCurrent:1769467
[ID:011] PresentCurrent:1900551 [ID:012] PresentCurrent:1835008 [ID:013] PresentCurrent:4293132176 [ID:014] PresentCurrent:1900539
[ID:011] PresentCurrent:1966088 [ID:012] PresentCurrent:2031615 [ID:013] PresentCurrent:4293066640 [ID:014] PresentCurrent:2031610
[ID:011] PresentCurrent:2097160 [ID:012] PresentCurrent:2162687 [ID:013] PresentCurrent:4292935567 [ID:014] PresentCurrent:2162683
[ID:011] PresentCurrent:2228234 [ID:012] PresentCurrent:2293759 [ID:013] PresentCurrent:4292804495 [ID:014] PresentCurrent:2293756
[ID:011] PresentCurrent:2293770 [ID:012] PresentCurrent:2424828 [ID:013] PresentCurrent:4292673420 [ID:014] PresentCurrent:2424827
[ID:011] PresentCurrent:2424842 [ID:012] PresentCurrent:2555903 [ID:013] PresentCurrent:4292607885 [ID:014] PresentCurrent:2555900
[ID:011] PresentCurrent:2555913 [ID:012] PresentCurrent:2686973 [ID:013] PresentCurrent:4292476825 [ID:014] PresentCurrent:2686970
[ID:011] PresentCurrent:2686989 [ID:012] PresentCurrent:2752512 [ID:013] PresentCurrent:4292345747 [ID:014] PresentCurrent:2752509
[ID:011] PresentCurrent:2818059 [ID:012] PresentCurrent:2949116 [ID:013] PresentCurrent:4292214668 [ID:014] PresentCurrent:2883582
[ID:011] PresentCurrent:2949129 [ID:012] PresentCurrent:3014651 [ID:013] PresentCurrent:4292083602 [ID:014] PresentCurrent:3014649
[ID:011] PresentCurrent:3080203 [ID:012] PresentCurrent:3145724 [ID:013] PresentCurrent:4291952527 [ID:014] PresentCurrent:3145720
[ID:011] PresentCurrent:3211276 [ID:012] PresentCurrent:3276796 [ID:013] PresentCurrent:4291821461 [ID:014] PresentCurrent:3276797
[ID:011] PresentCurrent:3342342 [ID:012] PresentCurrent:3407866 [ID:013] PresentCurrent:4291690388 [ID:014] PresentCurrent:3407871
[ID:011] PresentCurrent:3473411 [ID:012] PresentCurrent:3538939 [ID:013] PresentCurrent:4291559314 [ID:014] PresentCurrent:3538939
[ID:011] PresentCurrent:3538945 [ID:012] PresentCurrent:3670010 [ID:013] PresentCurrent:4291428242 [ID:014] PresentCurrent:3604477
[ID:011] PresentCurrent:3604481 [ID:012] PresentCurrent:3801078 [ID:013] PresentCurrent:4291297174 [ID:014] PresentCurrent:3735548
[ID:011] PresentCurrent:3735553 [ID:012] PresentCurrent:3932147 [ID:013] PresentCurrent:4291166102 [ID:014] PresentCurrent:3866616
[ID:011] PresentCurrent:3735552 [ID:012] PresentCurrent:4063219 [ID:013] PresentCurrent:4291100560 [ID:014] PresentCurrent:3932160
[ID:011] PresentCurrent:3735552 [ID:012] PresentCurrent:4194292 [ID:013] PresentCurrent:4290969486 [ID:014] PresentCurrent:4063232
[ID:011] PresentCurrent:3735552 [ID:012] PresentCurrent:4325361 [ID:013] PresentCurrent:4290838419 [ID:014] PresentCurrent:4259839
[ID:011] PresentCurrent:3670016 [ID:012] PresentCurrent:4456435 [ID:013] PresentCurrent:4290707353 [ID:014] PresentCurrent:4390907
[ID:011] PresentCurrent:3604480 [ID:012] PresentCurrent:4587508 [ID:013] PresentCurrent:4290576279 [ID:014] PresentCurrent:4456436
[ID:011] PresentCurrent:3538944 [ID:012] PresentCurrent:4718581 [ID:013] PresentCurrent:4290445208 [ID:014] PresentCurrent:4587518
[ID:011] PresentCurrent:3538943 [ID:012] PresentCurrent:4784111 [ID:013] PresentCurrent:4290314133 [ID:014] PresentCurrent:4653050
[ID:011] PresentCurrent:3342336 [ID:012] PresentCurrent:4915185 [ID:013] PresentCurrent:4290248594 [ID:014] PresentCurrent:4653050
[ID:011] PresentCurrent:3211264 [ID:012] PresentCurrent:5046253 [ID:013] PresentCurrent:4290117522 [ID:014] PresentCurrent:4653050
[ID:011] PresentCurrent:3080192 [ID:012] PresentCurrent:5177325 [ID:013] PresentCurrent:4289986456 [ID:014] PresentCurrent:4653049
[ID:011] PresentCurrent:2949120 [ID:012] PresentCurrent:5308395 [ID:013] PresentCurrent:4289855388 [ID:014] PresentCurrent:4587513
[ID:011] PresentCurrent:2883584 [ID:012] PresentCurrent:5439465 [ID:013] PresentCurrent:4289724312 [ID:014] PresentCurrent:4521977
[ID:011] PresentCurrent:2752512 [ID:012] PresentCurrent:5570540 [ID:013] PresentCurrent:4289593233 [ID:014] PresentCurrent:4456434
[ID:011] PresentCurrent:2621440 [ID:012] PresentCurrent:5701605 [ID:013] PresentCurrent:4289462159 [ID:014] PresentCurrent:4390903
[ID:011] PresentCurrent:2555903 [ID:012] PresentCurrent:5832674 [ID:013] PresentCurrent:4289331097 [ID:014] PresentCurrent:4259833
[ID:011] PresentCurrent:2359296 [ID:012] PresentCurrent:5963748 [ID:013] PresentCurrent:4289200035 [ID:014] PresentCurrent:4194300
[ID:011] PresentCurrent:2293759 [ID:012] PresentCurrent:6094819 [ID:013] PresentCurrent:4289068960 [ID:014] PresentCurrent:4063226
[ID:011] PresentCurrent:2097152 [ID:012] PresentCurrent:6160351 [ID:013] PresentCurrent:4288937880 [ID:014] PresentCurrent:3932153
[ID:011] PresentCurrent:2031616 [ID:012] PresentCurrent:6291419 [ID:013] PresentCurrent:4288872346 [ID:014] PresentCurrent:3801073
[ID:011] PresentCurrent:1900544 [ID:012] PresentCurrent:6422489 [ID:013] PresentCurrent:4288741283 [ID:014] PresentCurrent:3735548
[ID:011] PresentCurrent:1835006 [ID:012] PresentCurrent:6488028 [ID:013] PresentCurrent:4288675753 [ID:014] PresentCurrent:3604473
[ID:011] PresentCurrent:1638400 [ID:012] PresentCurrent:6488022 [ID:013] PresentCurrent:4288610210 [ID:014] PresentCurrent:3473405
[ID:011] PresentCurrent:1507328 [ID:012] PresentCurrent:6553556 [ID:013] PresentCurrent:4288610204 [ID:014] PresentCurrent:3342328
[ID:015] PresentCurrent:65534
[ID:015] PresentCurrent:65535
[ID:015] PresentCurrent:000
[ID:015] PresentCurrent:000
[ID:015] PresentCurrent:006
[ID:015] PresentCurrent:004
[ID:015] PresentCurrent:008
[ID:015] PresentCurrent:65544
[ID:015] PresentCurrent:65543
[ID:015] PresentCurrent:131083
[ID:015] PresentCurrent:196622
[ID:015] PresentCurrent:327695
[ID:015] PresentCurrent:393233
[ID:015] PresentCurrent:524302
[ID:015] PresentCurrent:720912
[ID:015] PresentCurrent:851980
[ID:015] PresentCurrent:983054
[ID:015] PresentCurrent:1179662
[ID:015] PresentCurrent:1310731
[ID:015] PresentCurrent:1441802
[ID:015] PresentCurrent:1572877
[ID:015] PresentCurrent:1703947
[ID:015] PresentCurrent:1835021
[ID:015] PresentCurrent:1900559
[ID:015] PresentCurrent:2031629
[ID:015] PresentCurrent:2162699
[ID:015] PresentCurrent:2293772
[ID:015] PresentCurrent:2359311
[ID:015] PresentCurrent:2490377
[ID:015] PresentCurrent:2621454
[ID:015] PresentCurrent:2752523
[ID:015] PresentCurrent:2883591
[ID:015] PresentCurrent:3014671
[ID:015] PresentCurrent:3145739
[ID:015] PresentCurrent:3276811
[ID:015] PresentCurrent:3342345
[ID:015] PresentCurrent:3473418
[ID:015] PresentCurrent:3604489
[ID:015] PresentCurrent:3735566
[ID:015] PresentCurrent:3866635
[ID:015] PresentCurrent:3997707
[ID:015] PresentCurrent:4128780
[ID:015] PresentCurrent:4259852
[ID:015] PresentCurrent:4325391
[ID:015] PresentCurrent:4456458
[ID:015] PresentCurrent:4587533
[ID:015] PresentCurrent:4718604
[ID:015] PresentCurrent:4849680
[ID:015] PresentCurrent:4980751
[ID:015] PresentCurrent:5111820
[ID:015] PresentCurrent:5177357
[ID:015] PresentCurrent:5308429
[ID:015] PresentCurrent:5439501
[ID:015] PresentCurrent:5570574
[ID:015] PresentCurrent:5701645
[ID:015] PresentCurrent:5832714
[ID:015] PresentCurrent:5963786
[ID:015] PresentCurrent:6029325
[ID:015] PresentCurrent:6160396
[ID:015] PresentCurrent:6225932
[ID:015] PresentCurrent:6291465
[ID:015] PresentCurrent:6357001
[ID:015] PresentCurrent:6422539
[ID:015] PresentCurrent:6422540
[ID:015] PresentCurrent:6422536
[ID:015] PresentCurrent:6488072
[ID:015] PresentCurrent:6488073
[ID:015] PresentCurrent:6488073
[ID:015] PresentCurrent:6488074
[ID:015] PresentCurrent:6488072
[ID:015] PresentCurrent:6488074
[ID:015] PresentCurrent:6488075
[ID:015] PresentCurrent:6488074
[ID:015] PresentCurrent:6488072
[ID:015] PresentCurrent:6488071
[ID:015] PresentCurrent:6488072
[ID:015] PresentCurrent:6488075
[ID:015] PresentCurrent:6488073
[ID:015] PresentCurrent:6488076
[ID:015] PresentCurrent:6488076
[ID:015] PresentCurrent:6488073
[ID:015] PresentCurrent:6488070
[ID:015] PresentCurrent:6488076
[ID:015] PresentCurrent:6488071
[ID:015] PresentCurrent:6488068
[ID:015] PresentCurrent:6488070
[ID:015] PresentCurrent:6488069
[ID:015] PresentCurrent:6422535
[ID:015] PresentCurrent:6356998
[ID:015] PresentCurrent:6291462
[ID:015] PresentCurrent:6225927
[ID:015] PresentCurrent:6094854
[ID:015] PresentCurrent:6029317
[ID:015] PresentCurrent:5898242
[ID:015] PresentCurrent:5832710
[ID:015] PresentCurrent:5701635
[ID:015] PresentCurrent:5570561
[ID:015] PresentCurrent:5439492
[ID:015] PresentCurrent:5373953
[ID:015] PresentCurrent:5242883
[ID:015] PresentCurrent:5111811
[ID:015] PresentCurrent:4980736
[ID:015] PresentCurrent:4849667
[ID:015] PresentCurrent:4718597
[ID:015] PresentCurrent:4653062
[ID:015] PresentCurrent:4521988
[ID:015] PresentCurrent:4390914
[ID:015] PresentCurrent:4259843
[ID:015] PresentCurrent:4128771
[ID:015] PresentCurrent:3997696
[ID:015] PresentCurrent:3866628
[ID:015] PresentCurrent:3801093
[ID:015] PresentCurrent:3670016
[ID:015] PresentCurrent:3538947
[ID:015] PresentCurrent:3407872
[ID:015] PresentCurrent:3276802
[ID:015] PresentCurrent:3145728
[ID:015] PresentCurrent:3014657
[ID:015] PresentCurrent:2883587
[ID:015] PresentCurrent:2752515
[ID:015] PresentCurrent:2686977
[ID:015] PresentCurrent:2555904
[ID:015] PresentCurrent:2424832
[ID:015] PresentCurrent:2293761
[ID:015] PresentCurrent:2162689
[ID:015] PresentCurrent:2031618
[ID:015] PresentCurrent:1900545
[ID:015] PresentCurrent:1769472
[ID:015] PresentCurrent:1638400
[ID:015] PresentCurrent:1507328
[ID:015] PresentCurrent:1376257


DYNAMIXEL Servo:

XM430-W350-T 5EA (Openmanipulator X set)


DYNAMIXEL Controller: OpenCR 1.0


Software Interface: Python in VScode, Dynamixel_SDK, Ubuntu 22.04

I think that this person had a similar issue as you when he was using PWM, it seemed to do with how Python handles 2-complement 2-bytes integers. He had to setup special data types in Python.

May be you can ask him for more details.

The online ROBOTIS eManual has information on the increment value for current measurement.

I understood the concept of complement from the respective post. However, when “present position” is displayed, it is output in the same format as the number inputted when setting the “goal position” without the need for understanding the concept of compensation. Why, then, is this concept applied and displayed when “present current” is output?

Excellent question! According to the Control Table of XM-430s at

When you use the XM-430 in Standard Position Control mode, the Goal Position is a POSITIVE integer between 0 and 4095, so same data type for the Present Position. But you can read from the e-manual that when this DXL is in the Extended Position Control Mode or Current-based Position Control Mode, the ranges of Goal Position values are very different.

image

Which mode are you using for your XM-430?


As CURRENT can go one way or the other, ROBOTIS sets up Parameter “Present Current” to represent a signed 16-bit integer.

According to the XM430-W350 Control Table, at run-time, you can use DXL SDK to read in Present Current (PC126) at Address 126

This PC126 number is supposed to be a signed 16-bit integer between (- Goal_Current) and (+Goal_Current), to be found at Address 102. By default, this range is between (-1193) and (+1193) – in decimal, and its unit value is 2.69 mA. In ROBOTIS software, negative integers use the 2-complement binary format for a 16-bit integer, however Python/C++ does not know that, so it would just print out the 2-complement integer as is, i.e. an integer between 0 and 65535. So, in your Python/C++ code, you need to do some checking before actually using PC126 “as received”:

// Assuming 16-bit 2-complement integers

if (PC126 > 32767) // NEGATIVE VALUES

PC126 = (65536 – PC126) * (-1)

else // POSITIVE VALUES

PC126 = PC126

Basically you need to distinguish between signed integers as received via Communications means (pretty much as is in binary) versus integer variables as defined by Python internally (i.e. plus/minus decimal as we humans like them!).

Now, I also saw that you got VERY BIG Integers at times in your output, way bigger than a 16-bit integer can represent! So I am not sure what is going there, data corruption of some sort? Are you using Bluetooth or wired communication to your DXLs? Python SDK issue?

I use C/C++ mostly, so I know how to control the Data Type to a specific number of bits and I usually don’t get this issue. Because Python is a Dynamic language, and I do not know enough about Python Internals to say anything about this aspect.

Personally, I see 3 possible options:

  1. Ignore any integer received for PC126 that is larger than 65535?
  2. Do a Bit-Wise AND operation between PC126 as received and 0xFFFF before converting it to “regular” signed decimal as shown in the previous pseudo code?
  3. Can you use Dynamixel Wizard 2 to check out this issue with Present Current? I got a hunch that you are not going to find the same issue.

Thank you for your response!
After receiving your answers and reviewing the E-manual, I found a hint: “Position I Gain(82) KPI = KPI(TBL) / 65,536.” By gradually operating the Dynamixel and checking the Present Current in the Dynamixel Wizard, I obtained the following result:

“When rotating in the + direction, the value increases from 0 in hexadecimal, but when rotating in the - direction, it doesn’t become negative. Instead, it decreases by 1 from 0 to become ‘0xFFFF = 65535’ and then starts decreasing from 65535.”

Because of this, a large value like “[ID:013] PresentCurrent:4289724312” appeared.
Based on this new information, calculating 4289724312 gives us: 0.00269[mA] * (4289724312/65535 - 65535) = -0.209828[A].

Thank you all for your help.

Very different from C/C++. I still can’t figure out where 4289724312 came from and how it represents -1?

Your integer division by 65535 is equivalent to a shift-right by 16 bits! So are you saying that on your Ubuntu box the 2 bytes received from the DXL got shifted 16 bits to the left by Python somehow? Or that the DXL sent over 4 bytes instead of 2 bytes as it is supposed to?

Thanks for sharing!

The Dynamixel X series represents negative value as 2’s Complement.
image

The present current is assigned as 2 bytes, please refer to ‘Size field’ in the Control table.

In case of 2 byte signed-integer variable with 2’s Complement, ‘-1’ is 0xFFFF, and ‘-2’ is 0xFFFE. On the other hand, for unsigned variable, 0xFFFF is 65535.

For 4 byte signed-integer variable, ‘-1’ is 0xFFFF FFFF, and ‘-2’ is 0xFFFF FFFE. Similarly, for unsigned-integer variable, 0xFFFF FFFF is 4,294,967,295.

It would be good to refer to the types of variables, type casting and 2’s Complement.

Two’s complement - Wikipedia

The binary world can be a little bit complicated

The value(4,289,724,312) is 0xFFAF FF98 in hexadecimal.
Because the present current is 2 byte, so it would be 0xFFAF or 0xFF98.
If 2’s complement is applied to the above values, 0xFFAF is '-81 and 0xFF98 is ‘-104’.