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.
Fork of Dynamixel by
DynamixelBus.h
00001 /* Copyright (C) 2016 Telesensorics Inc, MIT License 00002 * 00003 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 00004 * and associated documentation files (the "Software"), to deal in the Software without restriction, 00005 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 00006 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 00007 * furnished to do so, subject to the following conditions: 00008 * 00009 * The above copyright notice and this permission notice shall be included in all copies or 00010 * substantial portions of the Software. 00011 * 00012 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 00013 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00014 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 00015 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00016 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00017 */ 00018 00019 00020 #ifndef __DYNAMIXEL_BUS_H__ 00021 #define __DYNAMIXEL_BUS_H__ 00022 00023 #include "mbed.h" 00024 00025 #include <vector> 00026 using namespace std; 00027 00028 00029 enum InstructionTable 00030 { 00031 instructionPing = 0x1, // no action. obtain status packet. 00032 instructionRead = 0x2, // write values in control table 00033 instructionWrite = 0x3, // read values in control table 00034 instructionWriteAction = 0x4, // write actions to be performed upon triggering 00035 instructionTriggerAction = 0x5, // trigger stored actions 00036 instructionReset = 0x6, // changes ALL control table vaalues to factory default 00037 instructionSyncWrite = 0x83 // write to many servos at once 00038 }; 00039 00040 00041 enum StatusCodes 00042 { 00043 statusValid = 0x80, // REVIEW: Not in spec. I am overloading this for Ping, such that a 0 return value = unit not found 00044 instructionError = 0x40, 00045 overloadError = 0x20, 00046 checksumError = 0x10, 00047 rangeError = 0x08, 00048 overheatingError = 0x04, 00049 angleLimitError = 0x02, 00050 inputVoltageError = 0x01 00051 }; 00052 00053 typedef unsigned char StatusCode; 00054 00055 typedef vector<unsigned char> CommBuffer; 00056 00057 typedef unsigned char ServoId; 00058 00059 typedef pair< ServoId, CommBuffer > SyncIdDataPair; 00060 00061 class DynamixelBus 00062 { 00063 public: 00064 DynamixelBus( PinName txUartPin, PinName rxUartPin, PinName txSelectPin, PinName rxSelectPin, int baud ); 00065 00066 StatusCode Ping( ServoId id ); 00067 StatusCode Read( ServoId id, unsigned char controlTableStart, unsigned char bytesToRead, CommBuffer& data ); 00068 StatusCode Write( ServoId id, unsigned char controlTableStart, const CommBuffer& dataToWrite ); 00069 StatusCode WriteAction( ServoId id, unsigned char controlTableStart, const CommBuffer& dataToWrite ); 00070 void TriggerAction( ServoId id ); 00071 StatusCode HardReset( ServoId id ); 00072 StatusCode SyncWrite( unsigned char controlTableStart, unsigned char bytesToWrite, vector<SyncIdDataPair>& data ); 00073 00074 private: 00075 unsigned char CalculateTxPacketChecksum( CommBuffer& packet ); 00076 StatusCode send_ping( ServoId id ); 00077 StatusCode send_write( ServoId id, unsigned char controlTableStart, const CommBuffer& dataToWrite ); 00078 StatusCode send_read( ServoId id, unsigned char controlTableStart, unsigned char bytesToRead, CommBuffer& data ); 00079 00080 private: 00081 Serial _uart; // The uart the servos live on. 00082 DigitalOut _txSelect; // Turn on to enable the tri-state buffer before sending data over the bus. Turn off when data has been sent. 00083 DigitalOut _rxSelect; // Turn on to enable the tri-state buffer before receiving data over the bus. Turn off when data has been received. 00084 00085 float _replyDelay; // The delay time between command being sent and response being sent by the servo. 00086 int _baud; // baud of all connected servos 00087 float _responseTimeout; 00088 }; 00089 00090 #endif // __DYNAMIXEL_BUS_H__
Generated on Thu Jul 14 2022 23:42:07 by
