Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Controller/MachineDirectionController.cpp@13:34f7f783ad24, 2016-02-05 (annotated)
- Committer:
- mborchers
- Date:
- Fri Feb 05 16:06:44 2016 +0000
- Revision:
- 13:34f7f783ad24
L?ngsregelung ausgelagert
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mborchers | 13:34f7f783ad24 | 1 | #include "Controller/MachineDirectionController.h" |
mborchers | 13:34f7f783ad24 | 2 | |
mborchers | 13:34f7f783ad24 | 3 | MachineDirectionController::MachineDirectionController(PwmOut *pwmOut, Queue<float, 2> *machine_direction_queue, Queue<float, 2> *imu_queue_velocity) { |
mborchers | 13:34f7f783ad24 | 4 | this->pwmOut = pwmOut; |
mborchers | 13:34f7f783ad24 | 5 | this->machine_direction_queue = machine_direction_queue; |
mborchers | 13:34f7f783ad24 | 6 | this->imu_queue_velocity = imu_queue_velocity; |
mborchers | 13:34f7f783ad24 | 7 | init(); |
mborchers | 13:34f7f783ad24 | 8 | } |
mborchers | 13:34f7f783ad24 | 9 | |
mborchers | 13:34f7f783ad24 | 10 | void MachineDirectionController::init() { |
mborchers | 13:34f7f783ad24 | 11 | timer_velocity_sampling_time=0.01; |
mborchers | 13:34f7f783ad24 | 12 | |
mborchers | 13:34f7f783ad24 | 13 | l_Ki=0.1*timer_velocity_sampling_time; |
mborchers | 13:34f7f783ad24 | 14 | } |
mborchers | 13:34f7f783ad24 | 15 | |
mborchers | 13:34f7f783ad24 | 16 | void MachineDirectionController::check_queues() { |
mborchers | 13:34f7f783ad24 | 17 | velocity_set_event = machine_direction_queue->get(0); |
mborchers | 13:34f7f783ad24 | 18 | if (velocity_set_event.status == osEventMessage) { |
mborchers | 13:34f7f783ad24 | 19 | velocity_set = *(float*)velocity_set_event.value.p; |
mborchers | 13:34f7f783ad24 | 20 | } |
mborchers | 13:34f7f783ad24 | 21 | |
mborchers | 13:34f7f783ad24 | 22 | velocity_current_event = imu_queue_velocity->get(0); |
mborchers | 13:34f7f783ad24 | 23 | if (velocity_current_event.status == osEventMessage) { |
mborchers | 13:34f7f783ad24 | 24 | velocity_current = *(float *)velocity_current_event.value.p; |
mborchers | 13:34f7f783ad24 | 25 | } |
mborchers | 13:34f7f783ad24 | 26 | } |
mborchers | 13:34f7f783ad24 | 27 | |
mborchers | 13:34f7f783ad24 | 28 | void MachineDirectionController::cylic_control() { |
mborchers | 13:34f7f783ad24 | 29 | check_queues(); |
mborchers | 13:34f7f783ad24 | 30 | |
mborchers | 13:34f7f783ad24 | 31 | Vorsteuerung=88.316*velocity_set+175.17; |
mborchers | 13:34f7f783ad24 | 32 | l_e = velocity_set-velocity_current; |
mborchers | 13:34f7f783ad24 | 33 | l_esum = l_esum + l_e; |
mborchers | 13:34f7f783ad24 | 34 | |
mborchers | 13:34f7f783ad24 | 35 | PI_Regler =l_Kp*l_e+l_Ki * l_esum; |
mborchers | 13:34f7f783ad24 | 36 | |
mborchers | 13:34f7f783ad24 | 37 | l_output=Vorsteuerung+PI_Regler; |
mborchers | 13:34f7f783ad24 | 38 | |
mborchers | 13:34f7f783ad24 | 39 | l_PWM = 1500+l_output; |
mborchers | 13:34f7f783ad24 | 40 | |
mborchers | 13:34f7f783ad24 | 41 | if(l_PWM<1500) { |
mborchers | 13:34f7f783ad24 | 42 | l_PWM = 1500; |
mborchers | 13:34f7f783ad24 | 43 | l_esum = l_esum-2*l_e; |
mborchers | 13:34f7f783ad24 | 44 | } else if(l_PWM>2000) { |
mborchers | 13:34f7f783ad24 | 45 | l_PWM = 2000; |
mborchers | 13:34f7f783ad24 | 46 | l_esum = l_esum-2*l_e; |
mborchers | 13:34f7f783ad24 | 47 | } else if(velocity_set < 0.1) { |
mborchers | 13:34f7f783ad24 | 48 | l_PWM = 1500; |
mborchers | 13:34f7f783ad24 | 49 | } |
mborchers | 13:34f7f783ad24 | 50 | |
mborchers | 13:34f7f783ad24 | 51 | pwmOut->pulsewidth_us(1700); |
mborchers | 13:34f7f783ad24 | 52 | //pwmOut.pulsewidth_us(l_PWM); |
mborchers | 13:34f7f783ad24 | 53 | } |