Tool Libs
UMIT-TIROL Institute of Automation and Control Engineering library collection
 
Loading...
Searching...
No Matches
mcDSA.h
Go to the documentation of this file.
1
5#pragma once
6
7#include <cmath>
8#include <comm/canopen.h>
9
14 CAN::Open::RPDO speedPDO = {
15 .N = 1,
17 .map = {{.ix = 0x3300, .sub = 0, .len = 32}},
18 };
19 CAN::Open::TPDO msrPDO = {
20 .N = 1,
22 .map = {
23 {.ix = 0x3a04, .sub = 1, .len = 32}, // speed
24 {.ix = 0x3262, .sub = 1, .len = 32}, // current [mA]
25 },
26 };
27
28 mcDSA(CAN::Open::Dispatch &out, uint8_t id) : CAN::Open::Device(out, id) {
29 enable(false);
30 enablePDO(speedPDO);
31 enablePDO(msrPDO);
32 enable(true);
33 }
34 struct Measurements {
35 double speed, speedDes, current, position;
36 uint32_t error;
37 } meas;
38
40 void enable(bool en=true) {
41 w8(0x3004, 0, en);
42 }
43 void disable() {
44 enable(false);
45 }
46 void clear() {
47 w8(0x3000, 0, 1); // clear errors
48 }
49
50 //TODO:
55 void speed(double speed) {
56 speed = fmin(1, fmax(-1, speed));
57 /* int iSpeed = (int) (6000 / M_PI / CAR_WHEEL_DIAMETER * dSpeed); // calculates from m/s to (U/100) / min */
58 /* int iSpeed; */
59 speedPDO.map[0].data = 6000 / M_PI * speed;
60 wPDO(speedPDO);
61 }
62 double speed() {
63 return msrPDO.map[0].data;
64 }
65
72 void readData() {
73 read(0x3a04, 1);//, &this->tData.tSpeed);
74 read(0x3361, 0);//, &this->tData.tSpeedDes);
75 read(0x3262, 1);//, &this->tData.tCurrent);
76 read(0x394a, 0);//, &this->tData.tPosition);
77 read(0x3001, 0);//, &this->tData.tError);
78 }
79
83 double current() {
84 return msrPDO.map[1].data;
85 }
86
88 switch(rq.ix) {
89 case 0x3a04: assert(rq.sub == 1); meas.speed = rq.data; break;
90 case 0x3361: assert(rq.sub == 0); meas.speedDes = rq.data; break;
91 case 0x3262: assert(rq.sub == 1); meas.current = rq.data; break;
92 case 0x394a: assert(rq.sub == 0); meas.position = rq.data; break;
93 case 0x3001: assert(rq.sub == 0); meas.error = rq.data; break;
94 }
95 }
97 }
98};
@ SYNC
synchronous == on every NMT SYNC message
Definition canopen.h:62
@ CHANGE
change == ASAP on change of parameters
Definition canopen.h:64
CANOpen device wrapper class.
Definition canopen.h:232
void read(uint16_t ix, uint8_t sub)
read DO with given index and subindex of this device
Definition canopen.h:251
void wPDO(const RPDO &rpdo)
send PDO
Definition canopen.h:267
void w8(uint16_t ix, uint8_t sub, uint8_t val)
write given value to DO at given index and subindex
Definition canopen.h:255
void enablePDO(RPDO &pdo)
enable receiving PDO on device
Definition canopen.h:271
CANOpen dispatch class.
Definition canopen.h:108
CANOpen Receive Process Data Object Type.
Definition canopen.h:67
uint8_t N
Index of PDO [1 .. x].
Definition canopen.h:68
Buffer< PDOMap > map
PDO Data Map.
Definition canopen.h:71
CANOpen Service Data Object xfer request.
Definition canopen.h:29
uint16_t ix
index of DO
Definition canopen.h:31
uint8_t sub
subindex of DO
Definition canopen.h:32
uint32_t data
up to 4 bytes of data
Definition canopen.h:30
CANOpen Transmit Process Data Object Type.
Definition canopen.h:83
uint8_t N
Index of PDO [1 .. x].
Definition canopen.h:84
Buffer< PDOMap > map
PDO Data Map.
Definition canopen.h:88
Driver for the mcDSA-B60 CANOpen Motor driver.
Definition mcDSA.h:13
void speed(double speed)
Set the motor speed in u/min.
Definition mcDSA.h:55
void readData()
Read current motor data.
Definition mcDSA.h:72
double current()
Return the current motor current in mA.
Definition mcDSA.h:83
void enable(bool en=true)
Enable or Disable the motor driver.
Definition mcDSA.h:40
void callback(CAN::Open::SDO rq)
implement the callback method to handle incoming data
Definition mcDSA.h:87
void callback(CAN::Open::TPDO rq)
implement the callback method to handle incoming data
Definition mcDSA.h:96