Skip to content

Commit a68b5bb

Browse files
allow reading voltages from dunker motors (#140)
1 parent cbd9a65 commit a68b5bb

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

docs/module_reference.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -698,11 +698,15 @@ This module controls [dunkermotoren](https://www.dunkermotoren.de/) motor via CA
698698
| ----------------------------------- | ------------------------------- | ----------------- |
699699
| `motor = DunkerMotor(can, node_id)` | CAN module and node ID (1..127) | CAN module, `int` |
700700

701-
| Properties | Description | Data type |
702-
| ------------------ | ------------------------------- | --------- |
703-
| `motor.speed` | Motor speed (meters per second) | `float` |
704-
| `motor.m_per_turn` | Meters per turn | `float` |
705-
| `motor.reversed` | Reverse motor direction | `bool` |
701+
| Properties | Description | Data type |
702+
| --------------------- | ------------------------------- | --------- |
703+
| `motor.speed` | Motor speed (meters per second) | `float` |
704+
| `motor.voltage_logic` | Voltage logic (V) | `float` |
705+
| `motor.voltage_power` | Voltage power (V) | `float` |
706+
| `motor.m_per_turn` | Meters per turn | `float` |
707+
| `motor.reversed` | Reverse motor direction | `bool` |
708+
709+
Note: To reduce bandwidth, voltages are only queried when explicitly requested by calling `update_voltages()`.
706710

707711
| Methods | Description | Arguments |
708712
| ----------------------------------------------- | ----------------------------- | --------- |
@@ -711,6 +715,7 @@ This module controls [dunkermotoren](https://www.dunkermotoren.de/) motor via CA
711715
| `motor.disable()` | Disable motor | |
712716
| `motor.sdo_read(index[, subindex])` | Read SDO | 2x `int` |
713717
| `motor.sdo_write(index, subindex, bits, value)` | Write SDO | 4x `int` |
718+
| `motor.update_voltages()` | Update voltages | |
714719

715720
## DunkerWheels
716721

main/modules/dunker_motor.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
#include "dunker_motor.h"
22
#include "canopen.h"
3-
#include "uart.h"
43
#include "utils/timing.h"
4+
#include "utils/uart.h"
55
#include <cinttypes>
66

77
REGISTER_MODULE_DEFAULTS(DunkerMotor)
88

99
const std::map<std::string, Variable_ptr> DunkerMotor::get_defaults() {
1010
return {
1111
{"speed", std::make_shared<NumberVariable>()},
12+
{"voltage_logic", std::make_shared<NumberVariable>()},
13+
{"voltage_power", std::make_shared<NumberVariable>()},
1214
{"m_per_turn", std::make_shared<NumberVariable>(1.0)},
1315
{"reversed", std::make_shared<BooleanVariable>()},
1416
};
@@ -115,6 +117,10 @@ void DunkerMotor::call(const std::string method_name, const std::vector<ConstExp
115117
} else if (method_name == "speed") {
116118
Module::expect(arguments, 1, numbery);
117119
this->speed(arguments[0]->evaluate_number());
120+
} else if (method_name == "update_voltages") {
121+
Module::expect(arguments, 0);
122+
this->sdo_read(0x4110, 1);
123+
this->sdo_read(0x4111, 1);
118124
} else {
119125
Module::call(method_name, arguments);
120126
}
@@ -126,6 +132,12 @@ void DunkerMotor::handle_can_msg(const uint32_t id, const int count, const uint8
126132
}
127133
if (id == 0x580 + this->node_id) {
128134
this->waiting_sdo_writes--;
135+
if (data[0] == 0x43 && data[1] == 0x10 && data[2] == 0x41 && data[3] == 0x01) {
136+
this->properties["voltage_logic"]->number_value = ((data[5] << 8) | data[4]) / 1000.0;
137+
}
138+
if (data[0] == 0x43 && data[1] == 0x11 && data[2] == 0x41 && data[3] == 0x01) {
139+
this->properties["voltage_power"]->number_value = ((data[5] << 8) | data[4]) / 1000.0;
140+
}
129141
}
130142
if (id == 0x180 + this->node_id) {
131143
const int32_t motor_speed = demarshal_i32(data);

0 commit comments

Comments
 (0)