Hi all
I have just finished learning C# through some online tutorials and just finished reading the PC SDK application manual.
I am trying to design a program which will set up some variables, start my RAPID program- on button click, update the robtarget and move to it a few times, stop program on button click. effectivlet communicating the data between visual studios and robotstudio on the same computer
Firstly here is my simple RAPID code:
MODULE VariablePassTest
!***********************************************************
!
! Module: VariablePassTest
!
! Description: simple test for varaible pass via SDK
! xxxxx
!
! Author: el11et
!
! Version: 1.0
!
!***********************************************************
CONST jointtarget calib_pos:=[[0,0,0,0,0,0],[0, 9E9, 9E9, 9E9, 9E9, 9E9]];
VAR robtarget Target_10:=[[0,0,0], [0,0,0,0], [0,0,0,0], [9E9, 9E9, 9E9, 9E9, 9E9, 9E9]];
VAR num halt:= 0;
PROC Path_10() !continue moving to target until halt changes from button press
MoveAbsJ calib_pos,v1000\T:=3,z100,MyTool\WObj:=wobj0;
WHILE (halt==0) DO
MoveJ Target_10,v1000,z100,MyTool\WObj:=wobj0;
ENDWHILE
MoveAbsJ calib_pos,v1000\T:=3,z100,MyTool\WObj:=wobj0;
ENDPROC
PROC main() !start in home position, execute path 1 then move back to home position
Path_10;
ENDPROC
ENDMODULE
This seems simple enough- I know I could use a boolean indicator for halt but I am just trying out passing a number rather than straight copy from the application manual example
I have a few problems with the C# part:
- Do I need to create a scanner and scan for controllers, log on to a controller then make a controller object?
- Do all PC SDK applications need to do this to interact with RobotStudio?
Firstly this is the code for the stop button:
private void Stop(object sender, EventArgs e) //Clicking stop button will change halt variable and bring program to a halt
{
int Halt=1;
ABB.Robotics.Controllers.RapidDomain.Num rapidNum;
ABB.Robotics.Controllers.RapidDomain.RapidData rn= controller.Rapid.GetRapidData(“T_ROB1”, “VariablePassTest”, “halt”);
rapidNum.Value= Halt;
using (Mastership m = Mastership.Request(controller.Rapid))
{
rn.Value=rapidNum;
}
}
As i have other errors in my code and cannot build or run it, does this interaction look correct, all I am trying to do is change halt to 1 so the RAPID program moves out of the loop and ends the program.
Secondly the main part of my code has errors when using the FillFromString2 method, the example shows (“your text”) when I want to pass X, Y and Z like so ([ (X), (Y), (Z)]) I get erros about an invalid expression term.
Anyway here is the main part to my code:
public void Main ()
{
controller = new Controller (); // need controller object to access RAPID domain
this.controller.Logon(UserInfo.DefaultUser);
int X=70; // initialise variables
int Y=-60;
int Z=20;
bool Start= true;
//next set up object to represent RAPID data
ABB.Robotics.Controllers.RapidDomain.RobTarget robtarget;
ABB.Robotics.Controllers.RapidDomain.RapidData rt = controller.Rapid.GetRapidData(“T_ROB1”, “VariablePassTest”, “Target_10” );
if (rt.Value is ABB.Robotics.Controllers.RapidDomain.RobTarget)
{
while (Start ==true)
{
Pos nPos = new Pos();
nPos.FillFromString2([(X), (Y), (Z)]); //fill nPos with X Y and Z variables
robtarget.Trans = nPos; //set robtarget position data as nPos
using (Mastership.Request(controller.Rapid))
{
rt.Value= robtarget;
}
// adjust variables
X=X*-1;
Y=Y*-1;
if (Z>=200)
{
Z=20;
}
else
{
Z=Z+30;
}
//should keep looping until stop button is pressed
}
}
if (rt != null) // dispose of data when not in use
{
rt.Dispose();
rt=null;
}
}
Hopefully somebody can help me solve my problems with passing variables to robtarget position data.
Kind regard
Mechatronics Studuent