FerLicht

Hello all,

Phase one of the project has already been successful, y cloned the repository on a Gen 1 Galileo and compiled the project without errors using the "blank" driver. Congratulations to the one who wrote the scripts!

The nodejs server runs correctly, I have to test the Modbus communications.

The next step is to read and write digital inputs and outputs using the mraa library, I plan to start with a copy of the Raspberry Pi hardware layer and modifying it.

The institution were I teach received ten Galileos from Intel last year, if this works we will be able to set up more and more interesting labs.

Best regards,

Fernando

Quote 0 0
thiagoralves
FerLicht wrote:
Phase one of the project has already been successful, y cloned the repository on a Gen 1 Galileo and compiled the project without errors using the "blank" driver. Congratulations to the one who wrote the scripts!
Thanks! [smile]
FerLicht wrote:
The next step is to read and write digital inputs and outputs using the mraa library, I plan to start with a copy of the Raspberry Pi hardware layer and modifying it.
I never used an Intel Galileo board, so you'll be navigating in strange waters. However, since it runs Linux, it should be really straightforward to write a driver for it. Just copy the structure of the RPi driver as you said and you'll be fine.

The core of the OpenPLC runs exactly the same on all platforms. The only thing that changes is the I/O driver. The I/O driver is responsible to read the hardware I/O and feed the OpenPLC buffers with the new information. Everything else is already taken care of.


Quote 0 0
FerLicht
Hello,

I managed to compile and link the new "hardware layer", however the application is terminating in the "update buffers" function. I coded it a bit hastily without checking for return codes which I will have to do anyway. I have two questions that might speed up things:

One, is how can I log things, I am using printfs to show when I enter or leave functions and some values I get. ¿Where do these go? Should I use something else?

The other question is about the input and output buffers. In the loop

//INPUT
for (int i = 0; i < MAX_INPUT; i++)
{
if (bool_input[i/8][i%8] != NULL) *bool_input[i/8][i%8] = digitalRead(inBufferPinMask[i]);
}

MAX_INPUT is already set to 4 (I plan to start with 4 inputs and 4 outputs), I replaced the digitalRead calls with the appropiate ones, and here is where I suspect things are going south.
Where are the NULL values in the bool_input matrix set?

Best regards,

Fernandi




Quote 0 0
thiagoralves
FerLicht wrote:
One, is how can I log things, I am using printfs to show when I enter or leave functions and some values I get. ¿Where do these go? Should I use something else?
That's pretty much what I use for debugging as well. Perhaps you just need to include more information in your printf statements to figure out what goes where
FerLicht wrote:
The other question is about the input and output buffers. In the loop

//INPUT
for (int i = 0; i < MAX_INPUT; i++)
{
       if (bool_input[i/8][i%8] != NULL) *bool_input[i/8][i%8] = digitalRead(inBufferPinMask[i]);
}

MAX_INPUT is already set to 4 (I plan to start with 4 inputs and 4 outputs), I replaced the digitalRead calls with the appropiate ones, and here is where I suspect things are going south.
Where are the NULL values in the bool_input matrix set?
The OpenPLC buffers are actually a bunch of pointer arrays, each one for a type of I/O. For example, the bool_input array is responsible for digital inputs, bool_output for digital outputs, int_input for analog input and int_output for analog outputs. They are all pointers, there aren't variables stored inside them. The real variables are declared in your PLC Ladder program. Since it's not possible to know before hand which variables the user is using in the program, the pointers initially all point to NULL.

When the OpenPLC starts its execution, one of the first things it does is map the pointers array to the user declared variables. This is done in the gluevars function. So, if the user declared a variable "Lamp" connected to the output %QX0.0, gluevars will connect the pointer bool_output[0][0] to the variable __QX0_0. That's why you need to test every time before using the buffers, to see if they're "empty" (==NULL), because if you try to manipulate a NULL pointer you might end up in a crash.

The definition of the OpenPLC buffers is in the ladder.h file, and the implementation is in the gluevars.cpp file. Note: gluevars.cpp is automatically generated after each PLC program upload. Therefore, upload a sample program before viewing its contents.
Quote 0 0
FerLicht
Hello,

I found the error in the code and now it is working correctly, I managed to run a simple ladder program turning on a LED with a switch and connecting it to a screen in Ignition, a SCADA by Inductive Automation.

No I have to implement the analog inputs and outputs.

I also had to modify the build.sh script to include the "Galileo" option and create a build_galileo script in core_builders replacing the WiringPi library with the mraa library.

Best regards,

