Converting double array to struct array for generalized inverse kinematics

조회 수: 5 (최근 30일)
Joo Lee
Joo Lee 2018년 10월 12일
답변: Sebastian Castro 2018년 11월 4일
Hello,
q0 = robot.homeConfiguration.JointPosition;
numWaypoints = 5;
qWaypoints = repmat(q0, numWaypoints, 1);
gik = robotics.GeneralizedInverseKinematics;
gik.RigidBodyTree = robot;
gik.ConstraintInputs = {'position'};
posTgt = robotics.PositionTarget(ee);
posTgt.TargetPosition = [1 1 1];
qWaypoints(1,:)= q0;
for k = 2:numWaypoints
[qWaypoints(k,:),solutionInfo] = gik(qWaypoints(:,k-1), posTgt);
end
above is the code that I am working with. The error ouccurs at "gik(qWaypoints(:,k-1), posTgt)". So basically I need to convert the qWaypoints to struct array (currently it is an array of doubles). Is there an easy and simple way for this conversion ?
  댓글 수: 2
Kevin Chng
Kevin Chng 2018년 10월 12일
Hi,
I guess you have to
convert it to cell first
a=num2cell(gWaypoints);
later, use cell2struc() convert it to structure array.
I don't know how your qWaypoints array looks like, therefore i unable to help you to code it, however, you may refer to documentation :
Walter Roberson
Walter Roberson 2018년 10월 12일
Perhaps just set the robot DataFormat property to 'row'?

댓글을 달려면 로그인하십시오.

답변 (1개)

Sebastian Castro
Sebastian Castro 2018년 11월 4일
Instead of converting back and forth, it's easier to stick to a consistent format -- either all structs or all numeric.
If you do either of the following,
robot.DataFormat = 'row';
robot.DataFormat = 'column';
then the robot configuration, including the solution of gik, will be a numeric row/column instead of a struct.
As an alternative, as you said, you can keep everything as a struct. You can simply your first line to
q0 = robot.homeConfiguration
Then, repmat should handle the rest for initializing the array to be of structs rather than numeric.
Finally, your loop contents should become something like:
[qWaypoints(k),solutionInfo] = gik(qWaypoints(k-1), posTgt);
- Sebastian

카테고리

Help CenterFile Exchange에서 Simulation에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by