关节控制
对于串联式多关节机器人,关节控制是针对机械臂各个关节的变量进行的控制,目标是让机械臂各个关节按照一定速度达到目标位置。
1 单关节控制
1.1 发送单关节角度
SendOneAngle(int jointNo, int angle, int speed)
返回值:无
参数说明:参数1:关节号(1 - 6), 参数2:角度(范围:-170°- 170°)),参数3:速度(0-100)
示例:
    mc.SendOneAngle(1, 100,70);
2 多关节控制
2.1 获取所有关节角度
GetAngles()
返回值:返回int类型数组,int[], length: 6
参数说明:无
示例:
    var recv = mc.GetAngles();
2.2 发送所有关节角度
SendAngles(int[] angles, int speed)
返回值:无
参数说明:参数1:所有关节角度(范围:-170°- 170°), 参数2:速度(0-100)
示例:
int[] angles = new[] {100, 100, 100, 100, 100, 100};
mc.SendAngles(angles ,30);
3 完整使用案例
项目中的program.cs是完整的使用案例程序,可以在此基础上根据需要修改。
using System;
namespace Mycobot.csharp
{
    class Test 
    {
        static void Main(string[] args)
        {
            MyCobot mc = new MyCobot("/dev/ttyUSB0");
            mc.Open();
            // int[] angles = new[] {100, 100, 100, 100, 100, 100};
            // mc.SendAngles(angles, 50);
            // Thread.Sleep(5000);
            // var recv = mc.GetAngles();
            // foreach (var v in recv)
            // {
                // Console.WriteLine(v);
            // }
            // int[] coords = new[] {160, 160, 160, 0, 0, 0};
            // mc.SendCoords(coords, 90, 1);
            // Thread.Sleep(5000);
            // var recv = mc.GetCoords();
            // foreach (var v in recv)
            // {
                // Console.WriteLine(v);
            // }
            mc.SendOneAngle(1, 100,70);
            // byte[] setColor = {0xfe, 0xfe, 0x05, 0x6a, 0xff, 0x00, 0x00, 0xfa};
            mc.Close();
        }
    }