Skip to content

Commit 9e8fca4

Browse files
committed
Squashed 'modules/atom01_deploy/src/inference/' changes from f75ce36..56e7c8a
56e7c8a fix bug a088d5b add policy mode switch log 6feffc5 fix bug 879864d fix policy changing logic c47f1ca update conf git-subtree-dir: modules/atom01_deploy/src/inference git-subtree-split: 56e7c8a72be4bad25cf854a2a79b9744bb883145
1 parent c63fa15 commit 9e8fca4

File tree

7 files changed

+31
-14
lines changed

7 files changed

+31
-14
lines changed

config/inference_amp.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,4 @@ inference_node:
5252
-3.14, 3.14,
5353
-3.14, 3.14,
5454
-3.14, 3.14]
55-
gravity_z_upper: -0.7
55+
gravity_z_upper: -0.3

config/inference_beyondmimic.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ inference_node:
2525
clip_actions: 100.0
2626
usd2urdf: [0, 6, 12, 1, 7, 13, 18, 2, 8, 14, 19, 3, 9, 15, 20, 4, 10, 16, 21, 5, 11, 17, 22]
2727
clip_cmd:
28-
[-0.0, 0.0,
29-
-0.0, 0.0,
30-
-0.0, 0.0]
28+
[-0.4, 0.6,
29+
-0.4, 0.4,
30+
-0.8, 0.8]
3131
joint_default_angle:
3232
[0.0, 0.0, -0.1, 0.3, -0.2, 0.0,
3333
0.0, 0.0, -0.1, 0.3, -0.2, 0.0, 0.0,

config/robot.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ motors:
2323
master_id_offset: 16
2424
motor_zero_offset:
2525
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
26-
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
26+
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.093,
2727
0.0, 0.0, 0.0, 0.0, 0.0,
2828
0.0 ,0.0, 0.0, 0.0, 0.0]
2929

