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

Commit bc97020

Browse files
committed
Added all the configurations to launch two motors
1 parent 892ea97 commit bc97020

File tree

9 files changed

+129
-43
lines changed

9 files changed

+129
-43
lines changed

march_hardware/config/march_odrive.json renamed to march_hardware/config/right_hip_fe.json

-5
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,4 @@
7070
"type":"float",
7171
"value":0
7272
},
73-
{
74-
"name":"axis1.config.watchdog_timeout",
75-
"type":"float",
76-
"value":0
77-
}
7873
]

march_hardware/config/right_knee.json

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
[
2+
{
3+
"name":"axis1.motor.config.current_lim",
4+
"type":"float",
5+
"value":30.0
6+
},
7+
{
8+
"name":"axis1.encoder.config.cpr",
9+
"type":"int32",
10+
"value":4096
11+
},
12+
{
13+
"name":"axis1.encoder.config.use_index",
14+
"type":"bool",
15+
"value":1
16+
},
17+
{
18+
"name":"config.brake_resistance",
19+
"type":"float",
20+
"value":0.0
21+
},
22+
{
23+
"name":"axis1.motor.config.pole_pairs",
24+
"type":"int32",
25+
"value":21
26+
},
27+
{
28+
"name":"axis1.motor.config.calibration_current",
29+
"type":"float",
30+
"value":10.0
31+
},
32+
{
33+
"name":"axis1.controller.config.vel_limit",
34+
"type":"float",
35+
"value":200000.0
36+
},
37+
{
38+
"name":"axis1.motor.config.current_control_bandwidth",
39+
"type":"float",
40+
"value":100.0
41+
},
42+
43+
{
44+
"name":"axis1.motor.config.motor_type",
45+
"type":"uint8",
46+
"value":0
47+
},
48+
{
49+
"name":"axis1.controller.config.vel_gain",
50+
"type":"float",
51+
"value":0.01
52+
},
53+
{
54+
"name":"axis1.controller.config.vel_integrator_gain",
55+
"type":"float",
56+
"value":0.05
57+
},
58+
{
59+
"name":"axis1.controller.config.control_mode",
60+
"type":"uint8",
61+
"value":1
62+
},
63+
{
64+
"name":"axis1.sensorless_estimator.config.pm_flux_linkage",
65+
"type":"float",
66+
"value":0.001944723
67+
},
68+
69+
{
70+
"name":"axis1.config.watchdog_timeout",
71+
"type":"float",
72+
"value":0
73+
}
74+
]

march_hardware/include/march_hardware/motor_controller/odrive/usb_master.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class UsbMaster
1919
std::shared_ptr<OdriveEndpoint> getSerialConnection(const std::string& serial_number);
2020

2121
private:
22-
std::vector<std::shared_ptr<OdriveEndpoint>> odrive_endpoints;
22+
std::vector<std::shared_ptr<OdriveEndpoint>> odrive_endpoints_;
2323
};
2424

2525
} // namespace march

march_hardware/src/odrive/usb_master.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@ namespace march
66
{
77
std::shared_ptr<OdriveEndpoint> UsbMaster::getSerialConnection(const std::string& serial_number)
88
{
9-
for (uint i = 0; i < this->odrive_endpoints.size(); ++i)
9+
for (uint i = 0; i < this->odrive_endpoints_.size(); ++i)
1010
{
11-
if (odrive_endpoints[i]->getSerialNumber().compare(serial_number) == 0)
11+
if (this->odrive_endpoints_[i]->getSerialNumber().compare(serial_number) == 0)
1212
{
13-
return odrive_endpoints[i];
13+
return this->odrive_endpoints_[i];
1414
}
1515
}
1616

1717
std::shared_ptr<OdriveEndpoint> odrive_endpoint = std::make_shared<OdriveEndpoint>();
18-
ROS_INFO("Open serial connection %s", serial_number);
18+
ROS_INFO("Open serial connection %s", serial_number.c_str());
1919
odrive_endpoint->open_connection(serial_number);
2020

21-
odrive_endpoints.push_back(odrive_endpoint);
22-
odrive_endpoint->getSerialNumber();
21+
this->odrive_endpoints_.push_back(odrive_endpoint);
22+
2323
return odrive_endpoint;
2424
}
2525
} // namespace march

