@@ -81,13 +81,13 @@ double Pan::get_joint_yaw(double period, double range, double time, double phase
8181BT::NodeStatus Pan::tick ()
8282{
8383 rclcpp::spin_some (node_->get_node_base_interface ());
84- bool is_first_tick = false ;
84+ // bool is_first_tick = false;
8585
8686 if (status () == BT::NodeStatus::IDLE) {
8787 // node_->remove_activation("attention_server");
8888 start_time_ = node_->now ();
8989 initial_yaw_ = phase_; // Store the actual starting position
90- is_first_tick = true ;
90+ // is_first_tick = true;
9191
9292 // Calculate phase so the sine wave starts exactly at the current position
9393 // The sine wave equation is: yaw = range * sin(2π/period * t + phase)
@@ -128,8 +128,9 @@ BT::NodeStatus Pan::tick()
128128 command_msg.points [0 ].positions [1 ] = std::clamp (pitch_angle_, -pitch_limit_, pitch_limit_);
129129 command_msg.points [0 ].velocities [0 ] = 0.0 ;
130130 command_msg.points [0 ].velocities [1 ] = 0.0 ;
131- // Use 1.0 second for first command to smoothly transition, then 0.1 for rest
132- command_msg.points [0 ].time_from_start = rclcpp::Duration::from_seconds (is_first_tick ? 1.0 : 0.1 );
131+ double yaw_diff = std::abs (yaw - phase_);
132+ double time_to_reach = yaw_diff / 1.5 ; // 1.5 is max velocity
133+ command_msg.points [0 ].time_from_start = rclcpp::Duration::from_seconds (time_to_reach);
133134 joint_cmd_pub_->publish (command_msg);
134135 rclcpp::spin_some (node_->get_node_base_interface ());
135136
0 commit comments