4 dof robotic arm use of AX12 code
Dependents: 4dofRoboticArmAX12
Fork of AX12 by
Revision 1:cb08e032ef91, committed 2014-04-01
- Comitter:
- aimen
- Date:
- Tue Apr 01 06:22:23 2014 +0000
- Parent:
- 0:db8f063d50f0
- Commit message:
- no change to lib. It is making me do this to publish
Changed in this revision
AX12.cpp | Show annotated file Show diff for this revision Revisions of this file |
AX12.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/AX12.cpp Wed Oct 05 12:08:21 2011 +0000 +++ b/AX12.cpp Tue Apr 01 06:22:23 2014 +0000 @@ -22,7 +22,6 @@ */ #include "AX12.h" -#include "mbed.h" AX12::AX12(PinName tx, PinName rx, int ID, int baud) : _ax12(tx,rx) { @@ -64,14 +63,10 @@ } // 1023 / 300 * degrees - short goal = (1023 * degrees) / 300; -#ifdef AX12_DEBUG - printf("SetGoal to 0x%x\n",goal); -#endif + short goal = (1023 * degrees) / 300; data[0] = goal & 0xff; // bottom 8 bits - data[1] = goal >> 8; // top 8 bits - + data[1] = goal >> 8; // top 8 bits // write the packet, return the error code int rVal = write(_ID, AX12_REG_GOAL_POSITION, 2, data, reg_flag); @@ -423,15 +418,10 @@ int AX12::write(int ID, int start, int bytes, char* data, int flag) { // 0xff, 0xff, ID, Length, Intruction(write), Address, Param(s), Checksum - char TxBuf[16]; char sum = 0; char Status[6]; -#ifdef AX12_WRITE_DEBUG - printf("\nwrite(%d,0x%x,%d,data,%d)\n",ID,start,bytes,flag); -#endif - // Build the TxPacket first in RAM, then we'll send in one go #ifdef AX12_WRITE_DEBUG printf("\nInstruction Packet\n Header : 0xFF, 0xFF\n"); @@ -444,18 +434,10 @@ TxBuf[2] = ID; sum += TxBuf[2]; -#ifdef AX12_WRITE_DEBUG - printf(" ID : %d\n",TxBuf[2]); -#endif - // packet Length TxBuf[3] = 3+bytes; sum += TxBuf[3]; -#ifdef AX12_WRITE_DEBUG - printf(" Length : %d\n",TxBuf[3]); -#endif - // Instruction if (flag == 1) { TxBuf[4]=0x04; @@ -465,41 +447,24 @@ sum += TxBuf[4]; } -#ifdef AX12_WRITE_DEBUG - printf(" Instruction : 0x%x\n",TxBuf[4]); -#endif - // Start Address TxBuf[5] = start; sum += TxBuf[5]; -#ifdef AX12_WRITE_DEBUG - printf(" Start : 0x%x\n",TxBuf[5]); -#endif - // data for (char i=0; i<bytes ; i++) { TxBuf[6+i] = data[i]; sum += TxBuf[6+i]; - -#ifdef AX12_WRITE_DEBUG - printf(" Data : 0x%x\n",TxBuf[6+i]); -#endif - } // checksum TxBuf[6+bytes] = 0xFF - sum; -#ifdef AX12_WRITE_DEBUG - printf(" Checksum : 0x%x\n",TxBuf[6+bytes]); -#endif - // Transmit the packet in one burst with no pausing - for (int i = 0; i < (7 + bytes) ; i++) { - _ax12.putc(TxBuf[i]); + for (int i = 0; i < (7 + bytes); i++) { + _ax12.putc(TxBuf[i]); } - + // Wait for data to transmit wait (0.00002); @@ -528,19 +493,7 @@ wait (1.0/_baud); timeout++; } - - // Build the TxPacket first in RAM, then we'll send in one go -#ifdef AX12_WRITE_DEBUG - printf("\nStatus Packet\n Header : 0x%X, 0x%X\n",Status[0],Status[1]); - printf(" ID : %d\n",Status[2]); - printf(" Length : %d\n",Status[3]); - printf(" Error : 0x%x\n",Status[4]); - printf(" Checksum : 0x%x\n",Status[5]); -#endif - - } - return(Status[4]); // return error code }
--- a/AX12.h Wed Oct 05 12:08:21 2011 +0000 +++ b/AX12.h Tue Apr 01 06:22:23 2014 +0000 @@ -20,16 +20,16 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - #ifndef MBED_AX12_H #define MBED_AX12_H #include "mbed.h" +#include "SerialHalfDuplex.h" -//#define AX12_WRITE_DEBUG 0 -//#define AX12_READ_DEBUG 0 -//#define AX12_TRIGGER_DEBUG 0 -//#define AX12_DEBUG 0 +#define AX12_WRITE_DEBUG 0 +#define AX12_READ_DEBUG 0 +#define AX12_TRIGGER_DEBUG 0 +#define AX12_DEBUG 0 #define AX12_REG_ID 0x3 #define AX12_REG_BAUD 0x4 @@ -183,6 +183,7 @@ int read(int ID, int start, int length, char* data); int write(int ID, int start, int length, char* data, int flag=0); + char *itoa(short int n ); private :