Skip to content
This repository was archived by the owner on Dec 1, 2020. It is now read-only.

Commit 9e3346a

Browse files
authored
Merge pull request #262 from project-march/feature/PM-325-ethercat-interface
Feature: ethercat interface
2 parents a380abc + c5d67a1 commit 9e3346a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1098
-1063
lines changed

march_hardware/CMakeLists.txt

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,19 @@ if(CATKIN_ENABLE_TESTING AND ENABLE_COVERAGE_TESTING)
3838
endif()
3939

4040
add_library(${PROJECT_NAME}
41+
include/${PROJECT_NAME}/EtherCAT/pdo_interface.h
42+
include/${PROJECT_NAME}/EtherCAT/pdo_types.h
43+
include/${PROJECT_NAME}/EtherCAT/sdo_interface.h
44+
include/${PROJECT_NAME}/EtherCAT/slave.h
4145
include/${PROJECT_NAME}/encoder/AbsoluteEncoder.h
4246
include/${PROJECT_NAME}/encoder/Encoder.h
4347
include/${PROJECT_NAME}/encoder/IncrementalEncoder.h
4448
include/${PROJECT_NAME}/error/error_type.h
4549
include/${PROJECT_NAME}/error/hardware_exception.h
4650
include/${PROJECT_NAME}/error/motion_error.h
47-
src/EtherCAT/EthercatIO.cpp
4851
src/EtherCAT/EthercatMaster.cpp
49-
src/EtherCAT/EthercatSDO.cpp
52+
src/EtherCAT/pdo_interface.cpp
53+
src/EtherCAT/sdo_interface.cpp
5054
src/HighVoltage.cpp
5155
src/IMotionCube.cpp
5256
src/IMotionCubeTargetState.cpp
@@ -110,13 +114,15 @@ if(CATKIN_ENABLE_TESTING)
110114
test/encoder/TestEncoder.cpp
111115
test/error/test_hardware_exception.cpp
112116
test/error/test_motion_error.cpp
113-
test/mocks/MockAbsoluteEncoder.cpp
114-
test/mocks/MockEncoder.cpp
115-
test/mocks/MockIMotionCube.cpp
116-
test/mocks/MockIncrementalEncoder.cpp
117-
test/mocks/MockJoint.cpp
118-
test/mocks/MockTemperatureGES.cpp
119-
test/mocks/MockTemperatureSensor.cpp
117+
test/mocks/MockAbsoluteEncoder.h
118+
test/mocks/MockEncoder.h
119+
test/mocks/MockIMotionCube.h
120+
test/mocks/MockIncrementalEncoder.h
121+
test/mocks/MockJoint.h
122+
test/mocks/MockPdoInterface.h
123+
test/mocks/MockSdoInterface.h
124+
test/mocks/MockSlave.h
125+
test/mocks/MockTemperatureGES.h
120126
)
121127
target_link_libraries(${PROJECT_NAME}_test ${catkin_LIBRARIES} ${PROJECT_NAME})
122128

march_hardware/include/march_hardware/EtherCAT/EthercatIO.h

Lines changed: 0 additions & 109 deletions
This file was deleted.

