-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathVREPHelper.cs
58 lines (46 loc) · 1.95 KB
/
VREPHelper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System;
using System.Collections.Generic;
using System.Linq;
namespace remoteApiNETWrapper
{
public static class VREPHelper
{
private static bool positionControlEnabled = false;
public static float D { get; set; }
public static float I { get; set; }
public static float P { get; set; }
public static void BeginSetBlock(int clientID)
{
VREPWrapper.simxPauseCommunication(clientID, 1);
}
public static void EndSetBlock(int clientID)
{
VREPWrapper.simxPauseCommunication(clientID, 0);
}
public static simx_error SetJointPositionControl(int clientID, int jointID, bool onOff)
{
if (positionControlEnabled == onOff) return simx_error.noerror;
var code = new List<simx_error>
{
VREPWrapper.simxSetObjectIntParameter(clientID, jointID, 2001, (onOff) ? 1 : 0, simx_opmode.oneshot_wait),
VREPWrapper.simxSetObjectFloatParameter(clientID, jointID, 2002, P, simx_opmode.oneshot),
VREPWrapper.simxSetObjectFloatParameter(clientID, jointID, 2003, I, simx_opmode.oneshot),
VREPWrapper.simxSetObjectFloatParameter(clientID, jointID, 2004, D, simx_opmode.oneshot)
};
foreach (var c in code.Where(p => p > simx_error.noerror).Select((p, i) => new { Code = p, Index = i }))
{
Console.WriteLine("Errors: {0}: {1} -> {2}", jointID, c.Index, c.Code);
}
positionControlEnabled = onOff;
return code.Max();
}
}
public class VREPException : Exception
{
private simx_error error;
public VREPException(simx_error Error, string Message = "")
: base(String.Format("{0}: {1}", Enum.GetName(typeof(simx_error), Error), Message))
{
}
}
}