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

Commit 070de04

Browse files
committed
Make (empty) implementation of the remaining template methods
1 parent 1ca5a30 commit 070de04

File tree

10 files changed

+184
-52
lines changed

10 files changed

+184
-52
lines changed

march_hardware/include/march_hardware/ethercat/slave.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Slave : public PdoSlaveInterface
3131

3232
~Slave() noexcept override = default;
3333

34-
uint16_t getSlaveIndex() const
34+
int getSlaveIndex() const
3535
{
3636
return this->slave_index_;
3737
}

march_hardware/include/march_hardware/motor_controller/imotioncube/imotioncube.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class IMotionCube : public MotorController, public Slave
7777
void goToTargetState(IMotionCubeTargetState target_state);
7878
virtual void prepareActuation() override;
7979

80-
uint16_t getSlaveIndex() const override;
80+
int getSlaveIndex() const override;
8181
virtual void reset() override;
8282

8383
/** @brief Override comparison operator */

march_hardware/include/march_hardware/motor_controller/motor_controller.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class MotorController
2323
* Getter for the slave index.
2424
* @return slave index if the motor controller is an ethercat slave, else -1
2525
*/
26-
virtual uint16_t getSlaveIndex() const = 0;
26+
virtual int getSlaveIndex() const = 0;
2727

2828
virtual float getMotorCurrent() = 0;
2929
virtual float getMotorControllerVoltage() = 0;

march_hardware/include/march_hardware/motor_controller/odrive/odrive_enums.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#define O_PM_ENCODER_VELOCITY_UI ".encoder.vel_estimate"
99
#define O_PM_ODRIVE_INPUT_VOLTAGE "vbus_voltage"
1010
#define O_PM_ACTUAL_MOTOR_CURRENT ".motor.current_control.Iq_measured"
11+
#define O_PM_ACTUAL_MOTOR_VOLTAGE_D ".motor.current_control.v_current_control_integral_d"
12+
#define O_PM_ACTUAL_MOTOR_VOLTAGE_Q ".motor.current_control.v_current_control_integral_q"
1113

1214
// axis states
1315
enum States : int

march_hardware/include/march_hardware/motor_controller/odrive/odrive_motor.h

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,45 @@ class OdriveMotor : public Odrive
2020
public:
2121
OdriveMotor(const std::string& axisNumber, std::shared_ptr<OdriveEndpoint> odriveEndpoint, ActuationMode mode);
2222

23-
int initialize();
23+
bool initialize(int cycle_time) override;
24+
void prepareActuation() override;
25+
void reset() override;
2426

25-
int setState(uint8_t state);
26-
int getState();
27+
void actuateRad(double target_rad) override;
28+
void actuateTorque(int16_t target_torque) override;
29+
30+
MotorControllerStates& getStates() override;
31+
32+
float getMotorControllerVoltage() override;
33+
float getMotorCurrent() override;
34+
float getMotorVoltage() override;
35+
double getTorque() override;
2736

28-
float getMotorControllerVoltage();
29-
float getMotorCurrent();
30-
double getTorque();
37+
double getAngleRadAbsolute() override;
38+
double getVelocityRadAbsolute() override;
3139

32-
double getAngleRadAbsolute();
33-
double getVelocityRadAbsolute();
40+
double getAngleRadIncremental() override;
41+
double getVelocityRadIncremental() override;
3442

35-
double getAngleRadIncremental();
36-
double getVelocityRadIncremental();
43+
bool getIncrementalMorePrecise() const override;
44+
ActuationMode getActuationMode() const
45+
{
46+
return this->mode_;
47+
}
48+
int getSlaveIndex() const
49+
{
50+
return -1;
51+
}
3752

3853
private:
3954
std::string create_command(std::string command_name);
40-
ActuationMode mode;
55+
int setState(uint8_t state);
56+
int getState();
57+
58+
int getAngleCountsAbsolute();
59+
int getAngleCountsIncremental();
60+
61+
ActuationMode mode_;
4162
};
4263

4364
} // namespace march
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2019 Project March.
2+
#ifndef MARCH_HARDWARE_IMOTIONCUBE_STATES_H
3+
#define MARCH_HARDWARE_IMOTIONCUBE_STATES_H
4+
5+
#include <string>
6+
#include "march_hardware/motor_controller/motor_controller_states.h"
7+
#include "odrive_enums.h"
8+
9+
namespace march
10+
{
11+
struct OdriveStates : public MotorControllerStates
12+
{
13+
public:
14+
OdriveStates() = default;
15+
16+
States state;
17+
18+
virtual bool checkState()
19+
{
20+
return true;
21+
}
22+
23+
virtual std::string getErrorStatus()
24+
{
25+
std::ostringstream error_stream;
26+
// std::string state = IMCStateOfOperation(this->statusWord).getString().c_str();
27+
28+
error_stream << "State: " << state;
29+
return error_stream.str();
30+
}
31+
};
32+
33+
} // namespace march
34+
35+
#endif // MARCH_HARDWARE_IMOTIONCUBE_STATES_H