march_hardware/include/march_hardware/EtherCAT/EthercatSDO.h

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#ifndef MARCH_HARDWARE_PDO_INTERFACE_H
2+
#define MARCH_HARDWARE_PDO_INTERFACE_H
3+
#include "pdo_types.h"
4+
5+
#include <cstdint>
6+
#include <memory>
7+
#include <utility>
8+
9+
namespace march
10+
{
11+
/**
12+
* An interface to read and write Process Data Objects (PDOs).
13+
*/
14+
class PdoInterface
15+
{
16+
public:
17+
virtual void write8(uint16_t slave_index, uint8_t module_index, bit8 value) = 0;
18+
virtual void write16(uint16_t slave_index, uint8_t module_index, bit16 value) = 0;
19+
virtual void write32(uint16_t slave_index, uint8_t module_index, bit32 value) = 0;
20+
21+
virtual bit8 read8(uint16_t slave_index, uint8_t module_index) const = 0;
22+
virtual bit16 read16(uint16_t slave_index, uint8_t module_index) const = 0;
23+
virtual bit32 read32(uint16_t slave_index, uint8_t module_index) const = 0;
24+
};
25+
26+
/**
27+
* Shared pointer to an PdoInterface.
28+
*/
29+
using PdoInterfacePtr = std::shared_ptr<PdoInterface>;
30+
31+
/**
32+
* An interface to read and write Process Data Objects (PDOs) for a given slave.
33+
*/
34+
class PdoSlaveInterface
35+
{
36+
public:
37+
PdoSlaveInterface(uint16_t slave_index, PdoInterfacePtr pdo) : slave_index_(slave_index), pdo_(pdo)
38+
{
39+
}
40+
41+
virtual ~PdoSlaveInterface() noexcept = default;
42+
43+
void write8(uint8_t module_index, bit8 value)
44+
{
45+
this->pdo_->write8(this->slave_index_, module_index, value);
46+
}
47+
void write16(uint8_t module_index, bit16 value)
48+
{
49+
this->pdo_->write16(this->slave_index_, module_index, value);
50+
}
51+
void write32(uint8_t module_index, bit32 value)
52+
{
53+
this->pdo_->write32(this->slave_index_, module_index, value);
54+
}
55+
56+
bit8 read8(uint8_t module_index) const
57+
{
58+
return this->pdo_->read8(this->slave_index_, module_index);
59+
}
60+
bit16 read16(uint8_t module_index) const
61+
{
62+
return this->pdo_->read16(this->slave_index_, module_index);
63+
}
64+
bit32 read32(uint8_t module_index) const
65+
{
66+
return this->pdo_->read32(this->slave_index_, module_index);
67+
}
68+
69+
private:
70+
const uint16_t slave_index_;
71+
PdoInterfacePtr pdo_;
72+
};
73+
74+
/**
75+
* An implementation of the PdoInterface using SOEM.
76+
*/
77+
class PdoInterfaceImpl : public PdoInterface
78+
{
79+
public:
80+
/**
81+
* Creates a new shared PdoInterfaceImpl.
82+
* @return Generic PdoInterface shared ptr
83+
*/
84+
static PdoInterfacePtr create()
85+
{
86+
return std::make_shared<PdoInterfaceImpl>();
87+
}
88+
89+
void write8(uint16_t slave_index, uint8_t module_index, bit8 value) override;
90+
void write16(uint16_t slave_index, uint8_t module_index, bit16 value) override;
91+
void write32(uint16_t slave_index, uint8_t module_index, bit32 value) override;
92+
93+
bit8 read8(uint16_t slave_index, uint8_t module_index) const override;
94+
bit16 read16(uint16_t slave_index, uint8_t module_index) const override;
95+
bit32 read32(uint16_t slave_index, uint8_t module_index) const override;
96+
};
97+
} // namespace march
98+
#endif // MARCH_HARDWARE_PDO_INTERFACE_H
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright 2019 Project March.
2+
#ifndef MARCH_HARDWARE_ETHERCAT_PDO_TYPES_H
3+
#define MARCH_HARDWARE_ETHERCAT_PDO_TYPES_H
4+
#include <cstdint>
5+
6+
namespace march
7+
{
8+
// struct used to easily get specific bytes from a 32 bit variable
9+
struct packed_bit32
10+
{
11+
uint8_t b0;
12+
uint8_t b1;
13+
uint8_t b2;
14+
uint8_t b3;
15+
};
16+
17+
// union used for int32, uint32 and float
18+
union bit32
19+
{
20+
int32_t i;
21+
uint32_t ui;
22+
float f;
23+
packed_bit32 p;
24+
};
25+
26+
// struct used to easily get specific bytes from a 16 bit variable
27+
struct packed_bit16
28+
{
29+
uint8_t b0;
30+
uint8_t b1;
31+
};
32+
33+
// union used for int16 and uint16 in combination with the above struct
34+
union bit16
35+
{
36+
int16_t i;
37+
uint16_t ui;
38+
packed_bit16 p;
39+
};
40+
41+
// union used for int8 and uint8 in combination with the above struct, uint8_t is used to read single byte
42+
// unbiased
43+
union bit8
44+
{
45+
int8_t i;
46+
uint8_t ui;
47+
uint8_t b0;
48+
};
49+
} // namespace march
50+
#endif // MARCH_HARDWARE_ETHERCAT_PDO_TYPES_H

0 commit comments

Comments
 (0)