Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting the Velocity of the start and end point but does not work #257

Open
moguizhang opened this issue Nov 5, 2024 · 0 comments
Open

Comments

@moguizhang
Copy link

Thank you for writing such a great open source project. I want to use it for trajectory planning of the joint space of a six axis robotic arm, but I don't know how to set the start and end Velocity to non-zero. Could you please guide me? Thank you very much!
Here is my code

void test_toppra()
{
using namespace toppra;
constexpr int dofs = 6;

toppra::Vectors positions;
toppra::Vector waypoint1(dofs);
toppra::Vector waypoint2(dofs);
toppra::Vector waypoint3(dofs);
toppra::Vector waypoint4(dofs);
waypoint1 << 0, 0, 0, 0, 0, 0;
waypoint2 << 1, 2, 3, 3, 2, 1;
waypoint3 << 3, 2, 1, 1, 2, 3;
waypoint4 << 4, 5, 6, 4, 5, 6;

positions.push_back(waypoint1);
positions.push_back(waypoint2);
positions.push_back(waypoint3);
positions.push_back(waypoint4);

toppra::BoundaryCond bc1{ "clamped" };
bc1.order = 1;
//bc1.bc_type = toppra::BoundaryCond::Clamped;
bc1.values.resize(dofs);

toppra::BoundaryCond bc2{ "clamped" };
bc2.order = 1;
//bc2.bc_type = toppra::BoundaryCond::Clamped;
bc2.values.resize(dofs);

for (int i = 0; i < 6; ++i)
{
	bc1.values(i) = 0.8;
	bc2.values(i) = 0.5;
}


std::array<toppra::BoundaryCond, 2> boundary_cond;
boundary_cond[0] = bc1;
boundary_cond[1] = bc2;
toppra::Vector times(positions.size());
times.setLinSpaced(0, 1);
toppra::PiecewisePolyPath path = toppra::PiecewisePolyPath::CubicSpline(positions, times, boundary_cond);
toppra::GeometricPathPtr path_ptr = std::make_shared<toppra::PiecewisePolyPath>(path);

Eigen::VectorXd velLimitLower(dofs);
Eigen::VectorXd velLimitUpper(dofs);
Eigen::VectorXd accLimitLower(dofs);
Eigen::VectorXd accLimitUpper(dofs);
for (int i = 0; i < 6; ++i)
{
	velLimitLower[i] = -1;
	velLimitUpper[i] = 1;

	accLimitLower[i] = -10;
	accLimitUpper[i] = 10;
}
toppra::LinearConstraintPtrs constraints = toppra::LinearConstraintPtrs{
std::make_shared<toppra::constraint::LinearJointVelocity>(velLimitLower, velLimitUpper),
std::make_shared<toppra::constraint::LinearJointAcceleration>(accLimitLower, accLimitUpper) };


toppra::algorithm::TOPPRA problem{ constraints, path_ptr };
toppra::ReturnCode ret_code = problem.computePathParametrization();
if (ret_code == toppra::ReturnCode::OK)
{
	toppra::Vector gridpoints = problem.getParameterizationData().gridpoints;
	toppra::Vector vsquared = problem.getParameterizationData().parametrization;

	toppra::parametrizer::ConstAccel output_traj{ path_ptr,
												gridpoints,
												vsquared };

	auto path_interval = output_traj.pathInterval();
	double duration = path_interval[1] - path_interval[0];
	std::cout << "Traj duration:" << duration << std::endl;
	int rows = std::ceil(duration / 0.005);
	toppra::Vector time(rows);
	time.setLinSpaced(0, duration);
	toppra::Vectors topp_pos_vec_ = output_traj.eval(time, 0);
	toppra::Vectors topp_vel_vec_ = output_traj.eval(time, 1);
	toppra::Vectors topp_acc_vec_ = output_traj.eval(time, 2);
}
else
{
	cout << problem.getErrorMessage() << endl;
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant