Joint control

For serial multi-joint robots, joint control is the control of the variables of each joint of the robot arm. The goal is to make each joint of the robot arm reach the target position at a certain speed.

Single joint control

Send single joint angle

SendOneAngle(int jointNo, int angle, int speed)
Return value: None
Parameter description: Parameter 1: joint number (1 - 6), Parameter 2: angle (range: -170°- 170°), Parameter 3: speed (0-100)
Example:
mc.SendOneAngle(1, 100,70);

Multi-joint control

Get all joint angles

GetAngles()
Return value: Returns int type array, int[], length: 6
Parameter description: None
Example:
var recv = mc.GetAngles();

Send all joint angles

SendAngles(int[] angles, int speed)
Return value: None
Parameter description: Parameter 1: All joint angles (range: -170°- 170°), Parameter 2: Speed ​​(0-100)
Example:

int[] angles = new[] {100, 100, 100, 100, 100, 100}; mc.SendAngles(angles ,30);

Complete use case

The program.cs in the project is a complete use case program, which can be modified as needed.

using System; // Introduce the System namespace to provide basic classes and methods, such as Console and Thread

namespace Mycobot.csharp // Define a namespace for organizing code
{
 class Test // Define a class named Test
  {
static void Main(string[] args) // Main entry point of the program
     {
MyCobot mc = new MyCobot("/dev/ttyUSB0"); // Create a MyCobot instance, assuming that "/dev/ttyUSB0" is the serial port for the robot to communicate with the computer
mc.Open(); // Open the connection with the robot

// The following lines of code are commented out, they demonstrate how to send an array of angles, wait for a while, receive and print the returned angles
// int[] angles = new[] {100, 100, 100, 100, 100, 100}; // Create an array of 6 angles
// mc.SendAngles(angles, 50); // Send angle array and speed to the robot
// Thread.Sleep(5000); // Wait 5000 milliseconds (5 seconds)
// var recv = mc.GetAngles(); // Receive current angle
// foreach (var v in recv) // Traverse and print received angles
// {
// Console.WriteLine(v);
// }

// The following lines of code are also commented out, they demonstrate how to send a coordinate array, wait for a while, receive and print the returned coordinates
// int[] coords = new[] {160, 160, 160, 0, 0, 0}; // Create a coordinate array containing position and direction
// mc.SendCoords(coords, 90, 1); // Send coordinates and speed to the robot
// Thread.Sleep(5000); // Wait 5000 milliseconds (5 seconds)
// var recv = mc.GetCoords(); // Receive current coordinates
// foreach (var v in recv) // Traverse and print received coordinates
// {
// Console.WriteLine(v);
// }

mc.SendOneAngle(1, 100, 70); // Send the angle of a single joint (assuming it is the first joint), set the angle to 100 and the speed to 70

// byte[] setColor = {0xfe, 0xfe, 0x05, 0x6a, 0xff, 0x00, 0x00, 0xfa}; // This line of code is also commented out, it may be used to set LED color, etc.
mc.Close(); // Close the connection with the robot
  }
 }
}

results matching ""

    No results matching ""