Fernando
Quote 0 0
thiagoralves
This should be pretty much the same as the digital I/O. Just remind that the analog buffers have only one dimension, instead of two. So, the analog IN should be numbered *int_input[0] to *int_input[n] and analog OUT *int_output[0] to *int_output[n].

Once you have finished your project, please share the code with me, so that I can update it on the official git and also on the website.


Thanks! [wink]
Quote 0 0
FerLicht

Thiago,

I finished adding the analog inputs and outputs, I have tested only one digital input, two digital outputs and one analog input.

I am attaching a file with the hardware layer galileo.cpp, the build scripts, a program I used to test and a screenshot of the tests using Ignition.

The inputs and outputs were configured to be used with a PLC shield designed by a colleague at the institute.

I still have to test all the inputs and outputs and maybe "beautify" the code a little, in the meantime could you please take a look?

Do you think we can add this to your project? Intel has been giving away a lot of these boards. If so, How do you want to do this? I can create a new repository and load everything there or you can add it to yours, I still have to document it.

Best regards,

Fernando

Quote 0 0
thiagoralves
I don't have a Galileo to test it, but looking at the code it looks great. The only thing I would change so far is to have "result = mraa_gpio_dir (gpioInput[i] , MRAA_GPIO_IN)" (line 99 on galileo.cpp) inside the first for loop at line 86, and have "result = mraa_gpio_dir (gpioOutput[i] , MRAA_GPIO_OUT)" (line 105) inside the second for loop at line 92. Everything else seems fine for me.

Just let me know when you think the code is ready, and then I can add your contribution to the official git repository. Also, it would be great if you could write a documentation page similar to the raspberry pi one. I can then add it to the OpenPLC website. Don't worry about formatting the text, I just need text and images.


Thanks!
Quote 0 0
FerLicht
Thiago,

I don't understand, one of the loops initializes the input pins as inputs and the other one, the output pins as outputs, as it is done in the Raspberry code. You mean putting both the initialization of the context and setting the direction in the same loop?

I plan to write a tutorial to get this working from scratch starting with the Intel image, I will send you a copy as soon as I have it ready, it is good to know you will format it.

Best regards,

Fernando
Quote 0 0
thiagoralves
FerLicht wrote:
I don't understand, one of the loops initializes the input pins as inputs and the other one, the output pins as outputs, as it is done in the Raspberry code. You mean putting both the initialization of the context and setting the direction in the same loop?
You did the loop to go through all inputs and outputs twice. I'm just suggesting to do it only once instead:

//initialize pins as digital input and set pin direction as input
for (int i = 0; i < MAX_INPUT; i++)
{
  gpioInput[i] = mraa_gpio_init( inBufferPinMask[i] );
  result = mraa_gpio_dir (gpioInput[i] , MRAA_GPIO_IN);
}
//Initialize pins as digital output and set pin direction as output
for (int i = 0; i < MAX_OUTPUT; i++)
{
  gpioOutput[i] = mraa_gpio_init( outBufferPinMask[i] );
  result = mraa_gpio_dir (gpioOutput[i] , MRAA_GPIO_OUT);
}


FerLicht wrote:
I plan to write a tutorial to get this working from scratch starting with the Intel image, I will send you a copy as soon as I have it ready, it is good to know you will format it.
It will be great! Thanks.
Quote 0 0
thiagoralves
Hi FerLicht! Do you have any update on this? I want to add Galileo support on the OpenPLC project. Should I use the latest code you sent me?
Quote 0 0
FerLicht

Hello Thiago,

I just finished testing a shield a colleague designed with a matching ladder, everything went O.K.
I logged in to tell you when I saw your post dated November 2, sorry for that.

I haven't changed the OpenPLC code since last time but I can check it again. Do you need the steps for installing the software in Galileo?

Best regards,

Fernando

Quote 0 0
thiagoralves
Hi Fernando,

I would appreciate if you could share with me the code and the steps. Since I don't have a galileo board to test it, I will just update the site with the steps you write and the code.


Thanks!
Quote 0 0
Sareena K P
Hi Fernando,

I would appreciate if you could share with me the code and the steps. Since I don't have a galileo board to test it, I will just update the site with the steps you write and the code.


Hello Fernando and Thiago,

I am trying to get an Intel Galileo board set up as a PLC using openPLC. I am just starting on it, and I am glad that it seems to be feasible as per your discussion above. Also, I would be grateful if you could share the code and steps with me. Looking forward to your favorable reply.


Thanks!
Sareena.

Quote 0 0