src/inference_node.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ void InferenceNode::setup_model(std::unique_ptr<ModelContext>& ctx, std::string
5656

5757
void InferenceNode::reset() {
5858
is_running_.store(false);
59+
is_interrupt_.store(false);
60+
is_beyondmimic_.store(false);
61+
obs_.resize(obs_num_);
62+
active_ctx_ = normal_ctx_.get();
5963
std::fill(obs_.begin(), obs_.end(), 0.0f);
6064
std::fill(joint_pos_.begin(), joint_pos_.end(), 0.0f);
6165
std::fill(joint_vel_.begin(), joint_vel_.end(), 0.0f);
@@ -64,17 +68,19 @@ void InferenceNode::reset() {
6468
std::fill(cmd_vel_.begin(), cmd_vel_.end(), 0.0f);
6569
std::fill(quat_.begin(), quat_.end(), 0.0f);
6670
std::fill(ang_vel_.begin(), ang_vel_.end(), 0.0f);
67-
if (active_ctx_) {
68-
std::fill(active_ctx_->input_buffer.begin(), active_ctx_->input_buffer.end(), 0.0f);
69-
std::fill(active_ctx_->output_buffer.begin(), active_ctx_->output_buffer.end(), 0.0f);
71+
if (normal_ctx_) {
72+
std::fill(normal_ctx_->input_buffer.begin(), normal_ctx_->input_buffer.end(), 0.0f);
73+
std::fill(normal_ctx_->output_buffer.begin(), normal_ctx_->output_buffer.end(), 0.0f);
74+
}
75+
if (motion_ctx_) {
76+
std::fill(motion_ctx_->input_buffer.begin(), motion_ctx_->input_buffer.end(), 0.0f);
77+
std::fill(motion_ctx_->output_buffer.begin(), motion_ctx_->output_buffer.end(), 0.0f);
7078
}
7179
std::fill(act_.begin(), act_.end(), 0.0f);
7280
std::fill(last_act_.begin(), last_act_.end(), 0.0f);
7381
std::fill(joint_torques_.begin(), joint_torques_.end(), 0.0f);
7482
is_first_frame_ = true;
7583
motion_frame_ = 0;
76-
is_interrupt_.store(false);
77-
is_beyondmimic_.store(false);
7884
if(use_interrupt_){
7985
std::fill(interrupt_action_.begin(), interrupt_action_.end(), 0.0f);
8086
}
@@ -277,6 +283,9 @@ int main(int argc, char **argv) {
277283
RCLCPP_INFO(node->get_logger(), "Press 'X' to reset motors");
278284
RCLCPP_INFO(node->get_logger(), "Press 'B' to start/pause inference");
279285
RCLCPP_INFO(node->get_logger(), "Press 'Y' to switch between joystick and /cmd_vel control");
286+
if (node->use_interrupt_ || node->use_beyondmimic_){
287+
RCLCPP_INFO(node->get_logger(), "Press 'LB' to switch policy mode");
288+
}
280289
executor.spin();
281290
} catch (const std::exception &e) {
282291
RCLCPP_FATAL(rclcpp::get_logger("main"), "Exception caught: %s", e.what());

src/inference_node.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,12 @@ class InferenceNode : public rclcpp::Node {
146146
size_t num_inputs;
147147
size_t num_outputs;
148148
};
149+
bool use_interrupt_, use_beyondmimic_, use_attn_enc_;
149150
private:
150151
std::shared_ptr<RobotInterface> robot_;
151152
int offline_threshold_ = 10;
152153
std::atomic<bool> is_running_{false}, is_joy_control_{true}, is_interrupt_{false}, is_beyondmimic_{false};
153154
std::string model_name_, model_path_, motion_name_, motion_path_, motion_model_name_, motion_model_path_, perception_obs_topic_;
154-
bool use_interrupt_, use_beyondmimic_, use_attn_enc_;
155155
int obs_num_, motion_obs_num_, perception_obs_num_, frame_stack_, motion_frame_stack_, joint_num_;
156156
int decimation_;
157157
std::unique_ptr<Ort::Env> env_;

src/robot_interface.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ void RobotInterface::reset_joints(std::vector<double> joint_default_angle) {
156156
}
157157

158158
exec_motors_parallel([this, &joint_default_angle](std::shared_ptr<MotorDriver>& motor, int idx) {
159-
motor->motor_mit_cmd(joint_default_angle[idx] * robot_cfg_->motor_sign_[idx], 0.0f, robot_cfg_->kp_[idx]/2.0f, robot_cfg_->kd_[idx]/2.0f, 0.0f);
159+
motor->motor_mit_cmd(joint_default_angle[idx] * robot_cfg_->motor_sign_[idx], 0.0f, robot_cfg_->kp_[idx]/2.5f, robot_cfg_->kd_[idx], 0.0f);
160160
});
161161
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
162162
exec_motors_parallel([this, &joint_default_angle](std::shared_ptr<MotorDriver>& motor, int idx) {

src/ros_interface.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ void InferenceNode::load_config() {
3232
this->declare_parameter<std::vector<double>>("clip_cmd", std::vector<double>{});
3333
this->declare_parameter<std::vector<double>>("joint_default_angle", std::vector<double>{});
3434
this->declare_parameter<std::vector<double>>("joint_limits", std::vector<double>{});
35+
this->declare_parameter<float>("gravity_z_upper", -0.5);
3536

3637

3738
this->get_parameter("model_name", model_name_);
@@ -65,6 +66,7 @@ void InferenceNode::load_config() {
6566
this->get_parameter("clip_cmd", clip_cmd_);
6667
this->get_parameter("joint_default_angle", joint_default_angle_);
6768
this->get_parameter("joint_limits", joint_limits_);
69+
this->get_parameter("gravity_z_upper", gravity_z_upper_);
6870

6971

7072
model_path_ = std::string(ROOT_DIR) + "models/" + model_name_;
@@ -96,6 +98,7 @@ void InferenceNode::load_config() {
9698
print_vector<double>("clip_cmd", clip_cmd_);
9799
print_vector<double>("joint_default_angle", joint_default_angle_);
98100
print_vector<double>("joint_limits", joint_limits_);
101+
RCLCPP_INFO(this->get_logger(), "gravity_z_upper: %f", gravity_z_upper_);
99102
}
100103

101104
void InferenceNode::subs_joy_callback(const std::shared_ptr<sensor_msgs::msg::Joy> msg) {
@@ -147,11 +150,16 @@ void InferenceNode::subs_joy_callback(const std::shared_ptr<sensor_msgs::msg::Jo
147150
if (use_interrupt_ || use_beyondmimic_) {
148151
if (msg->buttons[4] == 1 && msg->buttons[4] != last_button4_) {
149152
if(use_interrupt_){
153+
is_running_.store(false);
154+
RCLCPP_INFO(this->get_logger(), "Inference paused");
155+
std::this_thread::sleep_for(std::chrono::milliseconds(50));
150156
is_interrupt_.store(!is_interrupt_.load());
157+
std::this_thread::sleep_for(std::chrono::milliseconds(50));
151158
RCLCPP_INFO(this->get_logger(), "Interrupt mode %s", is_interrupt_.load() ? "enabled" : "disabled");
152159
}
153-
if(use_beyondmimic_){
160+
else if(use_beyondmimic_){
154161
is_running_.store(false);
162+
RCLCPP_INFO(this->get_logger(), "Inference paused");
155163
std::this_thread::sleep_for(std::chrono::milliseconds(50));
156164
is_beyondmimic_.store(!is_beyondmimic_.load());
157165
bool is_beyondmimic = is_beyondmimic_.load();
@@ -170,10 +178,10 @@ void InferenceNode::subs_joy_callback(const std::shared_ptr<sensor_msgs::msg::Jo
170178
std::fill(active_ctx_->output_buffer.begin(), active_ctx_->output_buffer.end(), 0.0f);
171179
std::fill(act_.begin(), act_.end(), 0.0f);
172180
std::fill(last_act_.begin(), last_act_.end(), 0.0f);
181+
std::fill(joint_torques_.begin(), joint_torques_.end(), 0.0f);
173182
is_first_frame_ = true;
174183
motion_frame_ = 0;
175184
std::this_thread::sleep_for(std::chrono::milliseconds(50));
176-
is_running_.store(true);
177185
RCLCPP_INFO(this->get_logger(), "Beyondmimic mode %s", is_beyondmimic ? "enabled" : "disabled");
178186
}
179187
}

0 commit comments

Comments
 (0)