march_hardware_builder/include/march_hardware_builder/allowed_robot.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class AllowedRobot
4242
}
4343
else if (robot_name == "two_odrive_joints")
4444
{
45-
this->value = two_odrive_joints;
45+
this->value = two_odrive_joints;
4646
}
4747
else if (robot_name == "test_joint_linear")
4848
{
@@ -76,7 +76,7 @@ class AllowedRobot
7676
}
7777
else if (this->value == AllowedRobot::two_odrive_joints)
7878
{
79-
return base_path.append("/robots/two_odrive_joints.yaml");
79+
return base_path.append("/robots/two_odrive_joints.yaml");
8080
}
8181
else if (this->value == AllowedRobot::odrive_test_joint_rotational)
8282
{
@@ -126,6 +126,9 @@ class AllowedRobot
126126
case odrive_test_joint_rotational:
127127
out << "odrive_test_joint_rotational";
128128
break;
129+
case two_odrive_joints:
130+
out << "two_odrive_joints";
131+
break;
129132
case pdb:
130133
out << "pdb";
131134
break;

march_hardware_builder/include/march_hardware_builder/hardware_builder.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class HardwareBuilder
7171

7272
static march::Joint createJoint(const YAML::Node& joint_config, const std::string& joint_name,
7373
const urdf::JointConstSharedPtr& urdf_joint, march::PdoInterfacePtr pdo_interface,
74-
march::SdoInterfacePtr sdo_interface, march::UsbMaster usb_master);
74+
march::SdoInterfacePtr sdo_interface, march::UsbMaster& usb_master);
7575
static std::unique_ptr<march::AbsoluteEncoder> createAbsoluteEncoder(const YAML::Node& absolute_encoder_config,
7676
const urdf::JointConstSharedPtr& urdf_joint);
7777
static std::unique_ptr<march::IncrementalEncoder>
@@ -89,7 +89,7 @@ class HardwareBuilder
8989

9090
static std::unique_ptr<march::OdriveMotor> createOdrive(const YAML::Node& imc_config, march::ActuationMode mode,
9191
const urdf::JointConstSharedPtr& urdf_joint,
92-
march::UsbMaster usb_master);
92+
march::UsbMaster& usb_master);
9393

9494
static const std::vector<std::string> INCREMENTAL_ENCODER_REQUIRED_KEYS;
9595
static const std::vector<std::string> ABSOLUTE_ENCODER_REQUIRED_KEYS;
@@ -113,7 +113,7 @@ class HardwareBuilder
113113
* @return list of created joints
114114
*/
115115
std::vector<march::Joint> createJoints(const YAML::Node& joints_config, march::PdoInterfacePtr pdo_interface,
116-
march::SdoInterfacePtr sdo_interface, march::UsbMaster usb_master) const;
116+
march::SdoInterfacePtr sdo_interface, march::UsbMaster& usb_master) const;
117117

118118
YAML::Node robot_config_;
119119
urdf::Model urdf_;

march_hardware_builder/robots/two_odrive_joints.yaml

+14-14
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,26 @@ march4:
33
cycleTime: 4
44
slaveTimeout: 50
55
joints:
6-
# - right_hip_fe:
7-
# actuationMode: torque
8-
# allowActuation: true
9-
# odrive:
10-
# serial_number: "0x2084387E304E"
11-
# axis: "axis0"
12-
# absoluteEncoder:
13-
# resolution: 17
14-
# minPositionIU: 2045
15-
# maxPositionIU: 45632
16-
# incrementalEncoder:
17-
# resolution: 12
18-
# transmission: 101
6+
- right_hip_fe:
7+
actuationMode: torque
8+
allowActuation: true
9+
odrive:
10+
serial_number: "0x2084387E304E"
11+
axis: "axis0"
12+
absoluteEncoder:
13+
resolution: 17
14+
minPositionIU: 2045
15+
maxPositionIU: 45632
16+
incrementalEncoder:
17+
resolution: 12
18+
transmission: 101
1919

2020
- right_knee:
2121
actuationMode: torque
2222
allowActuation: true
2323
odrive:
2424
serial_number: "0x2084387E304E"
25-
axis: "axis0"
25+
axis: "axis1"
2626
absoluteEncoder:
2727
resolution: 17
2828
minPositionIU: 41533

march_hardware_builder/src/hardware_builder.cpp