march_hardware/src/imotioncube/imotioncube.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ void IMotionCube::actuateTorque(int16_t target_torque)
206206
this->write16(target_torque_location, target_torque_struct);
207207
}
208208

209-
uint16_t IMotionCube::getSlaveIndex() const
209+
int IMotionCube::getSlaveIndex() const
210210
{
211211
return this->Slave::getSlaveIndex();
212212
}
Lines changed: 109 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,65 @@
11
#include "march_hardware/motor_controller/odrive/odrive_motor.h"
2+
#include "march_hardware/motor_controller/odrive/odrive_states.h"
23

34
#include <utility>
45

56
namespace march
67
{
78
OdriveMotor::OdriveMotor(const std::string& axisNumber, std::shared_ptr<OdriveEndpoint> odriveEndpoint,
89
ActuationMode mode)
9-
: Odrive(axisNumber, std::move(odriveEndpoint), false), mode(mode)
10+
: Odrive(axisNumber, std::move(odriveEndpoint), false), mode_(mode)
1011
{
1112
}
1213

13-
int OdriveMotor::initialize()
14+
bool OdriveMotor::initialize(int cycle_time)
15+
{
16+
return cycle_time;
17+
}
18+
19+
void OdriveMotor::prepareActuation()
1420
{
1521
if (this->setState(States::AXIS_STATE_FULL_CALIBRATION_SEQUENCE) == 1)
1622
{
17-
ROS_ERROR("Calibration sequence was not finished successfully");
18-
return ODRIVE_ERROR;
23+
ROS_FATAL("Calibration sequence was not finished successfully");
1924
}
25+
}
2026

21-
return ODRIVE_OK;
27+
// to be implemented
28+
void OdriveMotor::reset()
29+
{
30+
return;
31+
}
32+
33+
void OdriveMotor::actuateRad(double target_rad)
34+
{
35+
ROS_INFO("Actuating rad %f", target_rad);
36+
return;
2237
}
2338

24-
int OdriveMotor::setState(uint8_t state)
39+
void OdriveMotor::actuateTorque(int16_t target_torque)
2540
{
26-
std::string command_name_ = this->create_command(O_PM_REQUEST_STATE);
27-
if (this->write(command_name_, state) == 1)
28-
{
29-
ROS_ERROR("Could net set state; %i to the axis", state);
30-
return ODRIVE_ERROR;
31-
}
32-
return ODRIVE_OK
41+
ROS_INFO("Actuating torque %d", target_torque);
42+
return;
3343
}
34-
int OdriveMotor::getState()
44+
45+
MotorControllerStates& OdriveMotor::getStates()
3546
{
36-
int axis_state;
37-
std::string command_name_ = this->create_command(O_PM_CURRENT_STATE);
38-
if (this->read(command_name_, axis_state) == 1)
39-
{
40-
ROS_ERROR("Could not retrieve incremental position of the encoder");
41-
return ODRIVE_ERROR;
42-
}
47+
static OdriveStates states;
48+
49+
// Common states
50+
states.motorCurrent = this->getMotorCurrent();
51+
states.controllerVoltage = this->getMotorControllerVoltage();
52+
states.motorVoltage = this->getMotorVoltage();
53+
54+
states.absoluteEncoderValue = this->getAngleCountsAbsolute();
55+
states.incrementalEncoderValue = this->getAngleCountsIncremental();
56+
states.absoluteVelocity = this->getVelocityRadAbsolute();
57+
states.incrementalVelocity = this->getVelocityRadIncremental();
58+
59+
states.state = States(this->getState());
60+
61+
return states;
4362

44-
return axis_state;
4563
}
4664

4765
float OdriveMotor::getMotorControllerVoltage()
@@ -50,23 +68,38 @@ float OdriveMotor::getMotorControllerVoltage()
5068
std::string command_name_ = this->create_command(O_PM_ODRIVE_INPUT_VOLTAGE);
5169
if (this->read(command_name_, motor_controller_voltage) == 1)
5270
{
53-
ROS_ERROR("Could not retrieve incremental position of the encoder");
71+
ROS_ERROR("Could not retrieve motor controller voltage");
5472
return ODRIVE_ERROR;
5573
}
5674
return motor_controller_voltage;
5775
}
76+
5877
float OdriveMotor::getMotorCurrent()
5978
{
6079
float motor_current;
6180
std::string command_name_ = this->create_command(O_PM_ACTUAL_MOTOR_CURRENT);
6281
if (this->read(command_name_, motor_current) == 1)
6382
{
64-
ROS_ERROR("Could not retrieve incremental position of the encoder");
83+
ROS_ERROR("Could not retrieve motor courrent");
6584
return ODRIVE_ERROR;
6685
}
6786

6887
return motor_current;
6988
}
89+
90+
float OdriveMotor::getMotorVoltage()
91+
{
92+
float motor_voltage;
93+
std::string command_name_ = this->create_command(O_PM_ACTUAL_MOTOR_VOLTAGE_D);
94+
if (this->read(command_name_, motor_voltage) == 1)
95+
{
96+
ROS_ERROR("Could not retrieve motor voltage");
97+
return ODRIVE_ERROR;
98+
}
99+
100+
return motor_voltage;
101+
}
102+
70103
double OdriveMotor::getTorque()
71104
{
72105
double motor_current = this->getMotorCurrent();
@@ -75,35 +108,52 @@ double OdriveMotor::getTorque()
75108
return motor_torque;
76109
}
77110

