|
1 | 1 | /** |
2 | 2 | * <rc/start_stop.h> |
3 | 3 | * |
4 | | - * @brief cleanly start and stop a process, signal handling, program flow |
5 | | - * |
6 | | - * It can be tricky to manage the starting and stopping of mutiple threads and |
7 | | - * loops. Since the robotics cape library has several background threads in |
8 | | - * addition to any user-created threads, we encourage the use of the |
9 | | - * consolidated high-level process control method described here. These |
10 | | - * functions allow easy implementation of good-practice process handling |
11 | | - * including a global shutdown flag, a signal handler, making & deleting a PID |
12 | | - * file, stopping previously running copies of a program, and stopping a program |
13 | | - * when it's in the background. |
14 | | - * |
15 | | - * The rc_state_t struct tries to cover the majority of use cases in the context |
16 | | - * of a robotics application. The user should start their program main() |
17 | | - * function by setting the state to UNINITIALIZED and enabling the signal |
18 | | - * handler before doing hardware initialization and starting threads. When the |
19 | | - * user's own initialization sequence is complete they should set the flow state |
20 | | - * to PAUSED or RUNNING to indicate to the newly created threads that the |
21 | | - * program should now behave in normal ongoing operational mode. |
22 | | - * |
23 | | - * During normal operation, the user may elect to implement a PAUSED state where |
24 | | - * the user's threads may keep running to read sensors but do not actuate |
25 | | - * motors, leaving their robot in a safe state. For example, pressing the pause |
26 | | - * button could be assigned to change this state back and forth between RUNNING |
27 | | - * and PAUSED. This is entirely optional. |
28 | | - * |
29 | | - * The most important state here is EXITING. The signal handler described here intercepts the SIGINT signal when the user presses |
30 | | - * Ctrl-C and sets the state to EXITING. It is then up to the user's |
31 | | - * threads to watch for this condition and exit cleanly. The user |
32 | | - * may also set the state to EXITING at any time to trigger the closing of |
33 | | - * their own threads and Robotics Cape library's own background threads. |
34 | | - * |
35 | | - * The flow state variable is kept in the robotics cape library's memory |
36 | | - * space and should be read and modified by the rc_get_state() and |
37 | | - * rc_set_state() functions above. The user may optionally use the |
38 | | - * rc_print_state() function to print a human readable version of the state enum |
39 | | - * to the screen. |
| 4 | + * @brief cleanly start and stop a process, signal handling, program flow |
| 5 | + * |
| 6 | + * It can be tricky to manage the starting and stopping of mutiple |
| 7 | + * threads and loops. Since the robot control library has several |
| 8 | + * background threads in addition to any user-created threads, we |
| 9 | + * encourage the use of the consolidated high-level process control |
| 10 | + * method described here. These functions allow easy implementation |
| 11 | + * of good-practice process handling including a global shutdown |
| 12 | + * flag, a signal handler, making & deleting a PID file, stopping |
| 13 | + * previously running copies of a program, and stopping a program |
| 14 | + * when it's in the background. |
| 15 | + * |
| 16 | + * The rc_state_t struct tries to cover the majority of use cases in |
| 17 | + * the context of a robotics application. The user should start |
| 18 | + * their program main() function by setting the state to |
| 19 | + * UNINITIALIZED and enabling the signal handler before doing |
| 20 | + * hardware initialization and starting threads. When the user's own |
| 21 | + * initialization sequence is complete they should set the flow |
| 22 | + * state to PAUSED or RUNNING to indicate to the newly created |
| 23 | + * threads that the program should now behave in normal ongoing |
| 24 | + * operational mode. |
| 25 | + * |
| 26 | + * During normal operation, the user may elect to implement a PAUSED |
| 27 | + * state where the user's threads may keep running to read sensors |
| 28 | + * but do not actuate motors, leaving their robot in a safe state. |
| 29 | + * For example, pressing the pause button could be assigned to |
| 30 | + * change this state back and forth between RUNNING and PAUSED. This |
| 31 | + * is entirely optional. |
| 32 | + * |
| 33 | + * The most important state here is EXITING. The signal handler |
| 34 | + * described here intercepts the SIGINT signal when the user presses |
| 35 | + * Ctrl-C and sets the state to EXITING. It is then up to the user's |
| 36 | + * threads to watch for this condition and exit cleanly. The user |
| 37 | + * may also set the state to EXITING at any time to trigger the |
| 38 | + * closing of their own threads and robot control library's own |
| 39 | + * background threads. |
| 40 | + * |
| 41 | + * The flow state variable is kept in the robot control library's |
| 42 | + * memory space and should be read and modified by the |
| 43 | + * rc_get_state() and rc_set_state() functions above. The user may |
| 44 | + * optionally use the rc_print_state() function to print a human |
| 45 | + * readable version of the state enum to the screen. |
40 | 46 | * |
41 | 47 | * |
42 | 48 | * @addtogroup start_stop |
|
50 | 56 | extern "C" { |
51 | 57 | #endif |
52 | 58 |
|
53 | | -#define RC_PID_DIR "/var/run/roboticscape" |
54 | | -#define RC_PID_FILE "/var/run/roboticscape/roboticscape.pid" |
| 59 | +#define RC_PID_DIR "/run/shm/" |
| 60 | +#define RC_PID_FILE "/run/shm/robotcontrol.pid" |
55 | 61 |
|
56 | 62 | /** |
57 | 63 | * @brief process state variable, read and modify by rc_get_state, |
@@ -91,7 +97,7 @@ void rc_set_state(rc_state_t new_state); |
91 | 97 | int rc_print_state(); |
92 | 98 |
|
93 | 99 | /** |
94 | | - * @brief Makes a PID file RC_PID_FILE (/var/run/robotics_cape.pid) |
| 100 | + * @brief Makes a PID file RC_PID_FILE (/run/shm/robotcontrol.pid) |
95 | 101 | * containing the current PID of your process |
96 | 102 | * |
97 | 103 | * @return Returns 0 if successful. If that file already exists then it is |
|
0 commit comments