NimbRo ROS Soccer Package
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
CM740mp.h
1 // Hardware interface for the CM740 board with megapacket support
2 // File: CM730.cpp
3 // Authors: Philipp Allgeuer <pallgeuer@ais.uni-bonn.de>
4 // Sebastian Schueller <schuell1@cs.uni-bonn.de>
5 // Grzegorz Ficht <gficht@cs.uni-bonn.de>
6 // Comment: This file is suitable for CM730 firmware versions of 0x88 and above (NimbRo-OP specific with megapacket support).
7 
8 // Ensure header is included only once
9 #ifndef CM740MP_H
10 #define CM740MP_H
11 
12 // Includes
13 #include <cm730/CM730.h>
14 
15 using namespace cm730;
16 
17 // megapacket servo data struct
18 struct MPData
19 {
20  // Constructor
21  MPData() { std::memset(this, 0, sizeof(MPData)); length=12; f_writePosition = false; }
22 
23  // Megapacket read parameters
24  unsigned char length; // subpacket length
25  unsigned char id;
26  unsigned char type; // not received, only written at configuration
27  unsigned char status;
28  unsigned char health;
29  unsigned char healthPrevious; // not received, copied before receiving new health information.
30 
31  // flags
32  bool f_writePosition;
33 
34  // Received data
35  unsigned short position; // P_PRESENT_POSITION_*
36  unsigned short speed; // P_PRESENT_SPEED_*
37  unsigned short torque; // P_PRESENT_TORQUE_*
38  unsigned char voltage; // P_PRESENT_VOLTAGE_*
39  unsigned char temperature; // P_PRESENT_TEMPERATURE_*
40 
41  // Sent data
42  unsigned char torqueEnable; // 0/1 = torque off/on
43  unsigned char complianceSlope; // 1024/complianceSlope = P_GAIN = effort;
44  unsigned short positionGoal; // 4095 = max position -> 300deg
45  unsigned short speedGoal; // 0 = max speed
46  unsigned short torqueGoal; // 1023 = max torque
47 
48 };
49 
50 // megapacket board data struct
51 struct MPBoard
52 {
53  // Constructor
54  MPBoard() { std::memset(this, 0, sizeof(MPBoard)); length = 30;}
55 
56  // Megapacket read parameters
57  unsigned char length; // subpacket length
58  unsigned char id;
59  unsigned char status;
60  unsigned char health;
61  unsigned char healthPrevious;
62 
63  // Received data
64  unsigned char power; // P_DYNAMIXEL_POWER
65  unsigned char ledPanel; // P_LED_PANEL
66  unsigned short rgbled5; // P_RGBLED5_*
67  unsigned short rgbled6; // P_RGBLED6_*
68  unsigned char button; // P_BUTTON
69  unsigned char voltage; // P_BATTERY_VOLTAGE
70  signed short gyroX; // P_GYRO_X_*
71  signed short gyroY; // P_GYRO_Y_*
72  signed short gyroZ; // P_GYRO_Z_*
73  signed short accX; // P_ACC_X_*
74  signed short accY; // P_ACC_Y_*
75  signed short accZ; // P_ACC_Z_*
76  signed short magX; // P_MAG_X_*
77  signed short magY; // P_MAG_Y_*
78  signed short magZ; // P_MAG_Z_*
79 
80  // Sent data
81  unsigned char ledPanelCmd; // P_LED_PANEL
82  unsigned short rgbled5Cmd; // P_RGBLED5_*
83 
84 };
85 
86 //
87 // CM740 with megapacket support class
88 //
89 class CM740mp : public CM730
90 {
91 public:
92  CM740mp() : m_inMegapacketMode(false), m_isMegapacketConfigured(false), m_writeMegapacket(false) { } ;
93  int writeMegapacket(std::vector<MPData>& Servos, MPBoard& Board);
94  int receiveMegapacket(std::vector<MPData>& Servos, MPBoard& Board);
95  int configureMegapacket(std::vector<MPData>& Servos, MPBoard& Board);
96  void addMegapacketServo(std::vector<MPData>& Servos,unsigned char id, unsigned char type);
97  int parseBoardData(MPBoard& Board, unsigned char* data);
98  int parseServoData(MPData& Servo, unsigned char* data);
99  int enableMegapacket(bool enable);
100  int packetsReceived(unsigned char oldPackets, unsigned char currentPackets);
101  int txMegapacket(unsigned char* txp);
102  int rxMegapacket(unsigned char* txp); // this is a stub
103 private:
104  bool m_inMegapacketMode;
105  bool m_isMegapacketConfigured;
106  bool m_writeMegapacket;
107 };
108 
109 
110 #endif
111 // EOF