111+
int OdriveMotor::getAngleCountsAbsolute()
112+
{
113+
return 0;
114+
}
115+
78116
double OdriveMotor::getAngleRadAbsolute()
79117
{
80-
return 0;
118+
double angle_rad = this->getAngleCountsAbsolute() * PI_2 / std::pow(2, 17);
119+
return angle_rad;
81120
}
121+
82122
double OdriveMotor::getVelocityRadAbsolute()
83123
{
84124
return 0;
85125
}
86126

87-
double OdriveMotor::getAngleRadIncremental()
127+
bool OdriveMotor::getIncrementalMorePrecise() const
88128
{
89-
float iu_position;
90-
std::string command_name_ = this->create_command(O_PM_ENCODER_POSITION_UI);
91-
if (this->read(command_name_, iu_position) == 1)
92-
{
93-
ROS_ERROR("Could not retrieve incremental position of the encoder");
94-
return ODRIVE_ERROR;
95-
}
129+
return true;
130+
}
96131

97-
double angle_rad = iu_position * PI_2 / std::pow(2, 12);
132+
int OdriveMotor::getAngleCountsIncremental()
133+
{
134+
float iu_position;
135+
std::string command_name_ = this->create_command(O_PM_ENCODER_POSITION_UI);
136+
if (this->read(command_name_, iu_position) == 1)
137+
{
138+
ROS_ERROR("Could not retrieve incremental position of the encoder");
139+
return ODRIVE_ERROR;
140+
}
141+
return iu_position;
142+
}
143+
144+
double OdriveMotor::getAngleRadIncremental()
145+
{
146+
double angle_rad = this->getAngleCountsIncremental() * PI_2 / std::pow(2, 12);
98147
return angle_rad;
99148
}
149+
100150
double OdriveMotor::getVelocityRadIncremental()
101151
{
102152
float iu_velocity;
103153
std::string command_name_ = this->create_command(O_PM_ENCODER_VELOCITY_UI);
104154
if (this->read(command_name_, iu_velocity) == 1)
105155
{
106-
ROS_ERROR("Could not retrieve incremental position of the encoder");
156+
ROS_ERROR("Could not retrieve incremental velocity of the encoder");
107157
return ODRIVE_ERROR;
108158
}
109159

@@ -120,4 +170,28 @@ std::string OdriveMotor::create_command(std::string command_name)
120170
return command_name;
121171
}
122172

173+
int OdriveMotor::setState(uint8_t state)
174+
{
175+
std::string command_name_ = this->create_command(O_PM_REQUEST_STATE);
176+
if (this->write(command_name_, state) == 1)
177+
{
178+
ROS_ERROR("Could net set state; %i to the axis", state);
179+
return ODRIVE_ERROR;
180+
}
181+
return ODRIVE_OK
182+
}
183+
184+
int OdriveMotor::getState()
185+
{
186+
int axis_state;
187+
std::string command_name_ = this->create_command(O_PM_CURRENT_STATE);
188+
if (this->read(command_name_, axis_state) == 1)
189+
{
190+
ROS_ERROR("Could not retrieve state of the motor");
191+
return ODRIVE_ERROR;
192+
}
193+
194+
return axis_state;
195+
}
196+
123197
} // namespace march

march_hardware/test/mocks/mock_motor_controller.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class MockMotorController : public march::MotorController
1818
MOCK_METHOD0(prepareActuation, void());
1919
MOCK_CONST_METHOD0(getActuationMode, march::ActuationMode());
2020

21-
MOCK_CONST_METHOD0(getSlaveIndex, uint16_t());
21+
MOCK_CONST_METHOD0(getSlaveIndex, int());
2222
MOCK_CONST_METHOD0(getIncrementalMorePrecise, bool());
2323
MOCK_METHOD0(getStates, march::MotorControllerStates&());
2424

march_hardware_builder/src/hardware_builder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ march::Joint HardwareBuilder::createJoint(const YAML::Node& joint_config, const
134134
}
135135
if (joint_config["odrive"])
136136
{
137-
HardwareBuilder::createOdrive(joint_config["odrive"], mode, urdf_joint, usb_master);
137+
controller = HardwareBuilder::createOdrive(joint_config["odrive"], mode, urdf_joint, usb_master);
138138
}
139139
if (!controller)
140140
{

0 commit comments

Comments
 (0)