This is a Hoist Control System implemented as a multi-process application in C following POSIX (Portable Operating System Interface) standards. It utilizes various inter-process communication methods including named and unnamed pipes, alongside a watchdog timer mechanism for resilience. The system operates in a Linux environment. The program is designed to control a hoist using inputs from two different consoles. The system can control the direction of hoist movement (Command console) and provide outputs from the motors (Inspection console). In addition, it offers two emergency functions:
- STOP: Immediately halt the movement of the motors, with the option to restart later.
- RESET: Immediately halt the hoist movement and return the motors to the zero position.
The project consists of five processes:
-
master.c
creates all the other processes using thefork()
function. It executes them using anexecvp()
function that points to the files containing the other processes. The master process is the parent of all others, hence it includes the watchdog timer function. -
Command.c
serves as the main control console. It reads the motors’ process IDs from their .txt files. Communication between this console and the motors is established using two independent named FIFO pipes. -
Inspection.c
is the console used as the user interface. It prints “-nan” when none of the processes are working yet, and it requires an interaction from the Command console. After receiving the interaction, it shows the changes in the motors' positions to the user. It also sends the emergency commands STOP and RESET in the parent process section. -
MotorX.c
andMotorZ.c
control the X and Z positions, respectively. They both use the same implemented functions and variables. Each of these processes sends a signal to the watchdog timer to verify they’re functioning.
Use the install.sh
script to compile and install the application:
#!/bin/bash
echo $1
unzip ZippedHA_1.zip -d $1
cd $1/HA_1
cd Command
gcc Command.c -o command
cd ..
cd MotorX
gcc MotorX.c -o motorx
cd ..
cd MotorZ
gcc MotorZ.c -o motorz
cd ..
cd Inspection
gcc Inspection.c -o inspection
cd ..
cd Master
gcc master.c -o masterWD
Use the run.sh script to start the application:
#!/bin/bash
echo please enter path of the unzipped folder
read pathname
cd $pathname/HA_1/Master
./masterWD
After running the application using the run.sh
script, the system waits for inputs from the Command console for hoist movement. The commands for movement are as follows:
j
: Increase motorX positionl
: Decrease motorZ positioni
: Increase motorZ positionk
: Decrease motorZ positionq
: Terminate all the four processes
For any other key press, the motor will remain in the same position until another valid command is given.
The system employs a watchdog mechanism in the master process to monitor the functioning of all subprocesses. The watchdog timer relies on a global boolean variable commandsig
initially set to true
. Each subprocess sends a signal to the master process upon successful execution, causing the watchdog timer to reset commandsig
to false
. If none of the subprocesses send a signal within a 60-second window, the watchdog timer will terminate all subprocesses, thus ensuring the overall system stability.
In case of emergency, the system provides two functions - STOP and RESET. These functions can be accessed from the Inspection console. The STOP command halts all motor movements but allows for later resumption. The RESET command not only stops all movement but also brings the motors to a zero position.
All of the above processes send a signal to the watchdog timer to prove they’re functioning. Additionally, each motor process writes its process ID to a .txt file at runtime. This allows for correct signal routing from the consoles to the intended processes.
For more details about the implementation of the individual processes, please refer to the source code documentation. Work done in cooperation with Alice Maria Catalano and Hussein Hassan.