terry LAI / Mbed 2 deprecated ESDC2014-pwm

Dependencies:   mbed

Fork of ESDC2014 by terry LAI

Files at this revision

API Documentation at this revision

Comitter:
TonyYI
Date:
Tue Jul 01 10:59:33 2014 +0000
Child:
1:cbec1283a16a
Commit message:
2014

Changed in this revision

buzzer.cpp Show annotated file Show diff for this revision Revisions of this file
buzzer.h Show annotated file Show diff for this revision Revisions of this file
camera_platform.cpp Show annotated file Show diff for this revision Revisions of this file
camera_platform.h Show annotated file Show diff for this revision Revisions of this file
communication.cpp Show annotated file Show diff for this revision Revisions of this file
communication.h Show annotated file Show diff for this revision Revisions of this file
compass.cpp Show annotated file Show diff for this revision Revisions of this file
compass.h Show annotated file Show diff for this revision Revisions of this file
define.h Show annotated file Show diff for this revision Revisions of this file
lifter.cpp Show annotated file Show diff for this revision Revisions of this file
lifter.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
port.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/buzzer.cpp	Tue Jul 01 10:59:33 2014 +0000
@@ -0,0 +1,47 @@
+/******************************************************
+
+****┏┓          ┏┓
+**┏┛┻━━━━━━┛┻┓
+**┃                 ┃
+**┃      ━━━      ┃
+**┃  ┳┛       ┗┳ ┃
+**┃                 ┃
+**┃ '''    ┻   ''' ┃
+**┃                 ┃
+**┗━━┓       ┏━━┛
+*******┃       ┃
+*******┃       ┃
+*******┃       ┃
+*******┃       ┗━━━━━━━━┓
+*******┃                      ┃━┓
+*******┃      NO BUG          ┏━┛
+*******┃                      ┃
+*******┗━┓  ┓  ┏━┏━┓  ━┛
+***********┃  ┛  ┛    ┃  ┛  ┛
+***********┃  ┃  ┃    ┃  ┃  ┃
+***********┗━┛━┛     ┗━┛━┛
+
+This part is added by project ESDC2014 of CUHK team.
+All the code with this header are under GPL open source license.
+This program is running on Mbed Platform 'mbed LPC1768' avaliable in 'http://mbed.org'.
+**********************************************************/
+
+#include "buzzer.h"
+
+Buzzer::Buzzer(MyDigitalOut* buzzer)
+{
+    this->_buzzer = buzzer;
+    *_buzzer = 1;
+}
+
+Buzzer::~Buzzer(){}
+
+void Buzzer::buzzerON()
+{
+    *_buzzer = 0;
+}
+
+void Buzzer::buzzerOFF()
+{
+    *_buzzer = 1;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/buzzer.h	Tue Jul 01 10:59:33 2014 +0000
@@ -0,0 +1,46 @@
+/******************************************************
+
+****┏┓          ┏┓
+**┏┛┻━━━━━━┛┻┓
+**┃                 ┃
+**┃      ━━━      ┃
+**┃  ┳┛       ┗┳ ┃
+**┃                 ┃
+**┃ '''    ┻   ''' ┃
+**┃                 ┃
+**┗━━┓       ┏━━┛
+*******┃       ┃
+*******┃       ┃
+*******┃       ┃
+*******┃       ┗━━━━━━━━┓
+*******┃                      ┃━┓
+*******┃      NO BUG          ┏━┛
+*******┃                      ┃
+*******┗━┓  ┓  ┏━┏━┓  ━┛
+***********┃  ┛  ┛    ┃  ┛  ┛
+***********┃  ┃  ┃    ┃  ┃  ┃
+***********┗━┛━┛     ┗━┛━┛
+
+This part is added by project ESDC2014 of CUHK team.
+All the code with this header are under GPL open source license.
+This program is running on Mbed Platform 'mbed LPC1768' avaliable in 'http://mbed.org'.
+**********************************************************/
+
+#ifndef _BUZZER_H
+#define _BUZZER_H
+
+#include "define.h"
+#include "mbed.h"
+
+class Buzzer
+{
+public:
+    Buzzer(MyDigitalOut* buzzer);
+    ~Buzzer();
+    void buzzerON();
+    void buzzerOFF();
+private:
+    MyDigitalOut* _buzzer; 
+};
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/camera_platform.cpp	Tue Jul 01 10:59:33 2014 +0000
@@ -0,0 +1,206 @@
+/******************************************************
+
+****┏┓          ┏┓
+**┏┛┻━━━━━━┛┻┓
+**┃                 ┃
+**┃      ━━━      ┃
+**┃  ┳┛       ┗┳ ┃
+**┃                 ┃
+**┃ '''    ┻   ''' ┃
+**┃                 ┃
+**┗━━┓       ┏━━┛
+*******┃       ┃
+*******┃       ┃
+*******┃       ┃
+*******┃       ┗━━━━━━━━┓
+*******┃                      ┃━┓
+*******┃      NO BUG          ┏━┛
+*******┃                      ┃
+*******┗━┓  ┓  ┏━┏━┓  ━┛
+***********┃  ┛  ┛    ┃  ┛  ┛
+***********┃  ┃  ┃    ┃  ┃  ┃
+***********┗━┛━┛     ┗━┛━┛
+
+This part is added by project ESDC2014 of CUHK team.
+All the code with this header are under GPL open source license.
+This program is running on Mbed Platform 'mbed LPC1768' avaliable in 'http://mbed.org'.
+**********************************************************/
+#include "camera_platform.h"
+
+//public
+Camera_platform::Camera_platform(MyPwmOut* _pwmRoll, MyPwmOut* _pwmPitch, MyPwmOut* _pwmYaw)
+{
+    this->_pwmRoll = _pwmRoll;
+    this->_pwmPitch = _pwmPitch;
+    this->_pwmYaw = _pwmYaw;
+    
+    _roll_angle = _pitch_angle = _yaw_angle = 0;
+}
+
+Camera_platform::~Camera_platform()
+{
+    delete _pwmRoll;
+    delete _pwmPitch;
+    delete _pwmYaw;
+}
+
+void Camera_platform::cameraPlatformMove(uint16_t move_dis, uint8_t move_dir, uint16_t rotate_dis, uint8_t rotate_dir)
+{
+    float _degree = rotate_dis / 100;
+    
+    if((rotate_dir & 0xc0) == 0xc0 && (rotate_dir & 0x20) == 0x20) //roll
+    {
+        if((rotate_dir & 0x10) == 0) //roll left
+        {
+            setRollLeft(_degree);
+        }
+        else //roll right
+        {
+            setRollRight(_degree);
+        }
+    }
+    if((rotate_dir & 0xc0) == 0xc0 && (rotate_dir & 0x08) == 0x08) //pitch
+    {
+        if((rotate_dir & 0x04) == 0) //pitch down
+        {
+            setPitchDown(_degree);
+        }
+        else //pitch up
+        {
+            setPitchUp(_degree);
+        }
+    }
+    if((rotate_dir & 0xc0) == 0xc0 && (rotate_dir & 0x02) == 0x02) //yaw
+    {
+        if((rotate_dir & 0x01) == 0) //yaw counter clockwise
+        {
+            setYawCClock(_degree);
+        }
+        else //yaw right
+        {
+            setYawClock(_degree);
+        }
+    }
+}  
+void Camera_platform::setRollLeft(float _degree)
+{
+    setPWM(computePwmValue(_degree, 0, ROLL), ROLL);
+}
+void Camera_platform::setRollRight(float _degree)
+{
+    setPWM(computePwmValue(_degree, 1, ROLL), ROLL);
+}
+void Camera_platform::setPitchUp(float _degree)
+{
+    setPWM(computePwmValue(_degree, 1, PITCH), PITCH);
+}
+void Camera_platform::setPitchDown(float _degree)
+{
+    setPWM(computePwmValue(_degree, 0, PITCH), PITCH);
+}
+void Camera_platform::setYawClock(float _degree)
+{
+    dir = 1;
+    setPWM(computePwmValue(_degree, 1, YAW), YAW);
+}
+void Camera_platform::setYawCClock(float _degree)
+{
+    dir = 0;
+    setPWM(computePwmValue(_degree, 0, YAW), YAW);
+}
+void Camera_platform::resetCameraPlatform()
+{
+    setPWM(ROLL_MID, ROLL);
+    setPWM(PITCH_MID, PITCH);
+    setPWM(YAW_MID, YAW);
+}
+
+//private
+void Camera_platform::setPWM(uint16_t _pwm_value_us, uint8_t _pwm_channel) //0 is roll, 1 is pitch, 2 is yaw
+{
+    switch(_pwm_channel)
+    {
+        case ROLL:
+        _pwmRoll->pulsewidth_us(_pwm_value_us);
+        break;
+        case PITCH:
+        _pwmPitch->pulsewidth_us(_pwm_value_us);
+        break;
+        case YAW:
+        _pwmYaw->pulsewidth_us(_pwm_value_us);
+        break;
+        default:
+        break;
+    }
+    wait_ms(800);
+}
+uint16_t Camera_platform::computePwmValue(float _degree, uint8_t _dir, uint8_t _pwm_channel) //0 is left/up/clock, 1 is right/down/cclock
+{
+    uint16_t return_value = 0;
+    
+    switch(_pwm_channel)
+    {
+        case ROLL:
+        if(_dir == 0)
+        {
+            _roll_angle -= _degree;
+            if(_roll_angle < ROLL_ANGLE_MIN)
+            {
+                _roll_angle = ROLL_ANGLE_MIN;
+            }
+        }
+        else if(_dir == 1)
+        {
+            _roll_angle += _degree;
+            if(_roll_angle > ROLL_ANGLE_MAX)
+            {
+                _roll_angle = ROLL_ANGLE_MAX;
+            }
+        }
+        return_value = (uint16_t)(ROLL_MID + _roll_angle * ROLL_USPD);
+        break;
+        case PITCH:
+        if(_dir == 0)
+        {
+            _pitch_angle -= _degree;
+            if(_pitch_angle < PITCH_ANGLE_MIN)
+            {
+                _pitch_angle = PITCH_ANGLE_MIN;
+            }
+        }
+        else if(_dir == 1)
+        {
+            _pitch_angle += _degree;
+            if(_pitch_angle > PITCH_ANGLE_MAX)
+            {
+                _pitch_angle = PITCH_ANGLE_MAX;
+            }
+        }
+        return_value = (uint16_t)(PITCH_MID + _pitch_angle * PITCH_USPD);
+        break;
+        case YAW:
+        if(_dir == 0)
+        {
+            _yaw_angle += _degree;
+            if(_yaw_angle > YAW_ANGLE_MAX)
+            {
+                _yaw_angle = YAW_ANGLE_MAX;
+            }
+        }
+        else if(_dir == 1)
+        {
+            _yaw_angle -= _degree;
+            if(_yaw_angle < YAW_ANGLE_MIN)
+            {
+                _yaw_angle = YAW_ANGLE_MIN;
+            }
+        }
+        
+        return_value = (uint16_t)(YAW_MID + _yaw_angle * YAW_USPD);
+        break;
+        default:
+        break;
+    }
+    
+    return return_value;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/camera_platform.h	Tue Jul 01 10:59:33 2014 +0000
@@ -0,0 +1,98 @@
+/******************************************************
+
+****┏┓          ┏┓
+**┏┛┻━━━━━━┛┻┓
+**┃                 ┃
+**┃      ━━━      ┃
+**┃  ┳┛       ┗┳ ┃
+**┃                 ┃
+**┃ '''    ┻   ''' ┃
+**┃                 ┃
+**┗━━┓       ┏━━┛
+*******┃       ┃
+*******┃       ┃
+*******┃       ┃
+*******┃       ┗━━━━━━━━┓
+*******┃                      ┃━┓
+*******┃      NO BUG          ┏━┛
+*******┃                      ┃
+*******┗━┓  ┓  ┏━┏━┓  ━┛
+***********┃  ┛  ┛    ┃  ┛  ┛
+***********┃  ┃  ┃    ┃  ┃  ┃
+***********┗━┛━┛     ┗━┛━┛
+
+This part is added by project ESDC2014 of CUHK team.
+All the code with this header are under GPL open source license.
+This program is running on Mbed Platform 'mbed LPC1768' avaliable in 'http://mbed.org'.
+**********************************************************/
+#include "mbed.h"
+#include "define.h"
+
+#ifndef _CAMERA_PLATFORM_H
+#define _CAMERA_PLATFORM_H
+
+/*
+PwmOut camera_platform_pwmRoll(p24);
+PwmOut camera_platform_pwmPitch(p26);
+PwmOut camera_platform_pwmYaw(p25);
+*/
+
+#define ROLL_MID 1500
+#define ROLL_LOW 1000
+#define ROLL_HIGH 2000
+#define ROLL_ANGLE_MAX 90
+#define ROLL_ANGLE_MIN -90
+#define ROLL_USPD (2000-1500)/180
+
+#define PITCH_MID 1500
+#define PITCH_LOW 1300
+#define PITCH_HIGH 2200
+#define PITCH_ANGLE_MAX 90
+#define PITCH_ANGLE_MIN -25
+#define PITCH_USPD (2200-1300)/115
+
+#define YAW_MID 1400
+#define YAW_LOW 600
+#define YAW_HIGH 2200
+#define YAW_ANGLE_MAX 90
+#define YAW_ANGLE_MIN -90
+#define YAW_USPD (2200-600)/180 //us per degree => 500/90
+
+#define ROLL 0
+#define PITCH 1
+#define YAW 2
+
+class Camera_platform
+{
+public:
+    Camera_platform(MyPwmOut* _pwmRoll, MyPwmOut* _pwmPitch, MyPwmOut* _pwmYaw);
+    ~Camera_platform();
+    
+    void cameraPlatformMove(uint16_t move_dis, uint8_t move_dir, uint16_t rotate_dis, uint8_t rotate_dir);
+    
+    void setRollLeft(float _degree);
+    void setRollRight(float _degree);
+    void setPitchUp(float _degree);
+    void setPitchDown(float _degree);
+    void setYawClock(float _degree);
+    void setYawCClock(float _degree);
+    
+    void resetCameraPlatform();
+    
+    uint8_t dir;
+    uint8_t angle;
+    
+private:
+    MyPwmOut* _pwmRoll;
+    MyPwmOut* _pwmPitch;
+    MyPwmOut* _pwmYaw;
+    
+    float _roll_angle; //record the current roll angle. need to divide 100 to convert to degree
+    float _pitch_angle; //record the current pitch angle. need to divide 100 to convert to degree
+    float _yaw_angle; //record the current yaw angle. need to divide 100 to convert to degree
+    
+    void setPWM(uint16_t _pwm_value_us, uint8_t _pwm_channel); //0 is roll, 1 is pitch, 2 is yaw
+    uint16_t computePwmValue(float _degree, uint8_t _dir, uint8_t _pwm_channel); //0 is left/up/clock, 1 is right/down/cclock
+};
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/communication.cpp	Tue Jul 01 10:59:33 2014 +0000
@@ -0,0 +1,510 @@
+/******************************************************
+
+****┏┓          ┏┓
+**┏┛┻━━━━━━┛┻┓
+**┃                 ┃
+**┃      ━━━      ┃
+**┃  ┳┛       ┗┳ ┃
+**┃                 ┃
+**┃ '''    ┻   ''' ┃
+**┃                 ┃
+**┗━━┓       ┏━━┛
+*******┃       ┃
+*******┃       ┃
+*******┃       ┃
+*******┃       ┗━━━━━━━━┓
+*******┃                      ┃━┓
+*******┃      NO BUG          ┏━┛
+*******┃                      ┃
+*******┗━┓  ┓  ┏━┏━┓  ━┛
+***********┃  ┛  ┛    ┃  ┛  ┛
+***********┃  ┃  ┃    ┃  ┃  ┃
+***********┗━┛━┛     ┗━┛━┛
+
+This part is added by project ESDC2014 of CUHK team.
+All the code with this header are under GPL open source license.
+This program is running on Mbed Platform 'mbed LPC1768' avaliable in 'http://mbed.org'.
+**********************************************************/
+#include <communication.h>
+
+Communication::Communication(MySerial* _DEBUG, MySerial *_IntelToMbed, MySerial *_MbedToArduino)
+:compass(SDA, SCL)
+{
+    this->_DEBUG = _DEBUG;
+    this->_IntelToMbed = _IntelToMbed;
+    this->_MbedToArduino = _MbedToArduino;
+    
+    init();
+}
+
+Communication::~Communication()
+{
+    delete[] buffer_IntelToMbed;
+    delete[] buffer_MbedToArduino;
+    delete _DEBUG;
+    delete _IntelToMbed;
+    delete _MbedToArduino;
+}
+
+void Communication::init()
+{
+    buffer_IntelToMbed = new uint8_t[BUFFER_SIZE];
+    buffer_MbedToArduino = new uint8_t[BUFFER_SIZE];
+    in_IntelToMbed = 0;
+    out_IntelToMbed = 0;
+    in_MbedToArduino = 0;
+    out_MbedToArduino = 0;
+    state_IntelToMbed = 0;
+    state_MbedToArduino = 0;
+    check_sum = 0;
+    info_ok_IntelToMbed = 0;
+    info_ok_MbedToArduino = 0;
+}
+
+uint8_t Communication::getByte(uint8_t communication_type)
+{
+    uint8_t _x = 0;
+    if(communication_type == 0)
+    {
+        _x = buffer_IntelToMbed[out_IntelToMbed++];
+        if(out_IntelToMbed == BUFFER_SIZE)
+        {
+            out_IntelToMbed &= 0x0000;
+        }
+    }
+    else if(communication_type == 1)
+    {
+        _x = buffer_MbedToArduino[out_MbedToArduino++];
+        if(out_MbedToArduino == BUFFER_SIZE)
+        {
+            out_MbedToArduino &= 0x0000;
+        }
+    }
+    return _x;
+}
+
+uint16_t Communication::get2Bytes(uint8_t communication_type)
+{
+    uint8_t byte1 = getByte(communication_type);
+    uint8_t byte2 = getByte(communication_type);
+    return uint16_t((byte1 << 8) | byte2);
+}
+
+void Communication::putByte(uint8_t _x, uint8_t _i)
+{
+    //Serial.write(_x);//For Arduino
+     //For Mbed
+    if(_i == 0) //_DEBUG
+    {
+        _DEBUG->putc(_x);
+    }
+    else if(_i == 1) //IntelToMbed
+    {
+        _IntelToMbed->putc(_x);
+    }
+    else if(_i == 2) //MbedToArduino
+    {
+        _MbedToArduino->putc(_x);
+    }
+}
+
+void Communication::put2Bytes(uint16_t _x, uint8_t _i)
+{
+    putByte(uint8_t(_x >> 8), _i);
+    putByte(uint8_t(_x & 0x0f), _i);
+}
+
+void Communication::putToBuffer(uint8_t _x, uint8_t communication_type)
+{
+    if(communication_type == 0)
+    {
+        buffer_IntelToMbed[in_IntelToMbed++] = _x;
+        if(in_IntelToMbed == BUFFER_SIZE)
+        {
+            in_IntelToMbed &= 0x00;
+        }
+    }
+    else if(communication_type == 1)
+    {
+        buffer_MbedToArduino[in_MbedToArduino++] = _x;
+        if(in_MbedToArduino == BUFFER_SIZE)
+        {
+            in_MbedToArduino &= 0x00;
+        }
+    }
+}
+
+void Communication::parseMessage()
+{
+    if(in_IntelToMbed != out_IntelToMbed)
+    {
+        uint8_t _x = getByte(0);
+        switch(state_IntelToMbed)
+        {
+            case 0: //checking starter
+            {
+                if(DEBUG_ON)
+                {
+                    _DEBUG->printf("Communication::parseMessage(). Checking STARTER...\r\n");
+                }
+                check_sum = 0;
+
+                if(_x == STARTER || _x == COMPASS_STARTER)
+                {
+                    state_IntelToMbed++;
+                }
+                else
+                {
+                    state_IntelToMbed = 0;
+                    if(DEBUG_ON)
+                    {
+                        _DEBUG->printf("Communication::parseMessage(). ERROR when checking STARTER: %x.\r\n", _x);
+                    }
+                }
+                break;
+            }
+
+            case 1: //checking action_type
+            {
+                if(DEBUG_ON)
+                {
+                    _DEBUG->printf("Communication::parseMessage(). Checking ACTION_TYPE...\r\n");
+                }
+                check_sum += _x;
+                action_type = _x;
+                if(action_type == 0 || action_type == 1 || action_type == 2 || action_type == 3)
+                {
+                    state_IntelToMbed++;
+                }
+                else
+                {
+                    state_IntelToMbed = 0;
+                    if(DEBUG_ON)
+                    {
+                        _DEBUG->printf("Communication::parseMessage(). ERROR when checking ACTION_TYPE: %x.\r\n", action_type);
+                    }
+                }
+                break;
+            }
+
+            case 2: //move_dis upper 4 bits
+            {
+                if(DEBUG_ON)
+                {
+                    _DEBUG->printf("Communication::parseMessage(). Checking MOVE_DIS upper 4 bits...\r\n");
+                }
+                check_sum += _x;
+                move_dis = _x << 8;
+                state_IntelToMbed++;
+                break;
+            }
+
+            case 3: //move_dis lower 4 bits
+            {
+                if(DEBUG_ON)
+                {
+                    _DEBUG->printf("Communication::parseMessage(). Checking MOVE_DIS lower 4 bits...\r\n");
+                }
+                check_sum += _x;
+                move_dis |=  _x;
+                state_IntelToMbed++;
+                break;
+            }
+
+            case 4: //move_dir
+            {
+                if(DEBUG_ON)
+                {
+                    _DEBUG->printf("Communication::parseMessage(). Checking MOVE_DIR...\r\n");
+                }
+                check_sum += _x;
+                move_dir = _x;
+                if((action_type == 0 && (move_dir == 0 || move_dir == 1 || move_dir == 2 || move_dir == 3)) || (action_type == 1 && (move_dir == 0 || move_dir == 2)) || action_type == 2 || action_type == 3)
+                {
+                    state_IntelToMbed++;
+                }
+                else
+                {
+                    state_IntelToMbed = 0;
+                    if(DEBUG_ON)
+                    {
+                        _DEBUG->printf("Communication::parseMessage(). ERROR when checking MOVE_DIR: %x.\r\n", move_dir);
+                    }
+                }
+                break;
+            }
+
+            case 5: //rotate_dis upper 4 bits
+            {
+                if(DEBUG_ON)
+                {
+                    _DEBUG->printf("Communication::parseMessage(). Checking ROTATE_DIS upper 4 bits...\r\n");
+                }
+                check_sum += _x;
+                rotate_dis = _x << 8;
+                state_IntelToMbed++;
+                break;
+            }
+
+            case 6: //rotate_dis lower 4 bits
+            {
+                if(DEBUG_ON)
+                {
+                    _DEBUG->printf("Communication::parseMessage(). Checking ROTATE_DIS lower 4 bits...\r\n");
+                }
+                check_sum += _x;
+                rotate_dis |= _x;
+                state_IntelToMbed++;
+                break;
+            }
+
+            case 7: //rotate_dir
+            {
+                if(DEBUG_ON)
+                {
+                    _DEBUG->printf("Communication::parseMessage(). Checking MOVE_DIR...\r\n");
+                }
+                check_sum += _x;
+                rotate_dir = _x;
+                if(action_type == 3 || (action_type == 1 && ((rotate_dir >> 6) == 0)) || ((action_type == 0 || action_type == 2) && ((rotate_dir >> 6) == 3)))
+                {
+                    state_IntelToMbed++;
+                }
+                else
+                {
+                    state_IntelToMbed = 0;
+                    if(DEBUG_ON)
+                    {
+                        _DEBUG->printf("Communication::parseMessage(). ERROR when checking ROTATE_DIR: %x.\r\n", rotate_dir);
+                    }
+                }
+                break;
+            }
+
+            case 8: //check_sum
+            {
+                if(DEBUG_ON)
+                {
+                    _DEBUG->printf("Communication::parseMessage(). Checking CHECK_SUM...\r\n");
+                }
+                if(check_sum == _x)
+                {
+                    switch(action_type)
+                    {
+                        case 0: //car movement
+                        info_ok_IntelToMbed = 1;
+                        break;
+
+                        case 1: //lifter
+                        info_ok_IntelToMbed = 2;
+                        break;
+
+                        case 2: //camera platform
+                        info_ok_IntelToMbed = 3;
+                        break;
+                        
+                        case 3: //compass
+                        info_ok_IntelToMbed = 4;
+                        break;
+
+                        default:
+                        info_ok_IntelToMbed = 0; //not ok
+                        break;
+                    }
+                }
+                else
+                {
+                    if(DEBUG_ON)
+                    {
+                        _DEBUG->printf("Communication::parseMessage(). ERROR when checking CHECK_SUM: %x.\r\n", check_sum);
+                    }
+                }
+                state_IntelToMbed  = 0;
+                break;
+            }
+
+            default:
+            {
+                state_IntelToMbed = 0;
+                break;
+            }
+        }
+    }
+}
+
+void Communication::forwardMessage()
+{
+    //message structure is defined in source/motion_platform/intel_board/lib/message.h
+    uint8_t i = out_IntelToMbed - 9; //message size is 9 bytes
+    putByte(buffer_IntelToMbed[i++], 2); //starter, 2 means MbedToArduino
+    putByte(buffer_IntelToMbed[i++], 2); //action_type
+    putByte(buffer_IntelToMbed[i++], 2); //move_dis
+    putByte(buffer_IntelToMbed[i++], 2);
+    putByte(buffer_IntelToMbed[i++], 2); //move_dir
+    putByte(buffer_IntelToMbed[i++], 2); //rotate_dis
+    putByte(buffer_IntelToMbed[i++], 2);
+    putByte(buffer_IntelToMbed[i++], 2); //rotate_dir
+    putByte(buffer_IntelToMbed[i++], 2); //checksum
+}
+
+void Communication::ACK(Lifter* lifter, Camera_platform* camera_platform)
+{
+    if(action_type == 0) //car movement
+    {
+        while(info_ok_MbedToArduino != 1)
+        {
+            if(in_MbedToArduino != out_MbedToArduino)
+            {
+                uint8_t _x = getByte(1);
+                switch(state_MbedToArduino)
+                {
+                    case 0: //checking starter
+                    {
+                        //putByte('0', 1);
+                        if(_x == STARTER)
+                        {
+                            state_MbedToArduino++;
+                        }
+                        else
+                        {
+                            state_MbedToArduino = 0;
+                        }
+                        break;
+                    }
+
+                    case 1: //checking 'O'
+                    {
+                        //putByte('1', 1);
+                        if(_x == 0x4f) //O
+                        {
+                            state_MbedToArduino++;
+                        }
+                        else
+                        {
+                            state_MbedToArduino = 0;
+                        }
+                        break;
+                    }
+
+                    case 2: //checking 'K'
+                    {
+                        //putByte('2', 1);
+                        if(_x == 0x4b) //K
+                        {
+                            state_MbedToArduino++;
+                        }
+                        else
+                        {
+                            state_MbedToArduino = 0;
+                        }
+                        break;
+                    }
+
+                    case 3: //checking check_sum_MbedToArduino
+                    {
+                        //putByte('3', 1);
+                        if(_x == 0x9a) //checksum
+                        {
+                            info_ok_MbedToArduino = 1;
+                        }
+                        
+                        state_MbedToArduino = 0;
+                        break;
+                    }
+
+                    default:
+                    {
+                        state_MbedToArduino = 0;
+                        info_ok_MbedToArduino = 0;
+                        break;
+                    }
+                }
+            }
+        }
+    }
+    else if(action_type == 1) //lifter
+    {
+        uint32_t pulseCountOld = 0;
+        uint32_t pulseCountNew = 0;
+        while(!lifter->isStopped())
+        {
+            pulseCountOld = lifter->pulseCount;
+            wait_ms(50);
+            pulseCountNew = lifter->pulseCount;
+            if(pulseCountOld == pulseCountNew)
+            {
+                break;
+            }
+        }
+    }
+    else if(action_type == 3)
+    {
+        HMC5883L compasss(SDA, SCL);
+        campass_degree = 0;
+        unsigned short data1 = compasss.get_degree(); 
+        wait(0.5);
+        unsigned short data2 = compasss.get_degree(); 
+
+        campass_degree = (data1 + data2) / 2;
+
+        uint8_t temp1,temp2;
+        temp1 = campass_degree;
+        temp2 = campass_degree>>8;
+        putByte(COMPASS_STARTER ,1); //1 means IntelToMbed
+        putByte(temp1 ,1); //O
+        putByte(temp2 ,1); //K
+        putByte(0x9a ,1); //check_sum = 0xaf + 0x4b = 0x9a
+    
+        return;
+    } 
+    
+    putByte(STARTER ,1); //1 means IntelToMbed
+    putByte(0x4f ,1); //O
+    putByte(0x4b ,1); //K
+    putByte(0x9a ,1); //check_sum = 0xaf + 0x4b = 0x9a
+}
+
+uint8_t Communication::getInfoOK(uint8_t communication_type)
+{
+    if(communication_type == 0)
+    {
+        return info_ok_IntelToMbed;
+    }
+    else if(communication_type == 1)
+    {
+        return info_ok_MbedToArduino;
+    }
+    return 0; //error
+}
+
+void Communication::resetInfoOK(uint8_t communication_type)
+{
+    if(communication_type == 0)
+    {
+        info_ok_IntelToMbed = 0;
+    }
+    else if(communication_type == 1)
+    {
+        info_ok_MbedToArduino = 0;
+    }
+}
+
+uint16_t Communication::getMoveDis()
+{
+    return move_dis;
+}
+
+uint16_t Communication::getRotateDis()
+{
+    return rotate_dis;
+}
+
+uint8_t Communication::getMoveDir()
+{
+    return move_dir;
+}
+
+uint8_t Communication::getRotateDir()
+{
+    return rotate_dir;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/communication.h	Tue Jul 01 10:59:33 2014 +0000
@@ -0,0 +1,96 @@
+/******************************************************
+
+****┏┓          ┏┓
+**┏┛┻━━━━━━┛┻┓
+**┃                 ┃
+**┃      ━━━      ┃
+**┃  ┳┛       ┗┳ ┃
+**┃                 ┃
+**┃ '''    ┻   ''' ┃
+**┃                 ┃
+**┗━━┓       ┏━━┛
+*******┃       ┃
+*******┃       ┃
+*******┃       ┃
+*******┃       ┗━━━━━━━━┓
+*******┃                      ┃━┓
+*******┃      NO BUG          ┏━┛
+*******┃                      ┃
+*******┗━┓  ┓  ┏━┏━┓  ━┛
+***********┃  ┛  ┛    ┃  ┛  ┛
+***********┃  ┃  ┃    ┃  ┃  ┃
+***********┗━┛━┛     ┗━┛━┛
+
+This part is added by project ESDC2014 of CUHK team.
+All the code with this header are under GPL open source license.
+This program is running on Mbed Platform 'mbed LPC1768' avaliable in 'http://mbed.org'.
+**********************************************************/
+
+/*
+The communication protocol is inside source/intel_board/lib/message.h
+*/
+#include "lifter.h"
+#include "camera_platform.h"
+#include "mbed.h"
+#include "compass.h"
+#include "buzzer.h"
+
+#ifndef _COMMUNICATION_H
+#define _COMMUNICATION_H
+
+#define BUFFER_SIZE 1024
+#define STARTER 0x7e
+#define COMPASS_STARTER 0x7d
+
+#define DEBUG_ON 1
+
+class Communication
+{
+public:
+    Communication(MySerial* _DEBUG, MySerial *_IntelToMbed, MySerial *_MbedToArduino);
+    ~Communication();
+
+    void putToBuffer(uint8_t _x, uint8_t communication_type); //0 is IntelToMbed, 1 is MbedTOArduino
+    uint8_t getByte(uint8_t communication_type); //0 is IntelToMbed, 1 is MbedTOArduino
+    uint16_t get2Bytes(uint8_t communication_type); //0 is IntelToMbed, 1 is MbedTOArduino
+    void putByte(uint8_t _x, uint8_t _i); //_i = 0 is _DEBUG, _i = 1 is _IntelToMbed, _i = 2 is _MbedToArduino
+    void put2Bytes(uint16_t _x, uint8_t _i);
+    void parseMessage();
+    void forwardMessage(); //forward the message to the Arduino
+    void ACK(Lifter* lifter, Camera_platform* camera_platform); //send ACK back to the intel board
+
+    uint8_t getInfoOK(uint8_t communication_type); //0 is IntelToMbed, 1 is MbedTOArduino
+    void resetInfoOK(uint8_t communication_type); //0 is IntelToMbed, 1 is MbedTOArduino
+    uint16_t getMoveDis();
+    uint16_t getRotateDis();
+    uint8_t getMoveDir();
+    uint8_t getRotateDir();
+
+    unsigned short campass_degree;
+    HMC5883L compass;
+private:
+    void init();
+    uint8_t* buffer_IntelToMbed;
+    uint8_t* buffer_MbedToArduino;
+    uint16_t in_IntelToMbed;
+    uint16_t out_IntelToMbed;
+    uint16_t in_MbedToArduino;
+    uint16_t out_MbedToArduino;
+    uint8_t state_IntelToMbed;
+    uint8_t state_MbedToArduino;
+    uint8_t check_sum;
+    uint8_t info_ok_IntelToMbed; //0 is not ok, 1 is car, 2 is lifter and 3 is camera platform
+    uint8_t info_ok_MbedToArduino; //0 is not ok, 1 is ok
+    
+    uint8_t action_type;
+    uint16_t move_dis;
+    uint8_t move_dir;
+    uint16_t rotate_dis;
+    uint8_t rotate_dir;
+    
+    MySerial *_DEBUG;
+    MySerial *_IntelToMbed;
+    MySerial *_MbedToArduino;
+};
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/compass.cpp	Tue Jul 01 10:59:33 2014 +0000
@@ -0,0 +1,180 @@
+#include "compass.h"
+
+HMC5883L::HMC5883L(PinName sda, PinName scl): i2c(sda, scl)
+{
+    //100KHz, as specified by the datasheet.
+    char rx;
+
+    
+    i2c.frequency(100000);
+    //Testar depois com 400KHz
+    //==========================================================================================================
+    // Read chip_id
+    //==========================================================================================================
+    rx = Read(HMC5883L_IDENT_A);
+    if (rx != 0x48)//ID do chip
+        printf("\ninvalid chip id %d\r\n", rx); 
+     
+    //==========================================================================================================
+    // Let's set the Configuration Register A
+    //==========================================================================================================
+    // This register set's the number of samples averaged per measurement output, the rate at which data is written
+    // to all three data output registers and the measurement flow of the device.
+    // -------------------------------------------------------
+    // |CRA7 CRA6   CRA5   CRA4   CRA3   CRA2   CRA1   CRA0  |
+    // |(1)  MA1(1) MA0(1) DO2(1) DO1(0) DO0(0) MS1(0) MS0(0)| -> This is the default value
+    // -------------------------------------------------------
+    // CRA7 -> we have to clear this bit for correct operation                                      (0)
+    // CRA6 to CRA5 -> Let's select the maximum number of samples averaged per measurement output   (11)
+    // CRA4 to CRA2 -> Also let's select the maximum data output rate                               (110)
+    // CRA1 to CRA0 -> The measurement flow is defined to normal                                    (00)
+    // -------------------------------------------------------
+    // |CRA7 CRA6   CRA5   CRA4   CRA3   CRA2   CRA1   CRA0  |
+    // |(0)  MA1(1) MA0(1) DO2(1) DO1(1) DO0(0) MS1(0) MS0(0)| -> This is the new value, 0x78 in hex
+    // -------------------------------------------------------
+    //Write(HMC5883L_CONFIG_A,0x78);
+    //Write(HMC5883L_CONFIG_A,0x70);
+        
+    //==========================================================================================================
+    // The Configuration Register B is set to 0010 0000 by default, this is a +/- 1.3 Ga sensor field range and
+    // the gain of LSB/gauss is 1090. This is the maximum value, so let's leave it like that.
+    //==========================================================================================================
+    //Datasheet page 13. I will explain later
+    //Write(HMC5883L_CONFIG_B,0x20);
+    //Write(HMC5883L_CONFIG_B,0xA0);
+  
+    //==========================================================================================================
+    // Let's set the Mode Register
+    //==========================================================================================================
+    // This register set's the operation mode, from continuous-measurements mode, single-measurement mode and idle mode.
+    // We will set to Continuouse-measurement mode, so the device continuously performs measurements and places the
+    // result in the data register
+    // ---------------------------------------------
+    // |MR7  MR6  MR5  MR4  MR3  MR2  MR1    MR0   |  -> This is the new value, 0x78 in hex, we are going to change
+    // |(1)  (0)  (0)  (0)  (0)  (0)  MD1(0) MD0(1)|     the MD1 and MD0 to 00 and clear the MR7 for correct operation.
+    // ---------------------------------------------     The final value is 0000 0000 (0x00).
+    Write(HMC5883L_MODE,0x00);
+     wait(1);
+     setDeclination(DECLINATIONANGLE);
+}
+
+
+void HMC5883L::Write(char reg_address, char data)
+{
+    char tx[2];
+    tx[0]=reg_address;
+    tx[1]=data;
+
+    i2c.write(HMC5883L_I2C_WRITE,tx,2);
+}
+
+char HMC5883L::Read(char data)
+{
+    char tx = data;
+    char rx;
+
+    i2c.write(HMC5883L_I2C_WRITE, &tx, 1);
+    i2c.read(HMC5883L_I2C_READ, &rx, 1);
+    return rx;
+}
+
+void HMC5883L::MultiByteRead(char address, char* output, int size) 
+{
+    i2c.write(HMC5883L_I2C_WRITE, &address, 1);      //tell it where to read from
+    i2c.read(HMC5883L_I2C_READ, output, size);     //tell it where to store the data read
+}
+
+float HMC5883L::getMx()
+{
+    //return (x * m_Scale);
+    char lsb_byte = 0;
+    signed short msb_byte;
+
+    lsb_byte = Read(HMC5883L_X_MSB);
+    msb_byte = lsb_byte << 8;
+    msb_byte |= Read(HMC5883L_X_LSB);
+    return (float)msb_byte;
+    /*
+    char tx[1];
+    char rx[2];
+
+
+    tx[0]=HMC5883L_X_MSB;
+    i2c.write(HMC5883L_I2C_READ,tx,1);
+    i2c.read(HMC5883L_I2C_READ,rx,2);
+    return ((int)rx[0]<<8|(int)rx[1]);
+    */
+
+}
+
+float HMC5883L::getMy()
+{
+    //return (y * m_Scale);
+
+    char lsb_byte = 0;
+    signed short msb_byte;
+
+    lsb_byte = Read(HMC5883L_Y_MSB);
+    msb_byte = lsb_byte << 8;
+    msb_byte |= Read(HMC5883L_Y_LSB);
+    return (float)msb_byte;
+}
+
+
+float HMC5883L::getMz()
+{
+    //return (z * m_Scale);
+    
+    char lsb_byte = 0;
+    signed short msb_byte;
+
+    lsb_byte = Read(HMC5883L_Z_MSB);
+    msb_byte = lsb_byte << 8;
+    msb_byte |= Read(HMC5883L_Z_LSB);
+    return (float)msb_byte;
+ }
+ 
+
+void HMC5883L::setDeclination(float declinationAngle)
+{
+   this->declinationAngle=declinationAngle;
+ }
+ 
+ void HMC5883L::setOffset(int offset)
+{
+   this->offset=offset;
+ }
+ 
+unsigned short HMC5883L::get_degree()
+{
+    //return (z * m_Scale);
+    wait_ms(200);     
+
+        float x, y, z, heading;
+      x = getMx();
+        y = getMy();
+        z = getMz();
+        heading += declinationAngle;
+        
+        heading = atan2(y, x);
+        if(heading < 0) 
+            heading += 2*PI;
+        if(heading > 2*PI) 
+            heading -= 2*PI;
+        
+        heading = heading * 180 / PI;
+        
+//        heading+=90;
+        
+        heading+=offset;
+        if(heading>=360)
+        heading-=360;
+        
+        if(heading<180)
+        heading+=180;
+        else
+        heading-=180;
+        return heading;
+ }
+ 
+ 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/compass.h	Tue Jul 01 10:59:33 2014 +0000
@@ -0,0 +1,54 @@
+#ifndef HMC5883L_H
+#define HMC5883L_H
+
+#include "mbed.h"
+
+#define HMC5883L_IDENT_A        0x0A // In this case the identification register A is used to identify the devide. ASCII value H
+#define HMC5883L_I2C            0x1E // 7-bit address. 0x3C write, 0x3D read.
+#define HMC5883L_I2C_WRITE      0x3C // Same as (& 0xFE), ensure that the MSB bit is being set to zero (RW=0 -> Writing)
+#define HMC5883L_I2C_READ       0x3D // Same as (| 0x01), ensure that the MSB bit is being set to one  (RW=1 -> Reading)
+
+#define HMC5883L_CONFIG_A       0x00
+#define HMC5883L_CONFIG_B       0x01
+#define HMC5883L_MODE           0x02
+#define HMC5883L_STATUS         0x09
+
+#define HMC5883L_X_MSB          0x03
+#define HMC5883L_X_LSB          0x04
+#define HMC5883L_Z_MSB          0x05
+#define HMC5883L_Z_LSB          0x06
+#define HMC5883L_Y_MSB          0x07
+#define HMC5883L_Y_LSB          0x08
+#define PI       3.14159265
+#define SDA      p9
+#define SCL      p10
+
+#define DECLINATIONANGLE  -0.0457
+#define OFFSET 0
+
+#include <math.h>
+
+class HMC5883L 
+{
+
+public:
+
+    HMC5883L(PinName sda, PinName scl);
+    float getMx();
+    float getMy();
+    float getMz();
+    
+    void setDeclination(float declinationAngle);
+    void setOffset(int offset);
+    
+    unsigned short get_degree();
+private:
+    void Write(char reg_address, char data);
+    char Read(char data);
+    void MultiByteRead(char address, char* output, int size); 
+    I2C i2c;
+    float declinationAngle;
+    int offset;
+};
+
+#endif /* HMC5883L_H */
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/define.h	Tue Jul 01 10:59:33 2014 +0000
@@ -0,0 +1,37 @@
+/******************************************************
+
+****┏┓          ┏┓
+**┏┛┻━━━━━━┛┻┓
+**┃                 ┃
+**┃      ━━━      ┃
+**┃  ┳┛       ┗┳ ┃
+**┃                 ┃
+**┃ '''    ┻   ''' ┃
+**┃                 ┃
+**┗━━┓       ┏━━┛
+*******┃       ┃
+*******┃       ┃
+*******┃       ┃
+*******┃       ┗━━━━━━━━┓
+*******┃                      ┃━┓
+*******┃      NO BUG          ┏━┛
+*******┃                      ┃
+*******┗━┓  ┓  ┏━┏━┓  ━┛
+***********┃  ┛  ┛    ┃  ┛  ┛
+***********┃  ┃  ┃    ┃  ┃  ┃
+***********┗━┛━┛     ┗━┛━┛
+
+This part is added by project ESDC2014 of CUHK team.
+All the code with this header are under GPL open source license.
+This program is running on Mbed Platform 'mbed LPC1768' avaliable in 'http://mbed.org'.
+**********************************************************/
+#ifndef _DEFINE_H
+#define _DEFINE_H
+
+#define MyDigitalOut DigitalOut
+#define MyDigitalIn DigitalIn
+#define MySerial Serial
+#define MyPwmOut PwmOut
+#define MyInterruptIn InterruptIn
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lifter.cpp	Tue Jul 01 10:59:33 2014 +0000
@@ -0,0 +1,121 @@
+/******************************************************
+
+****┏┓          ┏┓
+**┏┛┻━━━━━━┛┻┓
+**┃                 ┃
+**┃      ━━━      ┃
+**┃  ┳┛       ┗┳ ┃
+**┃                 ┃
+**┃ '''    ┻   ''' ┃
+**┃                 ┃
+**┗━━┓       ┏━━┛
+*******┃       ┃
+*******┃       ┃
+*******┃       ┃
+*******┃       ┗━━━━━━━━┓
+*******┃                      ┃━┓
+*******┃      NO BUG          ┏━┛
+*******┃                      ┃
+*******┗━┓  ┓  ┏━┏━┓  ━┛
+***********┃  ┛  ┛    ┃  ┛  ┛
+***********┃  ┃  ┃    ┃  ┃  ┃
+***********┗━┛━┛     ┗━┛━┛
+
+This part is added by project ESDC2014 of CUHK team.
+All the code with this header are under GPL open source license.
+This program is running on Mbed Platform 'mbed LPC1768' avaliable in 'http://mbed.org'.
+**********************************************************/
+#include "lifter.h"
+
+Lifter::Lifter(MyDigitalOut* _enable, MyPwmOut* _pwmUp, MyPwmOut* _pwmDown, MyInterruptIn* _encoder_A, MyDigitalIn* _encoder_B)
+{
+    pulseCount = 0;
+    targetPulseCount = 0;
+    _dir = 0;
+    _stop = 0;
+    
+    this->_enable = _enable;
+    this->_pwmUp = _pwmUp;
+    this->_pwmDown = _pwmDown;
+    this->_encoder_A = _encoder_A;
+    this->_encoder_B = _encoder_B;
+    
+    setLifterStop();
+}
+
+Lifter::~Lifter()
+{
+    delete _enable;
+    delete _pwmUp;
+    delete _pwmDown;
+    delete _encoder_A; //6 pulse per round
+    delete _encoder_B; //5v is up, 0v is down. looks like no use
+}
+
+void Lifter::lifterUp(uint16_t mm)
+{
+    targetPulseCount = mm * RPMM;
+    //targetPulseCount = mm;
+    setLifterUp();
+}
+
+void Lifter::lifterDown(uint16_t mm)
+{
+    targetPulseCount = mm * RPMM;
+    //targetPulseCount = mm;
+    setLifterDown();
+}
+
+uint8_t Lifter::getDir()
+{
+    /*
+    if(*_encoder_B == 1) //up
+    {
+        return true;
+    }
+    else //down
+    {
+        return false;
+    }
+    */
+    return _dir;
+}
+uint8_t Lifter::isStopped()
+{
+    return _stop;
+}
+
+void Lifter::lifterMove(uint16_t move_dis, uint8_t move_dir, uint16_t rotate_dis, uint8_t rotate_dir)
+{
+    pulseCount = targetPulseCount = 0;
+    _stop = 0;
+    
+    if(_dir = move_dir == 0x00) //up
+    {
+        lifterUp(move_dis);
+    }
+    else if(_dir = move_dir == 0x02) //down
+    {
+        lifterDown(move_dis);
+    }
+}
+
+void Lifter::setLifterStop()
+{
+    *_enable = 0;
+    *_pwmUp = 1.0f;
+    *_pwmDown = 1.0f;
+    _stop = 1;
+}
+void Lifter::setLifterUp()
+{
+    *_enable = 0;
+    *_pwmUp = 1.0f;
+    *_pwmDown = 0.0f;
+}
+void Lifter::setLifterDown()
+{
+    *_enable = 0;
+    *_pwmUp = 0.0f;
+    *_pwmDown = 1.0f;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lifter.h	Tue Jul 01 10:59:33 2014 +0000
@@ -0,0 +1,73 @@
+/******************************************************
+
+****┏┓          ┏┓
+**┏┛┻━━━━━━┛┻┓
+**┃                 ┃
+**┃      ━━━      ┃
+**┃  ┳┛       ┗┳ ┃
+**┃                 ┃
+**┃ '''    ┻   ''' ┃
+**┃                 ┃
+**┗━━┓       ┏━━┛
+*******┃       ┃
+*******┃       ┃
+*******┃       ┃
+*******┃       ┗━━━━━━━━┓
+*******┃                      ┃━┓
+*******┃      NO BUG          ┏━┛
+*******┃                      ┃
+*******┗━┓  ┓  ┏━┏━┓  ━┛
+***********┃  ┛  ┛    ┃  ┛  ┛
+***********┃  ┃  ┃    ┃  ┃  ┃
+***********┗━┛━┛     ┗━┛━┛
+
+This part is added by project ESDC2014 of CUHK team.
+All the code with this header are under GPL open source license.
+This program is running on Mbed Platform 'mbed LPC1768' avaliable in 'http://mbed.org'.
+**********************************************************/
+#include "mbed.h"
+#include "define.h"
+
+#ifndef _LIFTER_H
+#define _LIFTER_H
+
+/*
+DigitalOut lifter_enable(p23);
+PwmOut lifter_pwmUp(p21);
+PwmOut lifter_pwmDown(p22);
+DigitalIn lifter_encoder_A(p26);
+DigitalIn lifter_encoder_B(p25);
+*/
+
+//100 pulse => 8 mm
+#define RPMM 13 //pulseCount per mm
+
+class Lifter
+{
+public:
+    Lifter(MyDigitalOut* _enable, MyPwmOut* _pwmUp, MyPwmOut* _pwmDown, MyInterruptIn* encoder_A, MyDigitalIn* encoder_B);
+    ~Lifter();
+    void lifterUp(uint16_t mm);
+    void lifterDown(uint16_t mm);
+    void lifterMove(uint16_t move_dis, uint8_t move_dir, uint16_t rotate_dis, uint8_t rotate_dir);
+    uint8_t getDir();
+    uint8_t isStopped();
+    
+    uint32_t pulseCount;
+    uint32_t targetPulseCount;
+    
+    void setLifterStop();
+    void setLifterUp();
+    void setLifterDown();
+    
+private:
+    MyDigitalOut* _enable;
+    MyPwmOut* _pwmUp;
+    MyPwmOut* _pwmDown;
+    MyInterruptIn* _encoder_A; //6 pulse per round
+    MyDigitalIn* _encoder_B; //5v is up, 0v is down. looks like no use
+    uint8_t _dir;
+    uint8_t _stop; //0 means moving, 1 means stopped
+};
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Jul 01 10:59:33 2014 +0000
@@ -0,0 +1,75 @@
+/******************************************************
+
+****┏┓          ┏┓
+**┏┛┻━━━━━━┛┻┓
+**┃                 ┃
+**┃      ━━━      ┃
+**┃  ┳┛       ┗┳ ┃
+**┃                 ┃
+**┃ '''    ┻   ''' ┃
+**┃                 ┃
+**┗━━┓       ┏━━┛
+*******┃       ┃
+*******┃       ┃
+*******┃       ┃
+*******┃       ┗━━━━━━━━┓
+*******┃                      ┃━┓
+*******┃      NO BUG          ┏━┛
+*******┃                      ┃
+*******┗━┓  ┓  ┏━┏━┓  ━┛
+***********┃  ┛  ┛    ┃  ┛  ┛
+***********┃  ┃  ┃    ┃  ┃  ┃
+***********┗━┛━┛     ┗━┛━┛
+
+This part is added by project ESDC2014 of CUHK team.
+All the code with this header are under GPL open source license.
+This program is running on Mbed Platform 'mbed LPC1768' avaliable in 'http://mbed.org'.
+**********************************************************/
+#include "mbed.h"
+#include "communication.h"
+#include "port.h"
+
+int main()
+{
+    init_PORT();
+  
+    while(1)
+    {
+        com.parseMessage();
+        if(com.getInfoOK(0) == 1) //car
+        {
+            buzzer.buzzerON();
+            com.forwardMessage();
+            com.ACK(&lifter, &camera_platform);
+            com.resetInfoOK(0);
+            com.resetInfoOK(1);
+            buzzer.buzzerOFF();
+        }
+        else if(com.getInfoOK(0) == 2) //lifter
+        {
+            buzzer.buzzerON();
+            lifter.lifterMove(com.getMoveDis(), com.getMoveDir(), com.getRotateDis(), com.getRotateDir());
+            com.ACK(&lifter, &camera_platform);
+            com.resetInfoOK(0);
+            com.resetInfoOK(1);
+            buzzer.buzzerOFF();
+        }
+        else if(com.getInfoOK(0) == 3) //camera_platform
+        {
+            buzzer.buzzerON();
+            camera_platform.cameraPlatformMove(com.getMoveDis(), com.getMoveDir(), com.getRotateDis(), com.getRotateDir());
+            com.ACK(&lifter, &camera_platform);
+            com.resetInfoOK(0);
+            com.resetInfoOK(1);
+            buzzer.buzzerOFF();
+        }
+        else if(com.getInfoOK(0) == 4) //compass
+        {
+            buzzer.buzzerON();
+            com.ACK(&lifter, &camera_platform);
+            com.resetInfoOK(0);
+            com.resetInfoOK(1);
+            buzzer.buzzerOFF();
+        }
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Jul 01 10:59:33 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/0b3ab51c8877
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/port.h	Tue Jul 01 10:59:33 2014 +0000
@@ -0,0 +1,114 @@
+/******************************************************
+
+****┏┓          ┏┓
+**┏┛┻━━━━━━┛┻┓
+**┃                 ┃
+**┃      ━━━      ┃
+**┃  ┳┛       ┗┳ ┃
+**┃                 ┃
+**┃ '''    ┻   ''' ┃
+**┃                 ┃
+**┗━━┓       ┏━━┛
+*******┃       ┃
+*******┃       ┃
+*******┃       ┃
+*******┃       ┗━━━━━━━━┓
+*******┃                      ┃━┓
+*******┃      NO BUG          ┏━┛
+*******┃                      ┃
+*******┗━┓  ┓  ┏━┏━┓  ━┛
+***********┃  ┛  ┛    ┃  ┛  ┛
+***********┃  ┃  ┃    ┃  ┃  ┃
+***********┗━┛━┛     ┗━┛━┛
+
+This part is added by project ESDC2014 of CUHK team.
+All the code with this header are under GPL open source license.
+This program is running on Mbed Platform 'mbed LPC1768' avaliable in 'http://mbed.org'.
+**********************************************************/
+#include "mbed.h"
+#include "define.h"
+
+#ifndef _PORT_H
+#define _PORT_H
+
+MyDigitalOut IntelToMbed_LED(LED1); //uart port LED between Intel Board and Mbed
+MyDigitalOut MbedToArduino_LED(LED2); //uart port LED between Mbed and Arduino
+MySerial DEBUG(USBTX, USBRX); //usb serial port between computer and Mbed
+MySerial IntelToMbed(p13, p14); //uart port between Intel Board and Mbed
+MySerial MbedToArduino(p28, p27); //uart port between Mbed and Arduino
+MyPwmOut lifter_pwmUp(p21);
+MyPwmOut lifter_pwmDown(p22);
+MyDigitalOut lifter_enable(p23);
+MyInterruptIn lifter_encoder_A(p18);
+MyDigitalIn lifter_encoder_B(p17);
+
+MyPwmOut camera_platform_pwmRoll(p24);//roll            min counter clockwise, max clockwise 
+MyPwmOut camera_platform_pwmPitch(p26);//pitch           min down,  max up,  mid 1700
+MyPwmOut camera_platform_pwmYaw(p25);//yaw             min right, max left, mid 1500
+
+MyDigitalOut buzzer_pin(p29);
+Buzzer buzzer(&buzzer_pin);
+
+Communication com(&DEBUG, &IntelToMbed, &MbedToArduino);
+Lifter lifter(&lifter_enable, &lifter_pwmUp, &lifter_pwmDown, &lifter_encoder_A, &lifter_encoder_B);
+Camera_platform camera_platform(&camera_platform_pwmRoll, &camera_platform_pwmPitch, &camera_platform_pwmYaw);
+
+void IntelToMbedRxHandler()
+{
+    //__disable_irq();//disable interupt when receiving data from XBEE_UART
+    uint8_t _x = IntelToMbed.getc();
+    com.putToBuffer(_x, 0); //function inside Communication::
+    //__enable_irq();
+}
+void MbedToArduinoRxHandler()
+{
+    //__disable_irq();//disable interupt when receiving data from XBEE_UART
+    uint8_t _x = MbedToArduino.getc();
+    com.putToBuffer(_x, 1); //function inside Communication::
+    //__enable_irq();
+}
+
+void LifterPulseHandler()
+{
+    if(lifter.pulseCount < lifter.targetPulseCount)
+    {
+        lifter.pulseCount++;
+        if(lifter.getDir() == 0) //up
+        {
+            lifter.setLifterUp();
+        }
+        else if(lifter.getDir() == 2)//down
+        {
+            lifter.setLifterDown();
+        }
+    }
+    else
+    {
+        lifter.targetPulseCount = 0;
+        lifter.pulseCount = 0;
+        lifter.setLifterStop();
+    }
+}
+
+void init_PORT() //used in main() function
+{
+    DEBUG.baud(9600);
+    
+    IntelToMbed.baud(9600);
+    IntelToMbed.attach(&IntelToMbedRxHandler); //serial interrupt function
+    
+    MbedToArduino.baud(9600);
+    MbedToArduino.attach(&MbedToArduinoRxHandler); //serial interrupt function
+    
+    lifter_encoder_A.fall(&LifterPulseHandler); //interrupt
+    
+    camera_platform_pwmRoll.period_ms(20); //20ms periodic, 1000us to 2000us
+    camera_platform_pwmPitch.period_ms(20); //20ms periodic, 1000us to 2000us
+    camera_platform_pwmYaw.period_ms(20); //20ms periodic, 1000us to 2000us
+    
+     camera_platform_pwmRoll.pulsewidth_us(ROLL_MID);
+    camera_platform_pwmPitch.pulsewidth_us(PITCH_MID);
+    camera_platform_pwmYaw.pulsewidth_us(YAW_MID);
+}
+
+#endif
\ No newline at end of file