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

Commit f54a8f0

Browse files
committed
Added the configuration of the Json file to the odrive object.
also updated the xacro with the right limits.
1 parent d4b1910 commit f54a8f0

File tree

6 files changed

+67
-16
lines changed

6 files changed

+67
-16
lines changed

march_hardware/config/march_odrive.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
"type":"uint32",
1010
"value":4096
1111
},
12+
{
13+
"name":"axis0.encoder.config.use_index",
14+
"type":"bool",
15+
"value":1
16+
},
1217
{
1318
"name":"config.brake_resistance",
1419
"type":"float",

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#define O_PM_ENCODER_POSITION_UI ".encoder.pos_estimate"
88
#define O_PM_ENCODER_VELOCITY_UI ".encoder.vel_estimate"
99
#define O_PM_ODRIVE_INPUT_VOLTAGE "vbus_voltage"
10-
#define O_PM_DESIRED_MOTOR_CURRENT ".motor.current_control.Iq_setpoint"
10+
#define O_PM_DESIRED_MOTOR_CURRENT ".controller.current_setpoint"
1111
#define O_PM_ACTUAL_MOTOR_CURRENT ".motor.current_control.Iq_measured"
1212
#define O_PM_ACTUAL_MOTOR_VOLTAGE_D ".motor.current_control.v_current_control_integral_d"
1313
#define O_PM_ACTUAL_MOTOR_VOLTAGE_Q ".motor.current_control.v_current_control_integral_q"

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ namespace march
1818
class OdriveMotor : public Odrive
1919
{
2020
public:
21-
OdriveMotor(const std::string& axisNumber, std::shared_ptr<OdriveEndpoint> odriveEndpoint, ActuationMode mode);
21+
OdriveMotor(const std::string& axisNumber, std::shared_ptr<OdriveEndpoint> odriveEndpoint, ActuationMode mode,
22+
std::string json_config_file_path);
23+
~OdriveMotor();
2224

2325
bool initialize(int cycle_time) override;
2426
void prepareActuation() override;
@@ -66,6 +68,7 @@ class OdriveMotor : public Odrive
6668
int getAngleCountsIncremental();
6769

6870
ActuationMode mode_;
71+
std::string json_config_file_path_;
6972
};
7073

7174
} // namespace march

march_hardware/src/odrive/odrive.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ int Odrive::json_string_read(const Json::Value& json_parameter_object)
296296
else
297297
{
298298
ROS_ERROR("Error converting string for reading, invalid type %s", parameter_name.c_str());
299-
return ODRIVE_ERROR;
299+
return ODRIVE_ERROR
300300
}
301301
}
302302

@@ -349,7 +349,7 @@ int Odrive::json_string_write(const Json::Value& json_parameter_object)
349349
else
350350
{
351351
ROS_ERROR("Error converting string for writing, invalid type %s", parameter_name.c_str());
352-
return ODRIVE_ERROR;
352+
return ODRIVE_ERROR
353353
}
354354
}
355355

@@ -374,23 +374,21 @@ int Odrive::setConfigurations(const std::string& configuration_json_path)
374374
if (!res)
375375
{
376376
ROS_INFO("Error parsing odrive configuration, error");
377-
return ODRIVE_ERROR;
377+
return ODRIVE_ERROR
378378
}
379379

380380
for (auto& parameter : this->odrive_configuration_json_)
381381
{
382-
ROS_INFO("Setting %s to %s", parameter["name"].asString().c_str(), parameter["value"].asString().c_str());
382+
ROS_DEBUG("Setting %s to %s", parameter["name"].asString().c_str(), parameter["value"].asString().c_str());
383383
int result = this->json_string_write(parameter);
384384

385385
if (result != LIBUSB_SUCCESS)
386386
{
387-
ROS_INFO("Setting %s to %s failed", parameter["name"].asString().c_str(), parameter["value"].asString().c_str());
387+
ROS_WARN("Setting %s to %s failed", parameter["name"].asString().c_str(), parameter["value"].asString().c_str());
388388
continue;
389389
}
390-
391-
ROS_INFO("Setting succeeded %s", parameter["name"].asString().c_str());
392390
}
393-
return ODRIVE_OK;
391+
return ODRIVE_OK
394392
}
395393

396394
template int Odrive::validateType(const odrive_json_object& json_object, int8_t&);

march_hardware/src/odrive/odrive_motor.cpp

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,20 @@
66
namespace march
77
{
88
OdriveMotor::OdriveMotor(const std::string& axisNumber, std::shared_ptr<OdriveEndpoint> odriveEndpoint,
9-
ActuationMode mode)
10-
: Odrive(axisNumber, std::move(odriveEndpoint), false), mode_(mode)
9+
ActuationMode mode, std::string json_config_file_path)
10+
: Odrive(axisNumber, std::move(odriveEndpoint), false), mode_(mode), json_config_file_path_(json_config_file_path)
1111
{
1212
}
1313

