DaMiaoMotor¶
damiao_motor.motor.DaMiaoMotor ¶
Lightweight DaMiao motor wrapper over a CAN bus.
Source code in damiao_motor/motor.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 | |
clear_error ¶
encode_clear_error_msg
staticmethod
¶
encode_cmd_msg ¶
Encode a command to CAN frame for sending to the motor. Uses this motor's P/V/T limits (from motor_type preset) and fixed kp (KP_MIN/KP_MAX), kd (KD_MIN/KD_MAX).
Source code in damiao_motor/motor.py
encode_save_position_zero_msg
staticmethod
¶
ensure_control_mode ¶
Ensure control mode (register 10) matches the desired mode. Reads register 10; if it differs, writes and verifies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
control_mode |
str
|
"MIT", "POS_VEL", "VEL", or "FORCE_POS" |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If control_mode is invalid or register value is invalid |
TimeoutError
|
If reading/writing register times out |
RuntimeError
|
Other errors during register operations, or if verification after write fails |
Source code in damiao_motor/motor.py
get_register ¶
Read a register value from the motor.
If the value is not already cached, sends a read request and waits for the controller's background polling to receive the reply. The motor never reads from the bus; only the controller's poll_feedback does, avoiding multiple consumers.
Requires the motor to be managed by a DaMiaoController (added via controller.add_motor). Standalone motors can only return cached values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rid |
int
|
Register ID (0-81) |
required |
timeout |
float
|
Timeout in seconds to wait for response |
1.0
|
Returns:
| Type | Description |
|---|---|
float | int
|
Register value as float or int depending on register data type |
Raises:
| Type | Description |
|---|---|
KeyError
|
If register ID is not in the register table |
RuntimeError
|
If the motor is not managed by a controller (no background polling) |
TimeoutError
|
If the register reply was not received within timeout |
Source code in damiao_motor/motor.py
get_register_info ¶
Get information about a register.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rid |
int
|
Register ID |
required |
Returns:
| Type | Description |
|---|---|
RegisterInfo
|
RegisterInfo object with register details |
Raises:
| Type | Description |
|---|---|
KeyError
|
If register ID is not in the register table |
Source code in damiao_motor/motor.py
get_states ¶
Get the current motor state dictionary.
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dictionary containing current motor state information: |
Dict[str, Any]
|
|
Dict[str, Any]
|
|
Dict[str, Any]
|
|
Dict[str, Any]
|
|
Dict[str, Any]
|
|
Dict[str, Any]
|
|
Dict[str, Any]
|
|
Dict[str, Any]
|
|
Dict[str, Any]
|
|
Source code in damiao_motor/motor.py
read_all_registers ¶
Read all registers from the motor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout |
float
|
Timeout in seconds per register read |
0.05
|
Returns:
| Type | Description |
|---|---|
Dict[int, float | int]
|
Dictionary mapping register ID to value |
Source code in damiao_motor/motor.py
request_motor_feedback ¶
Request motor feedback/status information. After successful transmission, the motor driver will return current status information.
Source code in damiao_motor/motor.py
request_register_reading ¶
Request a register reading from the motor.
send_cmd ¶
send_cmd(target_position: float = 0.0, target_velocity: float = 0.0, stiffness: float = 0.0, damping: float = 0.0, feedforward_torque: float = 0.0, control_mode: str = 'MIT', velocity_limit: float = 0.0, current_limit: float = 0.0) -> None
Send command to motor with specified control mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_position |
float
|
Desired position (radians) |
0.0
|
target_velocity |
float
|
Desired velocity (rad/s) |
0.0
|
stiffness |
float
|
Stiffness (kp) for MIT mode |
0.0
|
damping |
float
|
Damping (kd) for MIT mode |
0.0
|
feedforward_torque |
float
|
Feedforward torque for MIT mode |
0.0
|
control_mode |
str
|
Control mode - "MIT" (default), "POS_VEL", "VEL", or "FORCE_POS" |
'MIT'
|
velocity_limit |
float
|
Velocity limit (rad/s, 0-100) for FORCE_POS mode |
0.0
|
current_limit |
float
|
Current limit normalized (0.0-1.0) for FORCE_POS mode |
0.0
|
Note
Before using this method to send commands, ensure that the motor's control mode register (register 10) is set to match the desired control_mode argument ("MIT", "POS_VEL", "VEL", or "FORCE_POS"). If the register does not match, the motor will not respond to commands and will not move.
Source code in damiao_motor/motor.py
send_raw ¶
Send raw CAN message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data |
bytes
|
CAN message data bytes (must be 8 bytes) |
required |
arbitration_id |
int | None
|
CAN arbitration ID (defaults to motor_id if not specified) |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If data is not 8 bytes or arbitration_id is invalid |
OSError
|
If CAN bus error occurs (e.g., Error Code 105 - No buffer space) |
CanError
|
If CAN-specific error occurs |
AttributeError
|
If bus is not initialized |
Source code in damiao_motor/motor.py
set_acceleration ¶
set_can_baud_rate ¶
Set CAN baud rate using register 35 (can_br).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
baud_rate_code |
int
|
Baud rate code (0=125K, 1=200K, 2=250K, 3=500K, 4=1M) |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If baud_rate_code is not in valid range [0, 4] |
Source code in damiao_motor/motor.py
set_can_timeout ¶
Set CAN timeout alarm time (register 9).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout_ms |
int
|
Timeout in milliseconds |
required |
Note
Register 9 stores timeout in units of 50 microseconds: 1 register unit = 50 microseconds.
Conversion formula: register_value = timeout_ms × 20
Examples: - 1000 ms = 1,000,000 microseconds = 20,000 register units - 50 ms = 50,000 microseconds = 1,000 register units
Source code in damiao_motor/motor.py
set_control_mode ¶
set_current_loop_bandwidth ¶
set_current_loop_enhancement ¶
set_deceleration ¶
set_feedback_id ¶
set_gear_efficiency ¶
set_limits ¶
set_limits(*, p_min: Optional[float] = None, p_max: Optional[float] = None, v_min: Optional[float] = None, v_max: Optional[float] = None, t_min: Optional[float] = None, t_max: Optional[float] = None) -> None
Update only the specified P/V/T limits. Omitted keys are left unchanged. kp and kd are fixed (KP_MIN/KP_MAX, KD_MIN/KD_MAX).
Source code in damiao_motor/motor.py
set_maximum_speed ¶
set_motor_type ¶
Update motor type and P/V/T limits from a preset. Validates against MOTOR_TYPE_PRESETS.
Source code in damiao_motor/motor.py
set_over_current_protection ¶
set_over_temperature_protection ¶
set_overvoltage_protection ¶
set_p_limits ¶
set_position_loop_ki ¶
set_position_loop_kp ¶
set_position_mapping_range ¶
set_receive_id ¶
set_speed_loop_damping ¶
set_speed_loop_enhancement ¶
set_speed_loop_filter_bandwidth ¶
set_speed_loop_ki ¶
set_speed_loop_kp ¶
set_speed_mapping_range ¶
set_t_limits ¶
set_timeout_alarm ¶
Set timeout alarm time (register 9).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value |
int
|
Timeout value in register units (1 unit = 50 microseconds) |
required |
Note
This method writes the raw register value. For convenience, use set_can_timeout()
which accepts milliseconds and handles the conversion automatically.
Conversion: 1 register unit = 50 microseconds To convert from milliseconds: register_value = timeout_ms × 20
Source code in damiao_motor/motor.py
set_torque_coefficient ¶
set_torque_mapping_range ¶
set_under_voltage_protection ¶
set_v_limits ¶
set_zero_command ¶
Send zero command (pos=0, vel=0, torq=0, kp=0, kd=0).
set_zero_position ¶
store_parameters ¶
Store all parameters to flash memory. After successful write, all parameters will be written to the chip.
write_register ¶
Write a value to a register.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rid |
int
|
Register ID (0-81) |
required |
value |
float | int
|
Value to write (float or int) |
required |
Raises:
| Type | Description |
|---|---|
KeyError
|
If register ID is not in the register table |
ValueError
|
If register is read-only or value is out of range |