2022年2月3日
ホームポジションを設定する方法(各種言語の場合)
DOBOTには、任意に設定できるホームポジションと呼ばれる座標があります。ホームコマンド(ホームポジションへ移動する動作)を実行した際に基準とする座標であり、座標のズレをある程度リセットすることができます。
各言語によって使用するAPI(関数)の名前等が異なりますが、流れとしては「パラメーターの設定」→「ホームコマンド」の実行になります。ホームポジションのパラメーターの設定とホームコマンドの実行部分は赤字で記載しています。プログラムの作成方法や実行方法は各種言語のテキストを参照してください。
Pythonのサンプルプログラム
import DobotDllType as dType from DobotDllType import PTPMode, JC, DobotConnect api = dType.load() ret, fwtype, version = dType.ConnectDobot(api, "", 115200) if not ret == DobotConnect.DobotConnect_NoError: print("Could not connect to DOBOT") exit() # 初期設定 dType.SetCmdTimeout(api, 3000) dType.SetQueuedCmdClear(api) dType.SetQueuedCmdStartExec(api) deviceName = "DOBOT Magician" dType.SetDeviceName(api, deviceName) # ホームポジションの座標を設定 dType.SetHOMEParams(api, 100, -200, 0, 0, True) # アームをホームポジションへ移動 dType.SetHOMECmdEx(api, 0, True) # DOBOT接続解除 dType.SetQueuedCmdStopExec(api) dType.DisconnectDobot(api)
C言語のサンプルプログラム
#include "stdafx.h" #include#include #include #include "../DobotDll/DobotDll.h" int main(int argc, char *argv[]) { // Dobotに接続する char fwType[60]; char version[60]; float time[60]; int ret = ConnectDobot("COM3", 115200, fwType, version, time); if (ret != DobotConnect_NoError) { printf("Could not connect to DOBOT.\n"); return 0; } // 初期設定 SetCmdTimeout(3000); const char deviceName[] = "Dobot Magician"; SetDeviceName(deviceName); char deviceSN[64]; GetDeviceName(deviceSN, sizeof(deviceSN)); uint64_t cmdIndex = 0; // ホームポジションの座標を設定 HOMEParams homeParam; homeParam.x = 100; homeParam.y = -200; homeParam.z = 0; homeParam.r = 0; SetHOMEParams(&homeParam, false, &cmdIndex); // コマンド構造体の変数宣言 HOMECmd cmd; memset(&cmd, 0, sizeof(cmd)); PTPCmd ptpCmd; memset(&ptpCmd, 0, sizeof(ptpCmd)); // キューコマンドの最後の番号 uint64_t CommandIndex = 0; uint64_t cmdIdx = 0; // アームをホームポジションへ移動 SetHOMECmd(&cmd, true, &CommandIndex); do { cmdIdx = 0; if (GetQueuedCmdCurrentIndex(&cmdIdx) != 0) Sleep(100); } while (cmdIdx < CommandIndex); // Dobot接続解除 DisconnectDobot(); return 0; }
C#のサンプルプログラム
using System; using System.Text; using DobotClientDemo.CPlusDll; namespace sample00 { class Program { static void Main(string[] args) { // DOBOTを接続する StringBuilder fwType = new StringBuilder(60); StringBuilder version = new StringBuilder(60); int ret = DobotDll.ConnectDobot("", 115200, fwType, version); if (ret != (int)DobotConnect.DobotConnect_NoError) { Console.WriteLine("Could not connect to DOBOT."); return; } // 初期設定 DobotDll.SetCmdTimeout(3000); string deviceName = "Dobot Magician"; DobotDll.SetDeviceName(deviceName); StringBuilder deviceSN = new StringBuilder(64); DobotDll.GetDeviceName(deviceSN, 64); UInt64 cmdIndex = 0; // ホームポジションの座標を設定 HOMEParams homeParam; homeParam.x = 100; homeParam.y = -200; homeParam.z = 0; homeParam.r = 0; DobotDll.SetHOMEParams(ref homeParam, false, ref cmdIndex); //インスタンス生成 HOMECmd cmd = new HOMECmd(); PTPCmd ptpCmd = new PTPCmd(); // キューコマンドの最後の番号 ulong CommandIndex = 0; ulong cmdIdx = 0; //アームをホームポジションへ移動 DobotDll.SetHOMECmd(ref cmd, true, ref CommandIndex); do { cmdIdx = 0; if (DobotDll.GetQueuedCmdCurrentIndex(ref cmdIdx) != 0) { System.Threading.Thread.Sleep(100); } } while (cmdIdx < CommandIndex); // DOBOT接続解除 DobotDll.DisconnectDobot(); } } }
Javaのサンプルプログラム
package sample; import com.sun.jna.Memory; import com.sun.jna.Pointer; import com.sun.jna.ptr.IntByReference; import CPlusDll.DobotDll; import CPlusDll.DobotDll.DobotConnectResult; import CPlusDll.DobotDll.HOMECmd; import CPlusDll.DobotDll.HOMEParams; import CPlusDll.DobotDll.JOGCommonParams; import CPlusDll.DobotDll.JOGCoordinateParams; import CPlusDll.DobotDll.JOGJointParams; import CPlusDll.DobotDll.PTPCmd; import CPlusDll.DobotDll.PTPCommonParams; import CPlusDll.DobotDll.PTPCoordinateParams; import CPlusDll.DobotDll.PTPJointParams; import CPlusDll.DobotDll.PTPJumpParams; import CPlusDll.DobotDll.PTPMode; public class Sample00 { public static void main(String[] args) throws InterruptedException { // DOBOTを接続する Pointer portName = new Memory(60); portName.setString(0, ""); Pointer fwType = new Memory(60); Pointer version = new Memory(60); int ret = DobotDll.instance.ConnectDobot(portName, 115200, fwType, version); if (DobotConnectResult.NoError.equals(ret) != true) { Msg("Could not connect to DOBOT."); return; } // 初期設定 DobotDll.instance.SetCmdTimeout(3000);// ミリ秒 DobotDll.instance.SetQueuedCmdClear(); DobotDll.instance.SetQueuedCmdStartExec(); Pointer deviceName = new Memory(64); deviceName.setString(0, "Dobot Magician"); DobotDll.instance.SetDeviceName(deviceName); Pointer deviceSN = new Memory(64); DobotDll.instance.GetDeviceName(deviceSN, 64); IntByReference cmdIndex = new IntByReference(); // ホームポジションの座標を設定 HOMEParams homeParam = new HOMEParams(); homeParam.x = 100; homeParam.y = -200; homeParam.z = 0; homeParam.r = 0; DobotDll.instance.SetHOMEParams(homeParam, false, cmdIndex); // インスタンスを生成 HOMECmd cmd = new HOMECmd(); PTPCmd ptpCmd = new PTPCmd(); // キューコマンドの最後の番号 IntByReference commandIndex = new IntByReference(); IntByReference cmdIdx = new IntByReference(); // アームをホームポジションへ移動 DobotDll.instance.SetHOMECmd(cmd, true, commandIndex); do { cmdIdx.setValue(0); if (DobotDll.instance.GetQueuedCmdCurrentIndex(cmdIdx) != 0) { Thread.sleep(100); } } while (cmdIdx.getValue() < commandIndex.getValue()); // DOBOT接続解除 DobotDll.instance.SetQueuedCmdClear(); DobotDll.instance.DisconnectDobot(); } private static void Msg(String string) { System.out.println(string); } }
(2022/02/01 現在)