Boban Ljubicic
Boban Ljubicic

Reputation: 3

Lissajos curve in stage ros2

I am trying to use differential drive to draw Lissajos curve in stage ros2 using following code: but the problem is that for some reason it dosnt follow that line, any help? I am give parametrization curve.

    // TODO: Compute the robot's linear and angular velocities
  int A=5;
  int B=4;
  int a = 3;
  //int b = 3;
  int num_points = static_cast<int>(duration*frequency);
  double dt = duration/num_points;

  for (int i=0; i < num_points; ++i) {
    double t = i*dt;
    double x = A * sin(a * t);
    double y = B*sin(2*a*t);

    double dx = A*cos(a*t);
    double dy = B*2*cos(2*a*t);

    double dx2 = A*sin(a*t);
    double dy2 = B*4*sin(2*a*t);

    double w1 = dy2*dx - dy*dx2;
    double w2 = dx*dx + dy*dy;

    double v = sqrt(dx*dx + dy*dy);
    double w = w1/w2;

    double theta1 = atan2(dy, dx);
    geometry_msgs::msg::Twist pose;
    pose.linear.x = v;
    pose.linear.y = 0;
    pose.linear.z = 0;

    pose.angular.x = 0;
    pose.angular.y = 0;
    pose.angular.z = w;

    cmd_vel_msgs_.push_back(pose);
  }

Upvotes: 0

Views: 33

Answers (1)

moonwatcher
moonwatcher

Reputation: 1

the dx2 and dy2 may be wrong, d/dx of cos = - sin you have + sin

also check num_points as the cast to int might drop precision, or have other issues when it rounds up and down.

is "duration" defined in scope? as it is not listed on this page?

check your parametric equation and that your trig identities are correct.

best luck

Upvotes: 0

Related Questions