Skip to content

Commit

Permalink
Optimize calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
m12watanabe1a committed Nov 24, 2023
1 parent d1c3046 commit 74bfef3
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
1 change: 0 additions & 1 deletion p9n_node/include/p9n_node/teleop_twist_joy_node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class TeleopTwistJoyNode : public rclcpp::Node
using Joy = sensor_msgs::msg::Joy;

private:
float speed_factor_ = 1.0;
double linear_max_speed_, angular_max_speed_;

p9n_interface::HW_TYPE hw_type_;
Expand Down
5 changes: 2 additions & 3 deletions p9n_node/src/teleop_twist_joy_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,14 @@ void TeleopTwistJoyNode::onJoy(Joy::ConstSharedPtr joy_msg)
this->timer_watchdog_->reset();
this->p9n_if_->setJoyMsg(joy_msg);

const double PI = 3.14159;
static bool stopped = true;
if (this->p9n_if_->isTiltedStickL()) {
auto twist_msg = std::make_unique<Twist>();
twist_msg->linear.set__x(this->linear_max_speed_ * this->p9n_if_->tiltedStickLY());

if (this->p9n_if_->tiltedStickLY() > sin(PI / 8)) {
if (this->p9n_if_->tiltedStickLY() > sin(M_PI * 0.125)) {
twist_msg->angular.set__z(this->angular_max_speed_ * this->p9n_if_->tiltedStickLX());
} else if (this->p9n_if_->tiltedStickLY() < sin(-PI / 8)) {
} else if (this->p9n_if_->tiltedStickLY() < sin(-M_PI * 0.125)) {
twist_msg->angular.set__z(-this->angular_max_speed_ * this->p9n_if_->tiltedStickLX());
} else {
twist_msg->linear.set__x(0.0);
Expand Down

0 comments on commit 74bfef3

Please sign in to comment.