Skip to content

Commit 6086fb3

Browse files
committed
update the example
Signed-off-by: Will Son <willson@robotis.com>
1 parent 28b1f13 commit 6086fb3

1 file changed

Lines changed: 32 additions & 21 deletions

File tree

examples/blender/openmanipulator_x/openmanipulator_x.ino

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
1-
/*******************************************************************************
2-
* Copyright 2016 ROBOTIS CO., LTD.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*******************************************************************************/
1+
// Copyright 2021 ROBOTIS CO., LTD.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// Example Environment
16+
//
17+
// - DYNAMIXEL: X series (except XL-320)
18+
// ID = 11, 12, 13, 14, 15, Baudrate = 4000000bps, Protocol 2.0
19+
// - Controller: OpenCR 1.0
20+
// - Library: DYNAMIXEL2Arduino
21+
// - Software: Blender 2.93.1
22+
// Arduino IDE
23+
// - https://emanual.robotis.com/docs/en/parts/interface/mkr_shield/#examples
24+
//
25+
// Author: David Park
1626

1727
#include <Dynamixel2Arduino.h>
1828

@@ -66,7 +76,7 @@ typedef struct sync_read_data {
6676
} __attribute__((packed)) sync_read_data_t;
6777

6878
// Sync Read Present Position
69-
const uint16_t ADDRESS_TO_SYNC_READ = 132;
79+
const uint16_t PRESENT_POSITION_ADDRESS = 132;
7080
const uint16_t LENGTH_TO_SYNC_READ = 4;
7181

7282
// Sync Read
@@ -81,7 +91,7 @@ typedef struct sync_write_data {
8191
} __attribute__((packed)) sync_write_data_t;
8292

8393
// Sync Write Goal Position
84-
const uint16_t ADDRESS_TO_SYNC_WRITE = 116;
94+
const uint16_t GOAL_POSITION_ADDRESS = 116;
8595
const uint16_t LENGTH_TO_SYNC_WRITE = 4;
8696

8797
// Sync Write
@@ -642,6 +652,7 @@ void loop()
642652
void InitDXL(int frame_time)
643653
{
644654
uint8_t index = 0;
655+
dxl.torqueOff(DXL_BROADCAST_ID);
645656

646657
// Ping DYNAMIXELs. If failed, check your Baudrate and pysical wiring connection.
647658
for (index = 0; index < NUMBER_OF_JOINT; index++)
@@ -650,17 +661,17 @@ void InitDXL(int frame_time)
650661
DEBUG_SERIAL.print("[ERROR] Failed to connect DYNAMIXEL ");
651662
DEBUG_SERIAL.println(DYNAMIXEL_ID[index]);
652663
} else {
653-
dxl.torqueOff(DYNAMIXEL_ID[index]);
654664
// Set the Drive Mode as Time-based mode.
655665
dxl.writeControlTableItem(DRIVE_MODE, DYNAMIXEL_ID[index], 4);
656666
// Lower Return Delay Time enhances the responsiveness.
657667
dxl.writeControlTableItem(RETURN_DELAY_TIME, DYNAMIXEL_ID[index], 0);
658668
dxl.setOperatingMode(DYNAMIXEL_ID[index], OP_POSITION);
659-
dxl.torqueOn(DYNAMIXEL_ID[index]);
660669
// Time-based should be larger than frame time.
661670
dxl.writeControlTableItem(PROFILE_VELOCITY, DYNAMIXEL_ID[index], frame_time);
662671
}
663672
}
673+
dxl.torqueOn(DXL_BROADCAST_ID);
674+
delay(100);
664675
}
665676

666677
// Initialize SyncRead packet in the structure
@@ -671,7 +682,7 @@ void InitSyncRead()
671682
sync_read_information.packet.p_buf = packet_buffer;
672683
sync_read_information.packet.buf_capacity = MAX_PACKET_BUFFER_LENGTH;
673684
sync_read_information.packet.is_completed = false;
674-
sync_read_information.addr = ADDRESS_TO_SYNC_READ;
685+
sync_read_information.addr = PRESENT_POSITION_ADDRESS;
675686
sync_read_information.addr_length = LENGTH_TO_SYNC_READ;
676687
sync_read_information.p_xels = sync_read_dynamixel_info;
677688
sync_read_information.xel_count = 0;
@@ -693,7 +704,7 @@ void InitSyncWrite()
693704

694705
sync_write_information.packet.p_buf = nullptr;
695706
sync_write_information.packet.is_completed = false;
696-
sync_write_information.addr = ADDRESS_TO_SYNC_WRITE;
707+
sync_write_information.addr = GOAL_POSITION_ADDRESS;
697708
sync_write_information.addr_length = LENGTH_TO_SYNC_WRITE;
698709
sync_write_information.p_xels = sync_write_dynamixel_info;
699710
sync_write_information.xel_count = 0;

0 commit comments

Comments
 (0)