+20-6
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ std::unique_ptr<march::MarchRobot> HardwareBuilder::createMarchRobot()
7272
auto pdo_interface = march::PdoInterfaceImpl::create();
7373
auto sdo_interface = march::SdoInterfaceImpl::create();
7474

75-
auto usb_master = march::UsbMaster();
75+
march::UsbMaster usb_master = march::UsbMaster();
7676

7777
std::vector<march::Joint> joints = this->createJoints(config["joints"], pdo_interface, sdo_interface, usb_master);
7878

@@ -98,7 +98,7 @@ std::unique_ptr<march::MarchRobot> HardwareBuilder::createMarchRobot()
9898
march::Joint HardwareBuilder::createJoint(const YAML::Node& joint_config, const std::string& joint_name,
9999
const urdf::JointConstSharedPtr& urdf_joint,
100100
march::PdoInterfacePtr pdo_interface, march::SdoInterfacePtr sdo_interface,
101-
march::UsbMaster usb_master)
101+
march::UsbMaster& usb_master)
102102
{
103103
ROS_DEBUG("Starting creation of joint %s", joint_name.c_str());
104104
if (!urdf_joint)
@@ -152,7 +152,7 @@ march::Joint HardwareBuilder::createJoint(const YAML::Node& joint_config, const
152152
std::unique_ptr<march::OdriveMotor> HardwareBuilder::createOdrive(const YAML::Node& odrive_config,
153153
march::ActuationMode mode,
154154
const urdf::JointConstSharedPtr& urdf_joint,
155-
march::UsbMaster usb_master)
155+
march::UsbMaster& usb_master)
156156
{
157157
if (!odrive_config || !urdf_joint)
158158
{
@@ -165,11 +165,25 @@ 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");
168+
169+
std::string configuration_path =
170+
ros::package::getPath("march_hardware").append("/config/" + urdf_joint->name + ".json");
171+
172+
std::ifstream file(configuration_path);
173+
174+
if (file.fail())
175+
{
176+
throw std::runtime_error("Could not open configuration file for the odrive");
177+
}
178+
179+
if (file.is_open())
180+
{
181+
file.close();
182+
}
169183

170184
auto odrive_endpoint = usb_master.getSerialConnection(serial_number);
171185

172-
return std::make_unique<march::OdriveMotor>(axis, odrive_endpoint, mode, json_configuration_path);
186+
return std::make_unique<march::OdriveMotor>(axis, odrive_endpoint, mode, configuration_path);
173187
}
174188

175189
std::unique_ptr<march::IMotionCube> HardwareBuilder::createIMotionCube(const YAML::Node& imc_config,
@@ -329,7 +343,7 @@ void HardwareBuilder::initUrdf()
329343
std::vector<march::Joint> HardwareBuilder::createJoints(const YAML::Node& joints_config,
330344
march::PdoInterfacePtr pdo_interface,
331345
march::SdoInterfacePtr sdo_interface,
332-
march::UsbMaster usb_master) const
346+
march::UsbMaster& usb_master) const
333347
{
334348
std::vector<march::Joint> joints;
335349
for (const YAML::Node& joint_config : joints_config)

march_hardware_interface/config/two_odrive_joints/controllers.yaml

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ march:
1313
type: effort_controllers/JointTrajectoryController
1414
allow_partial_joints_goal: true
1515
joints:
16-
# - right_hip_fe
16+
- right_hip_fe
1717
- right_knee
1818
gains: # Required because we're controlling an effort interface
19-
# right_hip_fe: {p: 0, i: 0, d: 0, i_clamp: 100, publish_state: true, antiwindup: true}
19+
right_hip_fe: {p: 0, i: 0, d: 0, i_clamp: 100, publish_state: true, antiwindup: true}
2020
right_knee: {p: 0, i: 0, d: 0, i_clamp: 100, publish_state: true, antiwindup: true}
2121
constraints:
22-
# right_hip_fe:
23-
# margin_soft_limit_error: 0.5
24-
# trajectory: 0.305
25-
# goal: 0.305
22+
right_hip_fe:
23+
margin_soft_limit_error: 0.5
24+
trajectory: 0.305
25+
goal: 0.305
2626
right_knee:
2727
margin_soft_limit_error: 0.5
2828
trajectory: 0.305

0 commit comments

Comments
 (0)