Created
October 29, 2019 03:16
-
-
Save choowilson/0a88bb26b9173926c25f84d1bd1bb672 to your computer and use it in GitHub Desktop.
example java source for B-cap JavaClient - pick and place
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package my.skymind.denso; | |
import orin2.bcap.BCAPClient; | |
import java.lang.reflect.Array; | |
public class Orin2RobotManager { | |
private BCAPClient m_client; | |
private int hCtrl = 0; | |
private int hRob = 0; | |
public Orin2RobotManager() { | |
try { | |
m_client = new BCAPClient("udp:192.168.0.1", 500, 3); | |
m_client.Service_Start("WDT=400"); | |
hCtrl = m_client.Controller_Connect("Ctrl1", "CaoProv.DENSO.VRC", "localhost", ""); | |
try { | |
hRob = m_client.Controller_GetRobot(hCtrl, "Rob", ""); | |
m_client.Robot_Execute(hRob, "Takearm", new int[]{0, 1}); | |
} catch (Throwable cause) { | |
System.out.println(cause.toString()); | |
} | |
} catch (Throwable cause) { | |
System.out.println(cause.toString()); | |
} | |
} | |
public void dispose() { | |
/* Release arm control authority */ | |
try { | |
m_client.Robot_Execute(hRob, "Givearm", null); | |
if (hRob != 0) { | |
/* Release robot handle */ | |
m_client.Robot_Release(hRob); | |
} | |
if (hCtrl != 0) { | |
/* Disconnect controller */ | |
m_client.Controller_Disconnect(hCtrl); | |
} | |
m_client.Service_Stop(); | |
m_client.Release(); | |
} catch (Throwable cause) { | |
System.out.println(cause.toString()); | |
} | |
} | |
public void offMotor() { | |
/* Motor off */ | |
try { | |
m_client.Robot_Execute(hRob, "Motor", false); | |
} catch (Throwable cause) { | |
System.out.println(cause.toString()); | |
} | |
} | |
public void moveTo(String positionStr) { | |
/* Move to first pose */ | |
try { | |
m_client.Robot_Move(hRob, 1, positionStr, ""); | |
} catch (Throwable cause) { | |
System.out.println(cause.toString()); | |
} | |
} | |
public void setSpeed(Object[] speed) { | |
/* Speed */ | |
try { | |
m_client.Robot_Speed(50, 25, 25.0f); | |
} catch (Throwable cause) { | |
System.out.println(cause.toString()); | |
} | |
} | |
public void onMotor() { | |
/* Motor on */ | |
try { | |
m_client.Robot_Execute(hRob, "Motor", true); | |
} catch (Throwable cause) { | |
System.out.println(cause.toString()); | |
} | |
} | |
public void halt() { | |
try { | |
m_client.Robot_Halt(hRob, ""); | |
} catch (Throwable cause) { | |
System.out.println(cause.toString()); | |
} | |
} | |
public void clearError() { | |
try { | |
m_client.Controller_Execute(hCtrl,"ClearError",new Object[]{1}); | |
} catch (Throwable throwable) { | |
throwable.printStackTrace(); | |
} | |
} | |
public void demo1() throws InterruptedException { | |
boolean isLego = true; | |
// Simple Pick and Place | |
// try { | |
// this.setSpeed(new Object[]{50, 25, 25.0f}); | |
// //Initialize, go to HOME location and open the grip | |
// m_client.Controller_Execute(hCtrl, "HandMoveA", new Object[]{ 25,50}); | |
// Thread.sleep(100); | |
// m_client.Robot_Move(hRob, 1, "@P P50", ""); | |
// Thread.sleep(100); | |
// m_client.Robot_Move(hRob, 1, "@P P51", ""); | |
// Thread.sleep(100); | |
// m_client.Robot_Move(hRob, 1, "@P P52", ""); | |
// Thread.sleep(100); | |
// m_client.Controller_Execute(hCtrl, "HandMoveA", new Object[]{ 17,50}); | |
// Thread.sleep(100); | |
// m_client.Robot_Move(hRob, 1, "@P P53", ""); | |
// Thread.sleep(100); | |
// m_client.Robot_Move(hRob, 1, "@P P54", ""); | |
// Thread.sleep(100); | |
// m_client.Controller_Execute(hCtrl, "HandMoveA", new Object[]{ 25,50}); | |
// Thread.sleep(100); | |
// m_client.Robot_Move(hRob, 1, "@P P54", ""); | |
// this.offMotor(); | |
// } catch (Throwable throwable) { | |
// throwable.printStackTrace(); | |
// } | |
// Inspect and Classify | |
try { | |
this.setSpeed(new Object[]{50, 25, 25.0f}); | |
//Initialize, go to HOME location and open the grip | |
m_client.Controller_Execute(hCtrl, "HandMoveA", new Object[]{ 25,50}); | |
Thread.sleep(100); | |
m_client.Robot_Move(hRob, 1, "@P P50", ""); | |
Thread.sleep(100); | |
m_client.Robot_Move(hRob, 1, "@P P51", ""); | |
Thread.sleep(100); | |
//Go to pick up area | |
m_client.Robot_Move(hRob, 1, "@P P60", ""); | |
Thread.sleep(100); | |
//Grip the container | |
m_client.Controller_Execute(hCtrl, "HandMoveA", new Object[]{ 2,50}); | |
Thread.sleep(100); | |
//Go to inspection area | |
m_client.Robot_Move(hRob, 1, "@P P61", ""); | |
Thread.sleep(2000); | |
if (isLego == true) { | |
//Go to above landing Zone | |
m_client.Robot_Move(hRob, 1, "@P P62", ""); | |
Thread.sleep(100); | |
//Drop item to landing zone | |
m_client.Robot_Move(hRob, 1, "@P P63", ""); | |
Thread.sleep(100); | |
//Back to above landing zone | |
m_client.Robot_Move(hRob, 1, "@P P62", ""); | |
Thread.sleep(100); | |
m_client.Robot_Move(hRob, 1, "@P P61", ""); | |
Thread.sleep(100); | |
} | |
else { | |
//Go to above landing Zone | |
m_client.Robot_Move(hRob, 1, "@P P64", ""); | |
Thread.sleep(100); | |
//Drop item to landing zone | |
m_client.Robot_Move(hRob, 1, "@P P65", ""); | |
Thread.sleep(100); | |
//Back to above landing zone | |
m_client.Robot_Move(hRob, 1, "@P P64", ""); | |
Thread.sleep(100); | |
m_client.Robot_Move(hRob, 1, "@P P61", ""); | |
Thread.sleep(100); | |
} | |
//Leave the container back at pick up area | |
m_client.Robot_Move(hRob, 1, "@P P60", ""); | |
Thread.sleep(100); | |
m_client.Controller_Execute(hCtrl, "HandMoveA", new Object[]{ 25,50}); | |
Thread.sleep(100); | |
//Go back to home position | |
m_client.Robot_Move(hRob, 1, "@P P51", ""); | |
this.offMotor(); | |
} catch (Throwable throwable) { | |
throwable.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment