lebai-motion-control  3.1.6
lebai motion control C interface
example_tg.cc
Go to the documentation of this file.
1 #include "create_robot_model.hh"
4 
16 int main(int argc, char **argv)
17 {
18  auto robot_model_config = createLM3Config();
19  lmc_robot_model_t* robot_model = lmc_rm_new();
20  lmc_rm_init(robot_model, &robot_model_config,STRUCT_TYPE_61);
21  lmc_tg_config_t tg_config;
22  lmc_tg_limit_t tg_limit;
23  for (int i = 0; i < 6; i++)
24  {
25  tg_limit.jnt_max_acc[i] = 4;
26  tg_limit.jnt_max_v[i] = 2;
27  tg_limit.jnt_pos_positive_limit[i] = 6.28;
28  tg_limit.jnt_pos_negative_limit[i] = -6.28;
29  }
30  tg_limit.cartesian_max_v = 1;
31  tg_limit.cartesian_max_acc = 1;
32  tg_limit.cartesian_max_rot_v = 1;
33  tg_limit.cartesian_max_rot_acc = 1;
34  tg_limit.jnt_acc_time_constant = 10;
35 
36  tg_config.cycle_time = 0.01;
37  tg_config.buffer_size = 10;
38  lmc_tg_t * tg = lmc_tg_new();
39 
40  lmc_joint_state_t joint_state[6];
41  lmc_joint_cmd_t joint_cmd[6];
42  lmc_tg_runtime_data_t runtime_data;
43 
44  joint_state[0].pos = 0.0;
45  joint_state[1].pos = 0.1;
46  joint_state[2].pos = 0.2;
47  joint_state[3].pos = 0.3;
48  joint_state[4].pos = 0.4;
49  joint_state[5].pos = 0.5;
50 
51  lmc_tg_init(tg, robot_model, &tg_config);
52  lmc_tg_set_limit(tg, &tg_limit);
53  lmc_tg_set_joint_pos(tg, joint_state);
55 
56  double move_joint_pos1[6];
57  for(size_t i = 0; i < 6; ++i) {
58  move_joint_pos1[i] = 0.8;
59  }
60  lmc_tg_move_param_t move_joint_param;
61  move_joint_param.v = 1.0;
62  move_joint_param.acc = 1.0;
63  move_joint_param.blend_radius = 0.0;
64  move_joint_param.interruptable = 0;
65  move_joint_param.smooth_move_to_next = 0;
66  move_joint_param.time = 0.0;
67  lmc_tg_buffer_move_joint(tg, 1, move_joint_pos1, &move_joint_param);
68  while(tg_ret.state != TGS_IDLE)
69  {
70  tg_ret = lmc_tg_update(tg);
71  lmc_tg_get_updated_date(tg, joint_cmd, &runtime_data);
72  }
73  lmc_tg_delete(&tg);
74  lmc_rm_delete(&robot_model);
75  return 0;
76 }
Limitation data structure for trajectory generator.
Definition: lmc_tg_config.h:27
Trjecotry generator update ret value.
Definition: lmc_tg.h:82
int lmc_rm_init(lmc_robot_model_t *const robot_model, lmc_robot_model_config_t const *const robot_model_config, lmc_robot_model_struct_t struct_type)
Init a robot model using lmc_robot_model_config_t.
double jnt_max_acc[LMC_MAX_JOINT_NUM]
Definition: lmc_tg_config.h:29
size_t buffer_size
Definition: lmc_tg_config.h:47
double cartesian_max_rot_acc
Definition: lmc_tg_config.h:37
void lmc_rm_delete(lmc_robot_model_t **robot_model_addr)
Delete a robot model instance.
Trjecotry generator runtime data.
Definition: lmc_tg.h:112
unsigned int interruptable
Definition: lmc_tg.h:130
unsigned int jnt_acc_time_constant
Definition: lmc_tg_config.h:38
int lmc_tg_set_limit(lmc_tg_t *const tg, lmc_tg_limit_t const *const limit)
Set trajectory generator limit parameters.
Trajectory generator related data structures and functions.
double jnt_pos_positive_limit[LMC_MAX_JOINT_NUM]
Definition: lmc_tg_config.h:30
joint command data
Definition: lmc_joint.h:35
Trajectory generator configuration data structure.
Configuration data structure for trajectory generator.
Definition: lmc_tg_config.h:45
double cartesian_max_acc
Definition: lmc_tg_config.h:35
unsigned int smooth_move_to_next
Definition: lmc_tg.h:128
lmc_tg_buffer_ret_t lmc_tg_buffer_move_joint(lmc_tg_t *const tg, int id, double const *const target, lmc_tg_move_param_t const *const param)
Try to add a move joint trajectory to buffer.
lmc_robot_model_t * lmc_rm_new()
Create a robot model instance.
double blend_radius
Definition: lmc_tg.h:130
int lmc_tg_get_updated_date(lmc_tg_t const *const tg, lmc_joint_cmd_t *const joint_cmd, lmc_tg_runtime_data_t *const tg_runtime_data)
Get usefull trajectory generator update data.
double cartesian_max_v
Definition: lmc_tg_config.h:34
double cartesian_max_rot_v
Definition: lmc_tg_config.h:36
struct lmc_robot_model lmc_robot_model_t
Robot model data structure.
double cycle_time
Definition: lmc_tg_config.h:46
lmc_tg_update_state_t state
Definition: lmc_tg.h:83
void lmc_tg_set_joint_pos(lmc_tg_t *const tg, lmc_joint_state_t const *const joint_state)
This function set current joint anchor point of trajectory generator caculation. It must be called wh...
joint state data
Definition: lmc_joint.h:21
double jnt_pos_negative_limit[LMC_MAX_JOINT_NUM]
Definition: lmc_tg_config.h:31
lmc_tg_update_ret_t lmc_tg_update(lmc_tg_t *const tg)
Core calculation function of trajectory generator, always call it in realtime loop,.
void lmc_tg_delete(lmc_tg_t **tg_addr)
Delete a trajectory generator instance.
struct lmc_tg lmc_tg_t
Trajectory generator data structure.
Definition: lmc_tg.h:33
int main(int argc, char **argv)
Example of tg usage.
Definition: example_tg.cc:16
Trjecotry generator move parameter.
Definition: lmc_tg.h:125
lmc_tg_t * lmc_tg_new()
Create a trajectory generator instance.
create robot model function.
int lmc_tg_init(lmc_tg_t *const tg, lmc_robot_model_t const *const robot_model, lmc_tg_config_t const *const config)
Init a trajectory generator.
lmc_robot_model_config_t createLM3Config()
Create a robot model config instance.
double jnt_max_v[LMC_MAX_JOINT_NUM]
Definition: lmc_tg_config.h:28