2 system software design
μC/OS-II is a portable, implantable ROM, croppable, preemptive real-time multitasking operating system kernel with high execution efficiency, small footprint, good real-time performance and scalability. Features, the smallest kernel can be compiled to 2KB. μC/OS-II is written in C and assembly language. Most of the code is written in C. Only a few of the code closely related to the processor are written in assembly language. μC/OS-II only includes basic functions such as task scheduling, task management, time management, memory management, communication between tasks, and synchronization.
Assignment of tasks under 2.2μC/OS-II system
After successfully porting the μC/OS-II system to the STM32F107, the μC/OS-II-based programming is done by dividing a large application into relatively independent tasks. The priority of each task is defined and the μC/OS-II kernel schedules and manages these tasks.
The software design idea is to give the motor speed and the steering position of the steering gear through the serial port according to the actual operation of the robot. The speed of the motor is compared with the set value of the incremental encoder and the closed loop control is implemented by the speed PID algorithm. The position of the steering gear is mainly that the absolute value encoder feeds back the current position, and the speed of the steering gear is adjusted according to the action time requirement. The functions to be realized by the motor control system software of this handling robot are as follows:
◆The upper machine gives the motor speed, steering angle and action time;
◆Requires continuous adjustment of motor speed and good static and dynamic performance. The speed is not counted by PI algorithm.
◆Requires the steering gear to reach the specified angle quickly, and the position feedback is used as the adjustment of the given speed of the steering gear;
◆ Has a certain fault protection function. When the motor is blocked, the current is too large, and the steering gear touches the limit switch, it is required to stop the drive module.
For the above functions to be implemented, the application design can be divided into the following tasks:
1 Start the task. Initialize the system, create an initial motor state, then delete itself and start the task to sleep.
2 motor and steering gear protection tasks. It is used to respond to an external interrupt when the overcurrent or limit switch is activated. When the interrupt status is entered, the task semaphore is sent. The task program detects that the semaphore is valid and responds to the task and stops outputting. The task priority is set to level 0.
3 host computer given tasks. It is used for the upper machine to control the motor and the steering gear, and the task priority is set to level 1. When the host computer data input register is generated, an interrupt will be generated, which will send the received byte into the buffer and release the semaphore of the given task of the host computer; when the semaphore is detected, the task will start executing and the corresponding byte will be executed. The information is parsed into corresponding motor speed and steering gear position information to assign values to the corresponding variables.
4 motor speed control task. For closed-loop speed regulation of the motor, the task priority is set to level 2.
5 steering gear control tasks. It is used to control the steering gear to reach the specified position within the specified time, and the task priority is set to level 3.
2.3 Start the task
In the main program, before calling other tasks of μC/OS-II, first call the system initialization function OSInit() to initialize all the variables and data structures of μC/OS-II; at the same time, establish the idle task OS_TaskIdle(), this task is always Is in the ready state; call the OSTaskCreate () function to establish the startup task; call OSStart (), transfer control to the μC / OS-II kernel, start running multitasking.
The startup task is created in the main program, which has three main functions:
1 for system initialization (PWM output module, serial port, ADC module, input level interrupt function, timer).
2 Establish the amount of signal used by the system.
3 establish other tasks of the system.
Finally, call OSTaskDel (OS_PRIO_SELF) to delete itself and start the task to sleep. The main program task flow is shown in Figure 4.
2.4 motor speed control task
Each time the incremental encoder generates an external interrupt, the task semaphore is issued in the interrupt state. The task program detects that the semaphore is valid and responds to the task. The task realizes closed-loop control by measuring the current motor speed and the given speed comparison. The motor speed control task flow is shown in Figure 5.
2.5 steering gear control task
The servo control generates a reference time by a timer, sends a semaphore every fixed time, and the task will be executed once. The servo control task compares the position measured by the absolute encoder with the given position and adjusts the speed of the servo according to the remaining time. The servo control task flow is shown in Figure 6.
3 system electromechanical interface
The steering gear of the robot consists of a 30:1 reducer connected to the DC motor. The absolute position encoder is connected to the steering gear and sends the angle signal of the steering gear to the drive control board. The two shafts of the front wheel of the robot are connected by a transmission rod. One of the shafts is connected to the steering gear by a transmission belt, so that when the steering gear rotates, the transmission belt drives the transmission rod to ensure that the two front wheels can rotate synchronously. The rear-wheel drive motor is a DC motor, which is directly connected to the incremental encoder. After the reduction ratio is reduced by a 25:1 reducer, the rear wheel is driven by the mechanical differential. The signals from the incremental encoder are also sent to the drive control board. The structure of the electromechanical system is shown in Figure 7.
In this paper, the design of the motor and servo controller hardware of the handling robot is realized. The real-time operating system μC/OS-II is successfully embedded on the STM32F107, and the speed closed-loop experiment of the motor and the steering gear is completed. Utilizing the characteristics of multi-task real-time performance of Cortex-M3 core controller and μC/OS-II system, it provides a software and hardware foundation for subsequent robot image video capture and navigation tracing. If the existing PI algorithm is improved and the motor's speed and current double closed-loop control can be realized, the characteristics of the robot motor will be better, and the application prospect of the handling robot will be broader.