PSL_2021 / servomotor_MX12_Lorenzo

Dependents:   PSL_ROBOT_lorenzo robot_lorenzo recepteur_mbed_os_6

Revision:
11:9bc7f5e2ccee
Parent:
10:ca9afe156ee1
Child:
12:acfd6c46954b
--- a/MX12.h	Sat Nov 06 16:56:46 2021 +0000
+++ b/MX12.h	Sat Nov 06 17:24:30 2021 +0000
@@ -82,24 +82,62 @@
  * @see https://emanual.robotis.com/docs/en/dxl/mx/mx-12w/
  * @see Dynamixel protocol v1.0 manual
  * @see https://emanual.robotis.com/docs/en/dxl/protocol1/
+ 
+@code
+ 
+#include "mbed.h"
+#include "MX12.h"
+
+#define SERVO_TX_PIN PC_4
+#define SERVO_RX_PIN PC_5
+#define SERVO_BAUD 115200
+#define SERVO_ID 1
+
+#define DELAY_1000ms 1000
+#define DELAY_1ms       1
+
+MX12 servo_bus(SERVO_TX_PIN, SERVO_RX_PIN, SERVO_BAUD);
+float relative_speed;
+
+int main()
+{
+    // Set speed of SERVO_ID servomotor to 10% 
+    // Send on servo_bus to SERVO_ID motor the instruction "moving speed"
+    // with parameter 0.1 (10% of maximum speed)
+    relative_speed = 0.1; 
+    servo_bus.SetSpeed(SERVO_ID, relative_speed);
+        
+    // wait for one second
+    thread_sleep_for(DELAY_1000ms);
+    
+    // set speed of SERVO_ID servomotor to 0% 
+    relative_speed = 0.0; 
+    servo_bus.SetSpeed(SERVO_ID, relative_speed);
+
+    // infinite loop 
+    while (true) thread_sleep_for(DELAY_1000ms);
+}
+
+@endcode
+ 
  *
  * @warning
  *
- *   Warning 1: error field of status packet if decoded by GetStatus() 
+ *   Error field of status packet if decoded by GetStatus() 
  *   Doxygen Release 1.7.2 returns an enumation type "Status". As several 
  *   errors can be reported simultaneously the type enum is not suitable 
  *   (B. Denis 11/2021).
  *
- * \bug
+ * @bug
  *
- *   Bug : _frame_pointer variable is used by private _ReadCallback() ISR 
+ *   Bug: _frame_pointer variable is used by private _ReadCallback() ISR 
  *   to store the current size for message (status packet) received from 
  *   servomotor. This variable is NOT initialised and NEVER reset to zero 
  *   at each new message.
  *
  *   Bug: GetStatus() method has a hazardous behavior because it provides 
  *   a result by reading the content of the variable _current_frame 
- *   which can be modified at any time by the private ISR _ReadCallback()  
+ *   which can be modified at any time by the private ISR _ReadCallback().
  *    
  */
 class MX12 
@@ -157,7 +195,7 @@
                                     in this exchange */
         unsigned char length;  /**< */
         unsigned char data[MX12_DATA_MAX_SIZE]; /**< */
-        unsigned char valid; /**< */
+        unsigned char valid;   /**< */
     };
 
     /** State of packet parser store which section of a status packet 
@@ -236,6 +274,32 @@
      *                   mot_id                      address   data
      *                                                        (len = N-1)
      * </PRE>
+     *
+     * Code simple
+     *
+     @code
+     * |Header1|Header2|Packet ID|Length|Instruction|Param1...ParamN|Checksum|
+     * |-------|-------|---------|------|-----------|---------------|--------|
+     * |  0xFF |  0xFF |Packet ID|Length|Instruction|Param1...ParamN| CHKSUM |
+     * | cmd[0]| cmd[1]|  cmd[2] |cmd[3]|  cmd[4]   |cmd[5]...      |        |
+     *                  \__  ___/                    \_  _/ \__  __/
+     *                     \/                          \/      \/
+     *                   mot_id                      address   data
+     *                                                        (len = N-1)
+     @endcode
+     *
+     * Code simple {.unparsed}
+     *
+     @code{.unparsed}
+     * |Header1|Header2|Packet ID|Length|Instruction|Param1...ParamN|Checksum|
+     * |-------|-------|---------|------|-----------|---------------|--------|
+     * |  0xFF |  0xFF |Packet ID|Length|Instruction|Param1...ParamN| CHKSUM |
+     * | cmd[0]| cmd[1]|  cmd[2] |cmd[3]|  cmd[4]   |cmd[5]...      |        |
+     *                  \__  ___/                    \_  _/ \__  __/
+     *                     \/                          \/      \/
+     *                   mot_id                      address   data
+     *                                                        (len = N-1)
+     @endcode
      */
     void rw(unsigned char mot_id, char address, char len, char *data);