summaryrefslogtreecommitdiff
path: root/src/emc/motion/simple_tp.h
blob: ca2f646ee914d68afa92b94bbbb4dd0d4353cbb2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/********************************************************************
* Description: simple_tp.h
*   A simple, single axis trajectory planner
*
* Author:
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved
*
* Last change:
********************************************************************/

/*  simple_tp.c and simple_tp.h define a simple, single axis trajectory
    planner.  It is based on the "free mode trajectory planner" that was
    originally written as part of EMC2's control.c, but the code has
    been pulled out of control.c and given a somewhat object oriented
    API to allow it to be used for both teleop and free mode.
*/

#ifndef SIMPLE_TP_H
#define SIMPLE_TP_H

#ifdef __cplusplus
extern "C" {
#endif

    typedef struct simple_tp_t {
	double pos_cmd;		/* position command */
	double max_vel;		/* velocity limit */
	double max_acc;		/* acceleration limit */
	int enable;		/* if zero, motion stops ASAP */
	double curr_pos;	/* current position */
	double curr_vel;	/* current velocity */
	int active;		/* non-zero if motion in progress */
    } simple_tp_t;

/* I could write a bunch of functions to read and write the first four
   structure members, and to read the last three, but that seems silly.
*/

/* The update() function does all the work.  If 'enable' is true, it
   computes a new value of 'curr_pos', which moves toward 'pos_cmd'
   while obeying the 'max_vel' and 'max_accel' limits.  It also sets
   'active' if movement is in progress, and clears it when motion
   stops at the commanded position.  The command or either of the
   limits can be changed at any time.  If 'enable' is false, it
   ramps the velocity to zero, then clears 'active' and sets
   'pos_cmd' to match 'curr_pos', to avoid motion the next time it
   is enabled.  'period' is the period between calls, in seconds.
*/

extern void simple_tp_update(simple_tp_t *tp, double period);


#ifdef __cplusplus
}
#endif
#endif	/* SIMPLE_TP_H */