2 hepta polynomial trajectory
7 #include "a/trajpoly7.h"
9 static int liba_trajpoly7_gen_(lua_State
*L
, a_trajpoly7
*ctx
, int arg
, int top
)
11 a_float p0
= 0, v0
= 0, a0
= 0, j0
= 0;
12 a_float p1
= 0, v1
= 0, a1
= 0, j1
= 0;
18 j1
= (a_float
)luaL_checknumber(L
, arg
+ 9);
21 j0
= (a_float
)luaL_checknumber(L
, arg
+ 8);
24 a1
= (a_float
)luaL_checknumber(L
, arg
+ 7);
27 a0
= (a_float
)luaL_checknumber(L
, arg
+ 6);
30 v1
= (a_float
)luaL_checknumber(L
, arg
+ 5);
33 v0
= (a_float
)luaL_checknumber(L
, arg
+ 4);
36 p1
= (a_float
)luaL_checknumber(L
, arg
+ 3);
39 p0
= (a_float
)luaL_checknumber(L
, arg
+ 2);
42 ts
= (a_float
)luaL_checknumber(L
, arg
+ 1);
45 a_trajpoly7_gen(ctx
, ts
, p0
, p1
, v0
, v1
, a0
, a1
, j0
, j1
);
51 constructor for hepta polynomial trajectory
52 @tparam number ts difference between final time and initial time
53 @tparam number p0 initial position
54 @tparam number p1 final position
55 @tparam[opt] number v0 initial velocity
56 @tparam[opt] number v1 final velocity
57 @tparam[opt] number a0 initial acceleration
58 @tparam[opt] number a1 final acceleration
59 @tparam[opt] number j0 initial jerk
60 @tparam[opt] number j1 final jerk
61 @treturn a.trajpoly7 hepta polynomial trajectory userdata
64 int liba_trajpoly7_new(lua_State
*L
)
66 int const top
= lua_gettop(L
);
69 a_trajpoly7
*const ctx
= lua_newclass(L
, a_trajpoly7
);
70 lua_registry_get(L
, liba_trajpoly7_new
);
71 lua_setmetatable(L
, -2);
72 return liba_trajpoly7_gen_(L
, ctx
, 0, top
);
78 generate for hepta polynomial trajectory
79 @tparam a.trajpoly7 ctx hepta polynomial trajectory userdata
80 @tparam number ts difference between final time and initial time
81 @tparam number p0 initial position
82 @tparam number p1 final position
83 @tparam[opt] number v0 initial velocity
84 @tparam[opt] number v1 final velocity
85 @tparam[opt] number a0 initial acceleration
86 @tparam[opt] number a1 final acceleration
87 @tparam[opt] number j0 initial jerk
88 @tparam[opt] number j1 final jerk
89 @treturn a.trajpoly7 hepta polynomial trajectory userdata
92 int liba_trajpoly7_gen(lua_State
*L
)
94 int const top
= lua_gettop(L
);
97 luaL_checktype(L
, 1, LUA_TUSERDATA
);
98 a_trajpoly7
*const ctx
= (a_trajpoly7
*)lua_touserdata(L
, 1);
100 return liba_trajpoly7_gen_(L
, ctx
, 1, top
- 1);
106 calculate position for hepta polynomial trajectory
107 @tparam a.trajpoly7 ctx hepta polynomial trajectory userdata
108 @tparam number x difference between current time and initial time
109 @treturn number position output
112 int liba_trajpoly7_pos(lua_State
*L
)
114 a_trajpoly7
const *const ctx
= (a_trajpoly7
const *)lua_touserdata(L
, 1);
117 a_float
const x
= (a_float
)luaL_checknumber(L
, 2);
118 lua_pushnumber(L
, (lua_Number
)a_trajpoly7_pos(ctx
, x
));
125 calculate velocity for hepta polynomial trajectory
126 @tparam a.trajpoly7 ctx hepta polynomial trajectory userdata
127 @tparam number x difference between current time and initial time
128 @treturn number velocity output
131 int liba_trajpoly7_vel(lua_State
*L
)
133 a_trajpoly7
const *const ctx
= (a_trajpoly7
const *)lua_touserdata(L
, 1);
136 a_float
const x
= (a_float
)luaL_checknumber(L
, 2);
137 lua_pushnumber(L
, (lua_Number
)a_trajpoly7_vel(ctx
, x
));
144 calculate acceleration for hepta polynomial trajectory
145 @tparam a.trajpoly7 ctx hepta polynomial trajectory userdata
146 @tparam number x difference between current time and initial time
147 @treturn number acceleration output
150 int liba_trajpoly7_acc(lua_State
*L
)
152 a_trajpoly7
const *const ctx
= (a_trajpoly7
const *)lua_touserdata(L
, 1);
155 a_float
const x
= (a_float
)luaL_checknumber(L
, 2);
156 lua_pushnumber(L
, (lua_Number
)a_trajpoly7_acc(ctx
, x
));
163 calculate jerk for hepta polynomial trajectory
164 @tparam a.trajpoly7 ctx hepta polynomial trajectory userdata
165 @tparam number x difference between current time and initial time
166 @treturn number jerk output
169 int liba_trajpoly7_jer(lua_State
*L
)
171 a_trajpoly7
const *const ctx
= (a_trajpoly7
const *)lua_touserdata(L
, 1);
174 a_float
const x
= (a_float
)luaL_checknumber(L
, 2);
175 lua_pushnumber(L
, (lua_Number
)a_trajpoly7_jer(ctx
, x
));
181 static int liba_trajpoly7_set(lua_State
*L
)
183 switch (a_hash_bkdr(lua_tostring(L
, 2), 0))
185 case 0xE8859EEB: // __name
186 case 0xA65758B2: // __index
187 case 0xAEB551C6: // __newindex
190 lua_getmetatable(L
, 1);
197 static int liba_trajpoly7_get(lua_State
*L
)
199 a_trajpoly7
const *const ctx
= (a_trajpoly7
const *)lua_touserdata(L
, 1);
200 switch (a_hash_bkdr(lua_tostring(L
, 2), 0))
202 case 0x00000070: // p
203 lua_array_num_new(L
, ctx
->p
, A_LEN(ctx
->p
));
205 case 0x00000076: // v
206 lua_array_num_new(L
, ctx
->v
, A_LEN(ctx
->v
));
208 case 0x00000061: // a
209 lua_array_num_new(L
, ctx
->a
, A_LEN(ctx
->a
));
211 case 0x0000006A: // j
212 lua_array_num_new(L
, ctx
->j
, A_LEN(ctx
->j
));
214 case 0xA65758B2: // __index
215 lua_registry_get(L
, liba_trajpoly7_new
);
216 lua_pushstring(L
, "p");
217 lua_array_num_new(L
, ctx
->p
, A_LEN(ctx
->p
));
219 lua_pushstring(L
, "v");
220 lua_array_num_new(L
, ctx
->v
, A_LEN(ctx
->v
));
222 lua_pushstring(L
, "a");
223 lua_array_num_new(L
, ctx
->a
, A_LEN(ctx
->a
));
225 lua_pushstring(L
, "j");
226 lua_array_num_new(L
, ctx
->j
, A_LEN(ctx
->j
));
230 lua_getmetatable(L
, 1);
237 static int liba_trajpoly7_(lua_State
*L
)
239 lua_pushcfunction(L
, liba_trajpoly7_new
);
241 lua_call(L
, lua_gettop(L
) - 1, 1);
245 int luaopen_liba_trajpoly7(lua_State
*L
)
247 static lua_fun
const funcs
[] = {
248 {"new", liba_trajpoly7_new
},
249 {"gen", liba_trajpoly7_gen
},
250 {"pos", liba_trajpoly7_pos
},
251 {"vel", liba_trajpoly7_vel
},
252 {"acc", liba_trajpoly7_acc
},
253 {"jer", liba_trajpoly7_jer
},
255 lua_createtable(L
, 0, A_LEN(funcs
));
256 lua_fun_reg(L
, -1, funcs
, A_LEN(funcs
));
257 lua_createtable(L
, 0, 1);
258 lua_fun_set(L
, -1, "__call", liba_trajpoly7_
);
259 lua_setmetatable(L
, -2);
261 static lua_fun
const metas
[] = {
262 {"__newindex", liba_trajpoly7_set
},
263 {"__index", liba_trajpoly7_get
},
265 lua_createtable(L
, 0, A_LEN(metas
) + A_LEN(funcs
) + 1);
266 lua_fun_reg(L
, -1, metas
, A_LEN(metas
));
267 lua_fun_reg(L
, -1, funcs
, A_LEN(funcs
));
268 lua_str_set(L
, -1, "__name", "a.trajpoly7");
269 lua_registry_set(L
, liba_trajpoly7_new
);