0
Answered

how to use the interface for commands?

MarkH 6 months ago in realvirtual.io Starter and Professional updated 3 months ago 13

I want to interface the realvirtual digital twin with a c# application. The c# application already exists and controls resources like motors with resource commands. The commands are already expressed in a message that is send via TCP. No PLC is used.

An example message would be:

- message type -> eg resource command request

- object id -> eg Xaxis

- command id -> eg move

- parameters -> eg position, speed, acceleration and deceleration parameters

The individual parameters in the message are extracted from the message by a decoding procedure.

I would like to use an industry standard like MQTT (or OPC UA) to interface with the digital twin. Therefore the TCP message has to be converted to a MQTT message.

I have limited knowledge in this area, but from what I understand is that the digital twin requires signals. Drive_DestinationMotor for example requires 5 PLC outputs and 4 PLC inputs, the PLC outputs/inputs should be mapped to signals, signals should be connected to MQTT topics, each MQTT topic represents 1 signal. Am I right?

I can understand how to convert the TCP message to multiple MQTT messages, but how can I make sure that parameters like position and speed signals are received all at once or before the actual "start drive" signal?

Are there examples available on how to do this or should I use a different approach? What would happen when I replace Drive_DestinationMotor by a controller with states? Are there examples of such a controller?

Hi, it would be best to implement a TCP-IP interface in C# for realvirtual.io which understands your custom commands and then send for example the drive to a position with the public methods of the drive:

if (commandtype = "motordriveto)

{

    drive.DriveTo(destinationposition);

}

I think this is much better than transferring your commands to a PLC like signal  based control of the Drive.

Ok, I thought of that as well, but can you give any direction on how to do that? Documentation? Example?

Answered

I am sorry we don't have example code really covering what you need.


You can check our api documentation here - there you will find the public properties and methods for example for our drives:

https://realvirtual.io/apidoc/namespacerealvirtual.html

You can also check here how to implement your own interface:

https://doc.realvirtual.io/components-and-scripts/custom-interfaces

The rest is more or less standard c# scripting for a tcp-ip communication. Maybe you can start here:

https://learn.microsoft.com/de-de/dotnet/fundamentals/networking/sockets/tcp-classes

I decided to implement a TCP-IP interface after more initial testing. For testing I really like the simplicity of PLC like signal control.

One question I have is the usage of a bool as PLCOutput (eg start drive). My test application would set this PLCOutput to true, but it should also be set to false again. Who would be responsible to set the PLCOutput to false and when?

Your application should set it back.

One good approach for your application could be - if you would like to send full commands like that, to not use the existing Drive Behavior Scripts but to create your own Drive Behavior Script and to attach this to our Drive. This Script could decode your full massage and make the Drive just move by the public properties or methods of the Drive.

Your application should set it back.


as long as I don't have the command style interface I have to work with the PLC signal interface. What would you recommend for set back behavior?

- set true, wait ... ms, set false

- set true, check isdriving, set false

- set true, check isatdestionation, set false

How to deal with a mismatch in order/timing of the outputs and inputs?

the second - set true, checkisdriving and set false

Is there a risk that isdriving becomes true and false again before my application knows in case of very small moves?

you should do your code in fixedupdate then this will be called fast enough.

Also you could check "isatdestination". 

My application code is in a separate standalone application that communicates with the mqtt broker. What do you mean with my code in fixedupdate? Do you advice to modify CalcFixedUpdate() in the drive_destinationmotor script?

You schould create your own script as a copy of one of the examples behavior models - for example of drive_destinationmotor.

Yes CalcFixedUpdate is called at the end by Unity FixedUpdate. Please check this about the update sequence. It is I think not important for your application, you could also use Unitys FixedUpdate but you should know the basics:
https://doc.realvirtual.io/components-and-scripts/motion/motion-for-developers

https://docs.unity3d.com/ScriptReference/MonoBehaviour.FixedUpdate.html


Is your application a commercial one?If yes maybe you could think about purchasing some support hours from our side.

Thanks, Your application should set it back. caused my confusion. It is a commercial application, I will look for the possibilities to purchase support hours.

My own Drive Behavior Script would be the way forward, but at the moment I am not feeling comfortable to explore this direction with my limited c# knowledge.

Maybe a small example could help, I think I need to:
- add a custom interface to send/receive messages through tcp-ip or udp, I could use the udp interface as example

- modify drive behavior script by removing PLC like signals and replacing them by a message decoder and if statements to call the right public methods of the drive

I have no idea yet how to make the connection between message in the interface and the drive behavior script, could you give me some direction?