Kristof T'Jonck / Mbed 2 deprecated proj2_car

Dependencies:   RemoteIR m3pi mbed-rtos mbed

Committer:
Kristof@LAPTOP-FT09DA9V
Date:
Wed May 10 09:33:18 2017 +0200
Revision:
8:aff4290aacff
Parent:
7:1d77c7e0208c
Child:
9:8c5229dfab82
added communication

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Kristof@LAPTOP-FT09DA9V.home 1:76cff32344d1 1 //
Kristof@LAPTOP-FT09DA9V.home 1:76cff32344d1 2 // Created by Kristof on 5/9/2017.
Kristof@LAPTOP-FT09DA9V.home 1:76cff32344d1 3 //
Kristof@LAPTOP-FT09DA9V.home 1:76cff32344d1 4
Kristof@LAPTOP-FT09DA9V.home 1:76cff32344d1 5 #include "Controller.h"
Kristof@LAPTOP-FT09DA9V.home 1:76cff32344d1 6
Kristof@LAPTOP-FT09DA9V 7:1d77c7e0208c 7 void Controller::runThread(){
Kristof@LAPTOP-FT09DA9V 7:1d77c7e0208c 8 lightCommunication->receiveData();
Kristof@LAPTOP-FT09DA9V 7:1d77c7e0208c 9 }
Kristof@LAPTOP-FT09DA9V 7:1d77c7e0208c 10
Kristof@LAPTOP-FT09DA9V.home 1:76cff32344d1 11 Controller::Controller() {
Kristof@LAPTOP-FT09DA9V.home 1:76cff32344d1 12 //constructor once to initialise
Kristof@LAPTOP-FT09DA9V 7:1d77c7e0208c 13 lightCommunication = new LightCommunication();
Kristof@LAPTOP-FT09DA9V.home 1:76cff32344d1 14 car = new m3pi();
Kristof@LAPTOP-FT09DA9V 8:aff4290aacff 15 receiveThread.start(callback(this,Controller::runThread));
Kristof@LAPTOP-FT09DA9V.home 1:76cff32344d1 16 ir_rx = new ReceiverIR(p21);
Kristof@LAPTOP-FT09DA9V 7:1d77c7e0208c 17
Kristof@LAPTOP-FT09DA9V.home 1:76cff32344d1 18 }
Kristof@LAPTOP-FT09DA9V.home 1:76cff32344d1 19
Kristof@LAPTOP-FT09DA9V.home 1:76cff32344d1 20 Controller::~Controller() {
Kristof@LAPTOP-FT09DA9V.home 1:76cff32344d1 21
Kristof@LAPTOP-FT09DA9V.home 1:76cff32344d1 22 }
Kristof@LAPTOP-FT09DA9V.home 1:76cff32344d1 23 int Controller::run() {
Kristof@LAPTOP-FT09DA9V.home 1:76cff32344d1 24
Kristof@LAPTOP-FT09DA9V 7:1d77c7e0208c 25 lightCommunication->mut.lock();
Kristof@LAPTOP-FT09DA9V 7:1d77c7e0208c 26 if (lightCommunication->needsToStop()){
Kristof@LAPTOP-FT09DA9V.home 1:76cff32344d1 27 car->stop();
Kristof@LAPTOP-FT09DA9V 7:1d77c7e0208c 28 lightCommunication->mut.unlock();
Kristof@LAPTOP-FT09DA9V.home 1:76cff32344d1 29 }else {
Kristof@LAPTOP-FT09DA9V 7:1d77c7e0208c 30 current_left = lightCommunication->getLeft(current_left);
Kristof@LAPTOP-FT09DA9V 7:1d77c7e0208c 31 current_right = lightCommunication->getRight(current_right);
Kristof@LAPTOP-FT09DA9V 7:1d77c7e0208c 32 lightCommunication->mut.unlock();
Kristof@LAPTOP-FT09DA9V.home 1:76cff32344d1 33 car->left_motor(current_left) ;
Kristof@LAPTOP-FT09DA9V.home 1:76cff32344d1 34 car->right_motor(current_right) ;
Kristof@LAPTOP-FT09DA9V.home 1:76cff32344d1 35 }
Kristof@LAPTOP-FT09DA9V.home 1:76cff32344d1 36 return 0;
Kristof@LAPTOP-FT09DA9V.home 1:76cff32344d1 37 }