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
77REGISTER_MODULE_DEFAULTS (DunkerMotor)
88
99const 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