39 boost::this_thread::sleep_for(boost::chrono::milliseconds(10));
40 uint64_t response = response_entry_.
get();
41 return (response & compare_mask) == (command &
compare_mask) ? response : 0;
44 bool set(
char c1,
char c2, uint16_t index, uint32_t val){
45 uint64_t response = 0;
46 uint64_t
command = c1 | (c2 << (1*8)) | ((index & 0x3FFF) << (2*8)) | static_cast<uint64_t>(val) << (4*8);
47 command_entry_.
set(command);
54 bool ok = response == command && (response &
byte_3_bit_6) == 0;
57 template<
typename T>
bool test(
char c1,
char c2, uint16_t index, uint32_t val, T dur){
58 uint64_t response = 0;
59 uint64_t
command = c1 | (c2 << (1*8)) | ((index & 0x3FFF) << (2*8)) | byte_3_bit_6;
63 command_entry_.
set(command);
67 return (response & byte_3_bit_6) == 0 && (response >> (4*8)) == val;
74 storage->entry(command_entry_, 0x2012);
75 storage->entry(response_entry_, 0x2013);
76 event_ = settings.
get_optional<int32_t>(
"homing_event", -1);
77 speed_ = settings.
get_optional<int32_t>(
"homing_speed", 50000);
78 offset_ = settings.
get_optional<int32_t>(
"homing_offset", 0);
79 timeout_= settings.
get_optional<uint32_t>(
"homing_timeout", 60);
83 Motor402::handleInit(status);
85 if(!command_entry_.
valid()){
86 status.
error(
"Command entry is not valid");
87 }
else if(!response_entry_.
valid()){
88 status.
error(
"Response entry is not valid");
90 status.
error(
"Could not switch mode");
92 if(!
set(
'H',
'M', 1, 0) ||
93 !
set(
'H',
'M', 2, offset_) ||
94 !
set(
'H',
'M', 3, event_) ||
95 !
set(
'H',
'M', 4, 2) ||
96 !
set(
'H',
'M', 5, 0) ||
97 !
set(
'H',
'M', 1, 1) ||
99 status.
error(
"could not initialize homing");
103 if(!
test(
'H',
'M', 1, 0, boost::chrono::seconds(timeout_))) status.
error(
"homing timeout");
106 if(!
set(
'H',
'M', 1, 0)) status.
error(
"could not stop homing");
117 return ROSCANOPEN_MAKE_SHARED<ElmoMotor402>(
name, storage, settings);
canopen::ObjectStorage::Entry< uint64_t > response_entry_
uint64_t readResponse(uint64_t command)
static const uint64_t byte_3_bit_6
virtual bool enterModeAndWait(uint16_t mode)
boost::chrono::high_resolution_clock::time_point time_point
ROSLIB_DECL std::string command(const std::string &cmd)
void handleInit(canopen::LayerStatus &status)
virtual bool setTarget(double val)
bool test(char c1, char c2, uint16_t index, uint32_t val, T dur)
canopen::ObjectStorage::Entry< uint64_t > command_entry_
Motor402(const std::string &name, ObjectStorageSharedPtr storage, const canopen::Settings &settings)
const void error(const std::string &r)
T get_optional(const std::string &n, const T &def) const
virtual canopen::MotorBaseSharedPtr allocate(const std::string &name, canopen::ObjectStorageSharedPtr storage, const canopen::Settings &settings)
static const uint64_t compare_mask
time_point get_abs_time(const time_duration &timeout)
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
ElmoMotor402(const std::string &name, canopen::ObjectStorageSharedPtr storage, const canopen::Settings &settings)