Case 1

The main function of this JavaScript program is to initialize the connection of a robot arm and perform different operations according to different types of robot arms (four-axis or six-axis). Specifically, it sets the joint angles of the robot arm and makes some adjustments to the color of the indicator light. This program can achieve basic control and status monitoring of the robot arm.

<!-- Initialization program -->
const mycobot = require('mycobot')
const obj = mycobot.connect('COM15',115200)

<!-- Assume that the connected device is a four-axis robot -->
const name = "myPallizer"
<!-- If the connected device is a six-axis robot -->
if(name == "myCobot"){
<!-- Set the angles of the six joints -->
obj.write(mycobot.sendAngles([-1.49,115,-153.45,30,-33.42,137.9],80))
<!-- And determine whether the coordinate has been reached -->
if(obj.write(mycobot.isInPosition([-1.49,115,-153.45,30,-33.42,137.9],0)) == 1){
<!-- Resume robot arm movement -->
obj.write(mycobot.programResume())
<!-- Wait for 0.5 seconds -->
settimeout(() =>{
<!-- Pause robot arm movement -->
obj.write(mycobot.programPause())
},500)
}
}else{
<!-- Set the angles of the four joints -->
obj.write(mycobot.sendAngles([-1.49,45,-23,30],80))
<!-- Set the color of the ATOM indicator -->
obj.write(mycobot.setColor(0,0,50))
<!-- Wait for 0.7 seconds -->
settimeout(() =>{
<!-- Set the angles of the four joints again -->
obj.write(mycobot.sendAngles([-1.49,60,11,30],80))
<!-- Set the color of the ATOM indicator -->
obj.write(mycobot.setColor(0,50,0))
},700)

}

Case 2

Case 2 The main function of this code is to initialize a robot arm and perform a series of operations through the mycobot library, including:

  • Get and output the current joint angle.
  • Set the initial angle of all joints.
  • Set the angle of each joint step by step.
  • Finally, set the robot arm to free mode. Through these steps, precise control and status monitoring of the robot arm can be achieved
<!-- Initialization program -->
const mycobot = require('mycobot')
const obj = mycobot.connect('COM15',115200)

<!-- Get the angles of all joints -->
const botData = obj.write(mycobot.getAngles())
<!-- Output the angles of all joints -->
console.log(botdata)
<!-- Set the angles of all joints -->
obj.write(mycobot.sendAngles([0,0,0,0],50))
<!-- Print whether the robot arm has reached this position -->
console.log(obj.write(mycobot.isInPosition([0,0,0,0,0,0],0)) == 1)

<!-- Wait for 3 seconds -->
settimeout(() =>{
<!-- Set the angle of the first joint -->
obj.write(mycobot.sendAngle(1,90,50))
},3000)

<!-- Wait for two seconds -->
settimeout(() =>{
<!-- Set the angle of joint 2 to 50 degrees -->
obj.write(mycobot.sendAngle(2,50,50))
},2000)
<!-- Wait for 1.5 seconds -->
settimeout(() =>{
<!-- Set the three joint angles to 50 degrees -->
obj.write(mycobot.sendAngle(3,-50,50))
},1500)
<!-- Wait for 1.5 seconds -->
settimeout(() =>{
<!-- Set all joint angles of the robot -->
obj.write(mycobot.sendAngles([88.68, -138.51, 155.65, -128.05, -9.93, -15.29],50))
},1500)
<!-- Wait for 2.5 seconds -->
settimeout(() =>{
<!-- Set the robot to free mode -->
obj.write(mycobot.releaseAllServos())
},2500)

results matching ""

    No results matching ""