Hi Eric,
I'm learning too, especially from your suggestions.
So where do I input Spline Interpolation in my Code:
PoseLegEndpoints[{x_, y_, z_, \[Theta]_, \[Phi]_, \[Tau]_}] :=
Table[Composition[TranslationTransform[{x, y, z} + {0, platformHeight, 0}],
RotationTransform[\[Theta], {1, 0, 0}],
RotationTransform[\[Phi], {0, 0, 1}],
RotationTransform[\[Tau], {0, 1, 0}]][p], {p, relativePlatformPoints}]
Function giving the lengths of each leg as a function of the pose coordinates:
PoseLegLengths[pose_] := Map[Norm, PoseLegEndpoints[N[pose]] - basePoints]
{PoseLegLengths[{0, 0, 0, 0, 0, 0}], PoseLegLengths[{0, 0.01, 0, 0, 0, 0}]}
{{1.13137, 1.13137, 1.13137, 1.13137, 1.13137, 1.13137}, {1.13793, 1.13793,
1.13793, 1.13793, 1.13793, 1.13793}}
Utility function for generating a sequence of steps between two poses:
PoseRange[{pose1_, pose2_}, steps_, time1_, time2_] :=
Table[pose1 + t/(time2 - time1) (pose2 - pose1), {t,
Range[0, time2 - time1, 1/steps]}]
fn = Interpolation[Transpose[{Range[Length[motionPlan]], motionPlan}]];
Function to tabulate and export a sequence of leg lengths corresponding to a platform shifting between a list of poses at the rate of one pose per second, with a specified fixed offset applied to the length each leg:
ExportMotionPlan[poses_List,
legoffsets_: {1.1313669977935081`, 1.1313669977935081`, 1.1313669977935084`,
1.131366997793508`, 1.1313669977935086`, 1.131366997793508`}] :=
Module[{framerate = 50, lengths, tabledata, time1, time2},
lengths = {poses[[1, 2 ;; 7]]};
time1 := poses[[1, 1]];
Do[(time2 := wp[[1]];
lengths =
Join[lengths,
Rest@PoseRange[{Last[lengths], wp[[2 ;; 7]]}, framerate, time1,
time2]];
time1 = time2;), {wp, Rest[poses]}];
AppendTo[lengths, Last[lengths]];
lengths = Map[PoseLegLengths, lengths];
lengths = Map[# &, lengths];
tabledata = MapIndexed[Prepend[#, (First[#2] - 1)/framerate] &, lengths];
{Export[FileNameJoin[{NotebookDirectory[], "DocumentationFiles",
"PlatformPath.txt"}], {{"LegLengths", tabledata}},
"ModelicaCombiTimeTable"], First[Last[tabledata]]};
lengths = Map[# - legoffsets &, lengths];
tabledata = MapIndexed[Prepend[#, (First[#2] - 1)/framerate] &, lengths];
{Export[FileNameJoin[{NotebookDirectory[], "DocumentationFiles",
"PlatformPath2.txt"}], {{"LegLengths", tabledata}},
"ModelicaCombiTimeTable"], First[Last[tabledata]]}
]
motionPlan = {
{0, 0, 0, 0, 0, 0, 0},
{3.4, 0, 0.40, 0, 0, 0, 0},
{3.5, 0, 0.47, 0, 0, 0, 0},
{4, 0, 0.48, 0, 0, 0, 0},
{4.1, 0, 0.477, 0, 0, 0, 0},
{4.2, 0, 0.48, 0, 0, 0, 0},
{4.3, 0, 0.483, 0, 0, 0, 0},
{4.4, 0, 0.48, 0, 0, 0, 0},
{5, 0, 0.5, 0, 0, 0, 0}, {
7, 0, 0.5, 0, 10, 0, 0},
{7.1, 0, 0.197, 0, 0, 0, 0},
{7.3, 0, 0.2, 0, 0, 10, 0},
{7.4, 0, 0.197, 0, 0, 0, 10},
{8, 0, 0.205, 0, 0, 0, 0},
{8.1, 0, 0.2, 0, 0, 0, 0},
{8.3, 0, 0.205, 0, 0, 0, 0},
{8.4, 0, 0.2, 0, 0, 0, 0},
{9, 0.05, 0.205, 0, 0, 0, 0},
{9.3, 0, 0.205, 0, 0, 0, 0},
{10.1, -0.05, 0.205, 0, 0, 0, 0},
{10.5, 0.05, 0.21, 0, 0, 0, 0}
};
ExportMotionPlan[motionPlan];
Mario