14+
OdriveMotor::~OdriveMotor()
15+
{
16+
if (this->setState(States::AXIS_STATE_IDLE) == 1)
17+
{
18+
ROS_FATAL("Not set to idle when closed");
19+
return;
20+
}
21+
}
22+
1423
bool OdriveMotor::initialize(int cycle_time)
1524
{
1625
return cycle_time;
@@ -20,6 +29,13 @@ void OdriveMotor::prepareActuation()
2029
{
2130
this->importOdriveJson();
2231

32+
if (this->setConfigurations(this->json_config_file_path_) == 1)
33+
{
34+
ROS_FATAL("Setting configurations was not finished successfully");
35+
}
36+
37+
this->reset();
38+
2339
if (this->setState(States::AXIS_STATE_FULL_CALIBRATION_SEQUENCE) == 1)
2440
{
2541
ROS_FATAL("Calibration sequence was not finished successfully");
@@ -30,7 +46,7 @@ void OdriveMotor::prepareActuation()
3046

3147
if (this->setState(States::AXIS_STATE_CLOSED_LOOP_CONTROL) == 1)
3248
{
33-
ROS_FATAL("Calibration sequence was not finished successfully");
49+
ROS_FATAL("Setting closed loop control was not finished successfully");
3450
return;
3551
}
3652
}
@@ -61,6 +77,27 @@ void OdriveMotor::reset()
6177
{
6278
ROS_ERROR("Could not reset axis");
6379
}
80+
81+
uint16_t axis_motor_error = 0;
82+
command_name_ = this->create_command(O_PM_AXIS_MOTOR_ERROR);
83+
if (this->write(command_name_, axis_motor_error) == 1)
84+
{
85+
ROS_ERROR("Could not reset motor axis");
86+
}
87+
88+
uint8_t axis_encoder_error = 0;
89+
command_name_ = this->create_command(O_PM_AXIS_ENCODER_ERROR);
90+
if (this->write(command_name_, axis_encoder_error) == 1)
91+
{
92+
ROS_ERROR("Could not reset encoder axis");
93+
}
94+
95+
uint8_t axis_controller_error = 0;
96+
command_name_ = this->create_command(O_PM_AXIS_CONTROLLER_ERROR);
97+
if (this->write(command_name_, axis_controller_error) == 1)
98+
{
99+
ROS_ERROR("Could not reset controller axis");
100+
}
64101
}
65102

66103
void OdriveMotor::actuateRad(double target_rad)
@@ -72,6 +109,12 @@ void OdriveMotor::actuateRad(double target_rad)
72109
void OdriveMotor::actuateTorque(double target_torque_ampere)
73110
{
74111
float target_torque_ampere_float = (float)target_torque_ampere;
112+
ROS_INFO("target torque: %f", target_torque_ampere_float);
113+
114+
if (target_torque_ampere_float < 3.0)
115+
{
116+
target_torque_ampere_float = 3.0;
117+
}
75118
std::string command_name_ = this->create_command(O_PM_DESIRED_MOTOR_CURRENT);
76119
if (this->write(command_name_, target_torque_ampere_float) == 1)
77120
{
@@ -207,8 +250,7 @@ int OdriveMotor::getAngleCountsAbsolute()
207250

208251
double OdriveMotor::getAngleRadAbsolute()
209252
{
210-
double angle_rad = this->getAngleCountsAbsolute() * PI_2 / std::pow(2, 17);
211-
return angle_rad;
253+
return 0;
212254
}
213255

214256
double OdriveMotor::getVelocityRadAbsolute()
@@ -230,6 +272,7 @@ int OdriveMotor::getAngleCountsIncremental()
230272
ROS_ERROR("Could not retrieve incremental position of the encoder");
231273
return ODRIVE_ERROR;
232274
}
275+
ROS_WARN("encoder position: %f", iu_position);
233276
return iu_position;
234277
}
235278

march_hardware_builder/src/hardware_builder.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,11 @@ std::unique_ptr<march::OdriveMotor> HardwareBuilder::createOdrive(const YAML::No
165165
YAML::Node absolute_encoder_config = odrive_config["absoluteEncoder"];
166166
std::string axis = odrive_config["axis"].as<std::string>();
167167
std::string serial_number = odrive_config["serial_number"].as<std::string>();
168+
std::string json_configuration_path = ros::package::getPath("march_hardware").append("/config/march_odrive.json");
169+
168170
auto odrive_endpoint = usb_master.getSerialConnection(serial_number);
169171

170-
return std::make_unique<march::OdriveMotor>(axis, odrive_endpoint, mode);
172+
return std::make_unique<march::OdriveMotor>(axis, odrive_endpoint, mode, json_configuration_path);
171173
}
172174

173175
std::unique_ptr<march::IMotionCube> HardwareBuilder::createIMotionCube(const YAML::Node& imc_config,

0 commit comments

Comments
 (0)