RobotStudio event

Simulation Controller (or how to move it)

Options

Well, I've noticed that a lot of people want to move things while running a simulation.image

Here comes a handy instruction on how to do that:
SimulationController.zip

image

Oh, and let's see if Dean takes a look at this or not...

Comments

  • Thanks alot for this demonstration, and offtopic: Techsmith Camtasia is really sweet Cool Worth every penny/dollar/euro/yen!

    [edit]

    Damn... those drag&drop smilies are irritating.. what about the usual :D:);):( etc...

    [/edit] 

    Melk38033,8438194444
    <@Logan&gt; I spent a minute looking at my own code by accident.
    <Beeth> And your point is?
    <@Logan&gt; I was thinking "What the hell is this guy doing?"
  • John Wiberg
    Options

    Yupp, camtasia rules the screencams...

    image

    Well I don't find those smilies that irritating, it's an excellent way to show irony or emotions, something that usually is lost in forums.
    8~)

  • Thanks for the avi John - my customer will also find this useful

    image

    Dean Thomas
    ABB Support Engineer
    Channel Partners Australia
  • [quote]

    Well I don't find those smilies that irritating, it's an excellent way to show irony or emotions, something that usually is lost in forums.
    8~)

    [/quote]

    John i think you might not understood what i was trying to say. It's not the smilies that are irritating. By all means i'm glad they are here. But the way you have to place one in a post is a littlebit unhandy. You have to drag & drop them from the list instead of just typing the code. But this is just my opinion.. :P

    <@Logan&gt; I spent a minute looking at my own code by accident.
    <Beeth> And your point is?
    <@Logan&gt; I was thinking "What the hell is this guy doing?"
  • John Wiberg
    Options
    Ah, sorry my mistake. Yes I'd say that forums that replaces text and turns them into smilies are a neater way of doing it.
  • Oscar
    Options

    Hello,

    I have tried to get this example working with a mechanism. I can move the mechanism, but i cannot stop it from going into the joint limits. How can i add the jointlimits and predefine on which angle (degrees) the movement should stop? I would like to add this angle into the macro. Below the code i created with your example. But i'm really bad with making macro's, so if you might have a answer.. i'd thank you greatly for a solution i could copy/paste..

    Dim velocity As Integer
    Private Sub Controller_AfterTick(ByVal Time As Double)
        'This example moves a mechanism
        'The name of the moving mechanism is:  Mecha1
        ActiveStation.Mechanisms("Mecha1").Joints(1).JointValue = ActiveStation.Mechanisms("Mecha1").Joints(1).JointValue + UnitToAPI(rsQuantityAngle, velocity)
    End Sub
    Private Sub Controller_Create()
        velocity = -1
    End Sub

    Sub startMech() 'this adds the controller to the simulation
        'MechanisMove is the controller
        'RobotStudio Class Object > Insert > Controller Class > Name it and declare that name here
        Dim x As MechanisMove
        Set x = ActiveStation.CreateController("MechanisMove")
        x.Name = "JohnWiberg"
        ActiveStation.Simulations("Simulation1").Controllers.Add x
    End Sub
    Sub stopMech() 'this kills the controller after simulation
        ActiveStation.Simulations("Simulation1").Controllers("JohnWiberg").Delete
    End Sub
    Sub scan() 'Scan for controllers not killed
        Dim x As Controller
        For Each x In ActiveStation.Simulations("Simulation1").Controllers
            ActiveStation.PrintLog "Log", x.Name
        Next
    End Sub

    Oscar38072,4428356482
  • John Wiberg
    Options

    Well, well, well. A copy/paste solution? Feeling a bit lazy?

    image

    All I did was put in checks for the lower and upper limit of the joint.

    image

    Dim velocity As Integer
    Private Sub Controller_AfterTick(ByVal Time As Double)
        'This example moves a mechanism
        'The name of the moving mechanism is:  Mecha1
        If ActiveStation.Mechanisms("Mecha1").Joints(1).JointValue + UnitToAPI(rsQuantityAngle, velocity) > ActiveStation.Mechanisms("Mecha1").Joints(1).LowerLimit And ActiveStation.Mechanisms("Mecha1").Joints(1).JointValue + UnitToAPI(rsQuantityAngle, velocity) < ActiveStation.Mechanisms("Mecha1").Joints(1).UpperLimit Then
            ActiveStation.Mechanisms("Mecha1").Joints(1).JointValue = ActiveStation.Mechanisms("Mecha1").Joints(1).JointValue + UnitToAPI(rsQuantityAngle, velocity)
        End If
    End Sub
    Private Sub Controller_Create()
        velocity = -1
    End Sub
    image

    With similiar code I could check for IOs and move only as long as the IO is moving etc.

    Why I use a velocity value is that then I could change that value using other macros...

  • Melk
    Options

    Interesting.. i was facing similar problems with a simulation i'm trying to run right now, and Oscar i think i can help you a little towards your goal to specify an angle on which the mechanism will stop moving.

    First of all i declared the velocity as a Double

    Dim velocity As Double

    This will allow for velocities that aren't round numbers (like 0.5 or 1.3). I use lower values. I did this because i noticed that the movement of the mechanism doesn't stop exactly at the Upper/LowerLimit when using higher velocities. I have a turntable that (with velocities above 0.5) will only reach 358 degrees in stead of 360.

    I also noticed that RS uses Radiants. And I as well want to use Degrees. So i use a helper value to convert radiants into degrees (found in RS API help)

        Dim Rad2Deg As Double 
        Rad2Deg = 1 / 360 * 2 * 4 * Atn(1)

    Then when specifieing a new angle use something like this:

    jointValues(1) = 90 * Rad2Deg

    But this is where i am stuck too. I only got this working on a robot, and it jumps from one angle to another, so no smooth movement..

    The three things i'm eager to know are first, how to  declare a specific rotation in degrees on which the mechanism stops moving. The mechanism I use is a turning table which can rotate from +360 to -360 degrees. I'd like to stop the movement when the turning table has turned 90 degrees (or any other angle). And i know this is possible without having to configure the turning table as an external axis.

    The second question is about how to abort the macro when the desired rotation is reached. Right now i use a separate macro to stop the controller, but this doubles the amount of IO i need to use..

    The third question would be about how to reach the exact angle, even when using higher velocities. Like i said before i need to drop the velocity to 0.5 or below in order to really reach the Upper/LowerLimit. And in some cases this causes long waits....

    Oh and even a fourth question comes to mind... How to set an input on the robot from within the macro.. In this case i can remove the WaitTime-instructions and establish a handshake between the robot and the macro.

    I know i'm asking pretty damn much.. but any efforts towards any of this goals are much appreciated.. (hmm.. deja vu.. i've said this before...)

    Melk38075,9059722222
    <@Logan&gt; I spent a minute looking at my own code by accident.
    <Beeth> And your point is?
    <@Logan&gt; I was thinking "What the hell is this guy doing?"
  • Melk
    Options

    Oh and i forgot about the code i cooked up so far (well... copied Wink). It's the part that i got working, so the helper value isn't included

    Sub TurnTableStart()
        Dim x As TurnTable
        Set x = ActiveStation.CreateController("TurnTable")
        x.Name = "TurnTable"
        ActiveStation.Simulations("Simulation1").Controllers.Add x
    End Sub


    Sub TurnTableStop()
        ActiveStation.Simulations("Simulation1").Controllers("TurnTable").Delete
    End Sub

    Dim velocity As Double
    Private Sub Controller_AfterTick(ByVal Time As Double)
        If ActiveStation.Mechanisms("TurnTable").Joints(1).JointValue + UnitToAPI(rsQuantityAngle, velocity) > ActiveStation.Mechanisms("TurnTable").Joints(1).LowerLimit And ActiveStation.Mechanisms("TurnTable").Joints(1).JointValue + UnitToAPI(rsQuantityAngle, velocity) < ActiveStation.Mechanisms("TurnTable").Joints(1).UpperLimit Then
            ActiveStation.Mechanisms("TurnTable").Joints(1).JointValue = ActiveStation.Mechanisms("TurnTable").Joints(1).JointValue + UnitToAPI(rsQuantityAngle, velocity)
        End If
    End Sub


    Private Sub Controller_Create()
        velocity = 0.5
    End Sub

    <@Logan&gt; I spent a minute looking at my own code by accident.
    <Beeth> And your point is?
    <@Logan&gt; I was thinking "What the hell is this guy doing?"
  • John Wiberg
    Options

    I also noticed that RS uses Radiants. And I as well want to use Degrees.

    Another function you should look at is:
    UnitToAPI(rsQuantityAngle,value)
    This converts from whatever units the user uses to what the API is using. The reverse is APIToUnit.

        ***Do not use this***
        Dim Rad2Deg As Double 
        Rad2Deg = 1 / 360 * 2 * 4 * Atn(1)

    You said that you found this in the help? image Can you tell me where so I can change it? To get a good definitation of degrees to radiants and vice versa then define it like this instead:
        Dim PI As Double
        PI = 4 * Atn(1)
        Dim deg2rad As Double
        deg2rad = PI / 180
        Dim rad2deg As Double
        rad2deg = 180 / PI
    That is sooooooo much easier and nicer. image Plus it gives an insight in how it really works as well.
    (For you codecrunchers out there you should dim the constants in the Global project and the definitions in the Initialize of the Global project...) image

    I'd like to stop the movement when the turning table has turned 90 degrees (or any other angle).

    If you use my macro above then you can exchange
    "ActiveStation.Mechanisms("Mecha1").Joints(1).LowerLimit"
    to your lower value and
    "ActiveStation.Mechanisms("Mecha1").Joints(1).UpperLimit"
    to your upper value...
    Now to get an exact value like a hard 90' I would actually add a check that if I'm above 90' I change it to 90' like this:
        If ActiveStation.Mechanisms("Irb140_M2000").Joints(1).JointValue > 90 * deg2rad Then
            ActiveStation.Mechanisms("Irb140_M2000").Joints(1).JointValue = 90 * deg2rad
        End If
    Now if that code would be in the 'Movement' controller class in the example above the joint could never become more that 90'.

    Oh, and if you like to smoothen the numbers you could do a
    Round(value,5)
    Which will round the value to 5 decimals. 0,00001

    The second question is about how to abort the macro when the desired rotation is reached.

    Uhm, depends on if you want a smooth motion or a 'jump' into place?
    If you are running a simulation like we are discussing here you can either set velocity=0 or you could kill the simulation controller or you could just add IF checks...
    If you are running a seperate macro then an 'Exit Sub' works nicely...
    image

    The third question

    Same as no1 add a check that if the joint goes over the value then give it the value and stop the motion...

    How to set an input on the robot from within the macro..

    RTFM image
    Sub IOset()
        Dim myIO As IO
        Set myIO = ActiveMechanism.Controller.IOs("theIOname")
        myIO.Value = 1
    End Sub

     

  • John Wiberg
    Options

    I created an example station with all code in the right places.

    image

    At Open_Station it creates its own ControllerClass to move the Mechanism 'Turner' which is in the station.

    Turner_Example.zip

    image

    IMPORTANT!!!
    Always CLOSE this station before opening a new one since I use the Station_Close event to clean up the controller.

  • Melk
    Options

    Perhapse a small step for people who know how to use VBA.. but a giant step for me. Things are starting to work over here Cool Thanx alot!

    With your latest example i'm able to set/reset IO, and make my turntable stop exactly at any desired angle. Next thing i tried was to detatch the macro from the Station_Open/Close events so i could start/stop it manually, or with an OI of the robot (Private Sub Station_Open >> Sub startTurner). This seemed to work, but when i start the VC of the robot, the macro is started automatically again. And when i run the macro, in stead of trying to move the turner, the macro wants to move the robot. I'm still working on it though. I'll let you know.

    <@Logan&gt; I spent a minute looking at my own code by accident.
    <Beeth> And your point is?
    <@Logan&gt; I was thinking "What the hell is this guy doing?"
  • Melk
    Options

    It all works now Cool, there is one thing left though.. Is is possible to set an input in the macro for a given period of time (e.g. i set it to 1 and after a second it reset to 0 again)? What i mean is somewhat similar to the "PulseDO"-instruction. I now use a separate macro to reset the input with an output of the robot, but this realy fills up the event table. For me it would be a much nicer solution if the input were to reset automatically by using somesort of wait- or pulse-instruction.

    <@Logan&gt; I spent a minute looking at my own code by accident.
    <Beeth> And your point is?
    <@Logan&gt; I was thinking "What the hell is this guy doing?"
  • John Wiberg
    Options

    Run the 'tester' macro below to see a use of the Time with a delay.
    You could add the SetDelay in your onIOmacro and then have the IsItTime in the controller_aftertick event.

    Dim blTime As Boolean
    Dim varTime As Variant
    Sub IsItTime()
        If Time >= varTime Then
            ActiveStation.PrintLog "Clock", "Check: " & Time
            blTime = False
        End If
    End Sub
    Sub SetDelay(SecondsDelay As Integer)
        varTime = Time + SecondsDelay / 60 / 60 / 24 'adds seconds to current time
        'The unit of Time is days so to get it into seconds
        'I divide by seconds/minutes/hours to get seconds/day
        blTime = True
    End Sub
    Sub tester()
        ActiveStation.PrintLog "Clock", "- - - - -"
        SetDelay (3)
        While blTime
            ActiveStation.PrintLog "Clock", Time
            IsItTime
        Wend
        ActiveStation.PrintLog "Clock", "- - - - -"
    End Sub

    imageimageimage

  • Melk
    Options
    I'm sorry i put you to work on this.. after all it seems better not to use the delays Dead. But it did work, and i'm trying to use it for something else.  Because the station has a lot of mechanisms, i'd like to move a couple of them simultanously and then shut down their controllers with an interval. I've tried to shut down a couple of them simultanously with outputs from the robots, but that results in a crash.. So i kinda wandered whether there is a limit to the amount of active controllers
    <@Logan&gt; I spent a minute looking at my own code by accident.
    <Beeth> And your point is?
    <@Logan&gt; I was thinking "What the hell is this guy doing?"
  • John Wiberg
    Options

    I haven't run into any limits on the number of controllers and I've had 30 at the same time.

    So you might need to do some better cleanup...

    image

  • Melk
    Options
    And I did Smile.. I declared the movement of multiple mechanisms in one controller class, and that did the trick. The simulation is almost finished and my boss is already happy. Besides that, after the completion of the new workcell we're building right now, my boss will let me do the VBA coarse Wink...  
    <@Logan&gt; I spent a minute looking at my own code by accident.
    <Beeth> And your point is?
    <@Logan&gt; I was thinking "What the hell is this guy doing?"
  • John Wiberg
    Options

    Nice the next one is planned for 19th21st of October 2004.

  • Melk
    Options
    I believe that would be the coarse in scandinavia right? I think (like always) i'm going to be visiting Zaventhem, Belgium. But basically it's the same coarse i guess..
    <@Logan&gt; I spent a minute looking at my own code by accident.
    <Beeth> And your point is?
    <@Logan&gt; I was thinking "What the hell is this guy doing?"
  • John Wiberg
    Options

    Hmm. I don't know about anyone but me who holds RobotStudio VBA courses... image
    So I think that to get it you need to travel to the beautiful city of Gothenburg in Sweden. image (Flighttime Gothenburg-Brussels is about 1 hour, with pricing, if you plan ahead, as low as 100euro.

    Is it Ron, Luc or Peter who usually holds your courses? I could check with them if they are up to holding a VBA course but I haven't heard anything like that from them.
    image

  • Melk
    Options

    That would be nice, i've never been to SwedenWink. But in that case i think i need a more tactical approach towards my boss. By now he's slowly getting used to the idea, but i'm not sure at all how he'll think about shipping me off to Sweden.. That will take some carefull manouvering..

    And i think i've had courses of both Luc and Peter, but to be sure i'll have to check my certificates (will do). And Ron, would that be Ron Nakken perhapse?

    <@Logan&gt; I spent a minute looking at my own code by accident.
    <Beeth> And your point is?
    <@Logan&gt; I was thinking "What the hell is this guy doing?"
  • Melk
    Options
    I've checked my certificates. I've had courses form Luc, Peter and Dick.
    <@Logan&gt; I spent a minute looking at my own code by accident.
    <Beeth> And your point is?
    <@Logan&gt; I was thinking "What the hell is this guy doing?"
  • John Wiberg
    Options

    Right, Ron is Ron Nakken. But Dick I don't think that I've met.

    Just to add a few arguments for a possible confrontation with your boss:

    • You would be in the office of the developers and would therefore be able to get and give direct input if you want.
    • You would have a chance to ask advanced questions not only on VBA stuff but also generic RobotStudio.
    • Apart from meeting an expert teacher image you would also meet other RS users who could give you new insight in how to get maximum return on the investment in offline simulation.
    • If you would book it in advance we could arrange demos of other productivity increasing softwares and coming releases.

    image