Simple Program to adjust robtarget data help
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
Tagged:
0
Comments
-
I have just rewritten the part where variables are copied to the new RAPID data variable and it seems to have no errors although i am not too sure if it is correct as i still have other build errorshere it is with attempt 1://ATTEMPT 1// 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//ATTEMPT 2robtarget.Trans.X=X;robtarget.Trans.Y=Y;robtarget.Trans.Z=Z;So I target and change each individual part of the Pos data and then copy robtarget to rt.Could anyone help me with my scanner/controller object problem?At this point in time i only need to interface with the VC on the same machine, would it be better to look up the specific controllers ISP address and only scan and create controller object for that? Or do i even need to as it is local?Finally after searching for other posts about updating a robtarget in the forums i found (rightly or wrongly) that I should have at least 3 targets in my path in the rapid code as the motion handler stays 1 line ahead and i could end up updating the target before it has finished moving. I assume this would cause the robot (real or virtual to stall). would i be right in saying i could have a series of 3 targets in the path that are just copies of each other and I only update the first?Something like this:PATH(1)move to robtarget_10robtarget_20=robtarget_10move to robtarget_20robtarget_30=robtarget_20move to robtarget_30while my C# code updates robtarget_10 with new position dataThanks in advanceMechatronics Student0
-
I have now reverted The basic structure of the code to the example used in the PC SDK manual, so I have a networkwatcher, information window etc. This will hopefully allow my program to scan and connect to any desired controller.The parts I have changed are the code for the start button which now looks like this:public void Start(object sender, EventArgs e) //Clicking Start button{try{if (controller.OperatingMode == ControllerOperatingMode.Auto) // starts if in auto mode{tasks = controller.Rapid.GetTasks();int X = 70;// initialise variablesint Y = -60;int Z = 20;bool Start = true;//next set up object to represent RAPID dataABB.Robotics.Controllers.RapidDomain.RobTarget robtarget;ABB.Robotics.Controllers.RapidDomain.RapidData rt = controller.Rapid.GetRapidData("T_ROB1", "VariablePassTest", "Target_10");using (Mastership m = Mastership.Request(controller.Rapid)){tasks[0].Start();}if (rt.Value is ABB.Robotics.Controllers.RapidDomain.RobTarget){while (Start == true){//ATTEMPT 1// 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//ATTEMPT 2robtarget.Trans.X = X;robtarget.Trans.Y = Y;robtarget.Trans.Z = Z;using (Mastership.Request(controller.Rapid)){rt.Value = robtarget;}// adjust variablesX = X * -1;Y = Y * -1;if (Z >= 200){Z = 20;}else{Z = Z + 30;}//should keep looping until stop button is pressed}}}else //error if not in auto mode{MessageBox.Show("Automatic mode is required to start execution");}}catch (System.InvalidOperationException ex){MessageBox.Show("Mastership is held by someone else" + ex.Message);}catch (System.Exception ex){MessageBox.Show("Unexpected error!" + ex.Message);}}As with my above post is Attempt 2 a valid way of writing to robtarget ?List of errors:
- one error/warning on the X line stating "use of possibly unassigned field 'Trans'. Struct instance variables are initially unsigned if struct is unsigned"
- 2 errors of using unsigned local variables - "robtarget" and "rapidNum"
- one warning stating "The variable 'Start' is assigned but its value is never used" - I believed the bool Start was used in the Start button execution and would only update the variables while it was true, the Stop button changes it to false so I thought this would stop that loop.
Again any help is greatly appreciatedKind regardsMechatronics Student0 - one error/warning on the X line stating "use of possibly unassigned field 'Trans'. Struct instance variables are initially unsigned if struct is unsigned"
Categories
- All Categories
- 5.5K RobotStudio
- 394 UpFeed
- 18 Tutorials
- 13 RobotApps
- 297 PowerPacs
- 405 RobotStudio S4
- 1.8K Developer Tools
- 249 ScreenMaker
- 2.7K Robot Controller
- 309 IRC5
- 59 OmniCore
- 7 RCS (Realistic Controller Simulation)
- 785 RAPID Programming
- AppStudio
- 3 RobotStudio AR Viewer
- 18 Wizard Easy Programming
- 105 Collaborative Robots
- 4 Job listings