Skip to content

Commit

Permalink
Merge pull request #91 from ziteh/develop
Browse files Browse the repository at this point in the history
Resolve #90
  • Loading branch information
ziteh authored Apr 2, 2022
2 parents 7137696 + 333523a commit 153d776
Show file tree
Hide file tree
Showing 4 changed files with 247 additions and 9 deletions.
1 change: 1 addition & 0 deletions RASDK.Arm/RASDK.Arm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
<Compile Include="Hiwin\ReturnCodeCheck.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RoboticArm.cs" />
<Compile Include="RoboticArmMotion.cs" />
<Compile Include="TMRobot\Default.cs" />
<Compile Include="TMRobot\SLogger.cs" />
<Compile Include="TMRobot\SocketClientObject.cs" />
Expand Down
38 changes: 38 additions & 0 deletions RASDK.Arm/RoboticArm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,44 @@ public abstract void Homing(bool slowly = true,
CoordinateType coordinate = CoordinateType.Descartes,
bool needWait = true);

/// <summary>
/// 運動。
/// </summary>
/// <param name="motion">機械手臂動作。</param>
/// <exception cref="ArgumentNullException"></exception>
/// <exception cref="ArgumentException"></exception>
public virtual void Move(RoboticArmMotion motion)
{
if (motion == null)
{
throw new ArgumentNullException();
}

var position = new double[] { motion.J1X, motion.J2Y, motion.J3Z, motion.J4A, motion.J5B, motion.J6C };
var addParams = new AdditionalMotionParameters()
{
NeedWait = motion.NeedWait,
CoordinateType = motion.CoordinateType,
MotionType = motion.MotionType,
SmoothType = motion.SmoothType,
SmoothValue = motion.SmoothValue
};

switch (motion.PositionType)
{
case PositionType.Absolute:
MoveAbsolute(position, addParams);
break;

case PositionType.Relative:
MoveRelative(position, addParams);
break;

default:
throw new ArgumentException("'PositionType' must be 'Absolute' or 'Relative'.");
}
}

#region Motion.Absolute

/// <summary>
Expand Down
199 changes: 199 additions & 0 deletions RASDK.Arm/RoboticArmMotion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RASDK.Arm.Type;

