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.
XBee.cpp@1:7f0b90daef14, 2015-08-21 (annotated)
- Committer:
 - inst
 - Date:
 - Fri Aug 21 04:51:52 2015 +0000
 - Revision:
 - 1:7f0b90daef14
 - Parent:
 - 0:7e177131730d
 - Child:
 - 2:869012d317b5
 
y evol
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| inst | 0:7e177131730d | 1 | #include "mbed.h" | 
| inst | 0:7e177131730d | 2 | #include "I2CDevice.h" | 
| inst | 0:7e177131730d | 3 | #include "XBee.h" | 
| inst | 1:7f0b90daef14 | 4 | #include "Math.h" | 
| inst | 1:7f0b90daef14 | 5 | #include "Steering.h" | 
| inst | 1:7f0b90daef14 | 6 | #include "Command.h" | 
| inst | 0:7e177131730d | 7 | |
| inst | 1:7f0b90daef14 | 8 | const size_t XBee::mNumOfDivDirection = 8; | 
| inst | 1:7f0b90daef14 | 9 | const float XBee::mDutyTable[] = { | 
| inst | 1:7f0b90daef14 | 10 | 0.4f, 0.85f, 0.85f, 0.85f | 
| inst | 1:7f0b90daef14 | 11 | }; | 
| inst | 1:7f0b90daef14 | 12 | // 右回りがプラスで左回りがマイナス | 
| inst | 1:7f0b90daef14 | 13 | const float XBee::mRollCoeffTable[] = { | 
| inst | 1:7f0b90daef14 | 14 | -0.85f, 0.85f, -0.4f, 0.4f | 
| inst | 1:7f0b90daef14 | 15 | }; | 
| inst | 1:7f0b90daef14 | 16 | |
| inst | 1:7f0b90daef14 | 17 | XBee::XBee( char address ) : I2CDevice( address ){ | 
| inst | 1:7f0b90daef14 | 18 | mMoveDirection_rad = 0; | 
| inst | 1:7f0b90daef14 | 19 | mMoveDuty = 1.0f; | 
| inst | 1:7f0b90daef14 | 20 | mRollCoeff = 0; | 
| inst | 1:7f0b90daef14 | 21 | mActionType = Command::STOP; | 
| inst | 0:7e177131730d | 22 | } | 
| inst | 0:7e177131730d | 23 | |
| inst | 0:7e177131730d | 24 | void XBee::read(){ | 
| inst | 1:7f0b90daef14 | 25 | char buf[ 3 ] = { 0 }; | 
| inst | 1:7f0b90daef14 | 26 | I2CDevice::mI2C->read( mAddress, buf, 3 ); | 
| inst | 1:7f0b90daef14 | 27 | |
| inst | 1:7f0b90daef14 | 28 | mActionType = static_cast< Command::ActionType >( buf[ 0 ] ); | 
| inst | 1:7f0b90daef14 | 29 | |
| inst | 1:7f0b90daef14 | 30 | switch ( mActionType ){ | 
| inst | 1:7f0b90daef14 | 31 | case Command::STOP: | 
| inst | 1:7f0b90daef14 | 32 | break; | 
| inst | 1:7f0b90daef14 | 33 | |
| inst | 1:7f0b90daef14 | 34 | case Command::MOVE: | 
| inst | 1:7f0b90daef14 | 35 | mMoveDirection_rad = 2.0f * gPI / mNumOfDivDirection * buf[ 1 ]; | 
| inst | 1:7f0b90daef14 | 36 | mMoveDuty = mDutyTable[ buf[ 2 ] ]; | 
| inst | 1:7f0b90daef14 | 37 | break; | 
| inst | 1:7f0b90daef14 | 38 | |
| inst | 1:7f0b90daef14 | 39 | case Command::ROLL: | 
| inst | 1:7f0b90daef14 | 40 | mRollCoeff = mRollCoeffTable[ buf[ 1 ] ]; | 
| inst | 1:7f0b90daef14 | 41 | break; | 
| inst | 1:7f0b90daef14 | 42 | |
| inst | 1:7f0b90daef14 | 43 | default: | 
| inst | 1:7f0b90daef14 | 44 | mActionType = Command::STOP; | 
| inst | 1:7f0b90daef14 | 45 | break; | 
| inst | 1:7f0b90daef14 | 46 | } | 
| inst | 1:7f0b90daef14 | 47 | } | 
| inst | 1:7f0b90daef14 | 48 | |
| inst | 1:7f0b90daef14 | 49 | Command XBee::generateCommand(){ | 
| inst | 1:7f0b90daef14 | 50 | return Command( mActionType, mMoveDirection_rad, mMoveDuty, mRollCoeff ); | 
| inst | 1:7f0b90daef14 | 51 | } |