namespace RASDK.Arm
{
/// <summary>
/// 機械手臂動作。
/// </summary>
public class RoboticArmMotion
{
#region Default Value

/// <summary>
/// 預設的座標類型。
/// </summary>
protected const CoordinateType _defaultCoordinateType = CoordinateType.Descartes;

/// <summary>
/// 預設的運動類型。
/// </summary>
protected const MotionType _defaultMotionType = MotionType.PointToPoint;

/// <summary>
/// 預設的位置類型。
/// </summary>
protected const PositionType _defaultPositionType = PositionType.Absolute;

/// <summary>
/// 預設的手臂平滑模式。
/// </summary>
protected const SmoothType _defaultSmoothType = SmoothType.TwoLinesSpeedSmooth;

#endregion Default Value

#region Position Value

/// <summary>
/// 座標 J1/X。
/// </summary>
public double J1X = 0;

/// <summary>
/// 座標 J2/Y。
/// </summary>
public double J2Y = 0;

/// <summary>
/// 座標 J3/Z。
/// </summary>
public double J3Z = 0;

/// <summary>
/// 座標 J4/A。
/// </summary>
public double J4A = 0;

/// <summary>
/// 座標 J5/B。
/// </summary>
public double J5B = 0;

/// <summary>
/// 座標 J6/C。
/// </summary>
public double J6C = 0;

#endregion Position Value

#region Type

/// <summary>
/// 座標類型。
/// </summary>
public CoordinateType CoordinateType;

/// <summary>
/// 運動類型。
/// </summary>
public MotionType MotionType;

/// <summary>
/// 位置類型。
/// </summary>
public PositionType PositionType;

/// <summary>
/// 手臂平滑模式。
/// </summary>
public SmoothType SmoothType = _defaultSmoothType;

/// <summary>
/// 手臂平滑模式數值。
/// </summary>
public int SmoothValue = 50;

#endregion Type

/// <summary>
/// 是否需要等待動作完成(阻塞)。
/// </summary>
public bool NeedWait = true;

#region Constructor

/// <summary>
/// 機械手臂動作。
/// </summary>
/// <param name="j1X">座標 J1/X。</param>
/// <param name="j2Y">座標 J2/Y。</param>
/// <param name="j3Z">座標 J3/Z。</param>
/// <param name="j4A">座標 J4/A。</param>
/// <param name="j5B">座標 J5/B。</param>
/// <param name="j6C">座標 J6/C。</param>
/// <param name="positionType">位置類型。</param>
/// <param name="coordinateType">座標類型。</param>
/// <param name="motionType">運動類型。</param>
/// <param name="needWait">是否需要等待動作完成(阻塞)。</param>
public RoboticArmMotion(double j1X, double j2Y, double j3Z, double j4A, double j5B, double j6C,
PositionType positionType = _defaultPositionType,
CoordinateType coordinateType = _defaultCoordinateType,
MotionType motionType = _defaultMotionType,
bool needWait = true)
{
J1X = j1X;
J2Y = j2Y;
J3Z = j3Z;
J4A = j4A;
J5B = j5B;
J6C = j6C;
PositionType = positionType;
CoordinateType = coordinateType;
MotionType = motionType;
NeedWait = needWait;
}

/// <summary>
/// 機械手臂動作。
/// </summary>
/// <param name="position">座標位置。</param>
/// <param name="positionType">位置類型。</param>
/// <param name="coordinateType">座標類型。</param>
/// <param name="motionType">運動類型。</param>
/// <param name="needWait">是否需要等待動作完成(阻塞)。</param>
/// <exception cref="ArgumentException"></exception>
public RoboticArmMotion(double[] position,
PositionType positionType = _defaultPositionType,
CoordinateType coordinateType = _defaultCoordinateType,
MotionType motionType = _defaultMotionType,
bool needWait = true)
{
if (position.Length != 6)
{
throw new ArgumentException("The length of 'position' must be 6.");
}
J1X = position[0];
J2Y = position[1];
J3Z = position[2];
J4A = position[3];
J5B = position[4];
J6C = position[5];
PositionType = positionType;
CoordinateType = coordinateType;
MotionType = motionType;
NeedWait = needWait;
}

/// <summary>
/// 機械手臂動作。
/// </summary>
/// <param name="roboticArmMotion">機械手臂動作。</param>
public RoboticArmMotion(RoboticArmMotion roboticArmMotion)
{
if (roboticArmMotion == null)
{
throw new ArgumentNullException();
}

// Clone.
J1X = roboticArmMotion.J1X;
J2Y = roboticArmMotion.J2Y;
J3Z = roboticArmMotion.J3Z;
J4A = roboticArmMotion.J4A;
J5B = roboticArmMotion.J5B;
J6C = roboticArmMotion.J6C;
PositionType = roboticArmMotion.PositionType;
CoordinateType = roboticArmMotion.CoordinateType;
MotionType = roboticArmMotion.MotionType;
SmoothType = roboticArmMotion.SmoothType;
SmoothValue = roboticArmMotion.SmoothValue;
NeedWait = roboticArmMotion.NeedWait;
}

#endregion Constructor
}
}
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,25 @@
## 機械手臂(RASDK.Arm)

```csharp
// 實體化。
var logHandler = new RASDK.Basic.EmptyLog(); // EmptyLog():不產生 Log
var messageHandler = new RASDK.Basic.Message.GeneralMessage(logHandler); // GeneralMessage():一般的訊息處理器。
// 實體化 (Instantiation)
var logHandler = new RASDK.Basic.EmptyLogHandler(); // EmptyLogHandler:不產生 Log 檔的日誌處理器
var messageHandler = new RASDK.Basic.Message.GeneralMessageHandler(logHandler); // GeneralMessageHandler:一般的訊息處理器。
var arm = new RASDK.Arm.Hiwin.RoboticArm(messageHandler, "192.168.100.123"); // 以 HIWIN 手臂爲例。
arm.Connect(); // 連線。
arm.Disconnect(); // 斷線。
var connected = arm.Connected; // 判斷連線。
bool connected = arm.Connected; // 判斷連線。
arm.Homing(); // 復歸,回原點。
arm.MoveAbsolute(-20, 400, 350, 180, 0, 90); // 絕對運動。
arm.MoveRelative(0, 15, -0.5, 0, 0, 0); // 相對運動。
arm.Jog("+X"); // 吋動。
arm.Abort(); // 停止動作。
arm.Speed = 25; // 設定速度。
arm.Acceleration = 20; // 設定加速度。
var speed = arm.Speed; // 取得速度。
var acc = arm.Acceleration; // 取得加速度。
arm.Speed = 25; // 設定速度。
arm.Acceleration = 20; // 設定加速度。
double speed = arm.Speed; // 取得速度。
double acc = arm.Acceleration; // 取得加速度。
var position = arm.GetNowPosition(); // 取得目前座標位置。
double[] position = arm.GetNowPosition(); // 取得目前座標位置。
```

0 comments on commit 153d776

Please sign in to comment.