paolojo
Posts: 117
Joined: Mon Oct 26, 2015 3:32 pm

RTOS on raspberry pi3

Thu Jan 04, 2018 3:33 pm

hi everybody and happy new year!!!
2018 starts with a great question: does exist a real time OS for raspberry pi3?
My aim is to develop an agricultural application able to read some sensor outputs and able to drive some motors/valves in the tractors.
Could you give me some suggestions?
Thanks in advance
Paolo

fruitoftheloom
Posts: 27226
Joined: Tue Mar 25, 2014 12:40 pm

Re: RTOS on raspberry pi3

Thu Jan 04, 2018 3:40 pm

paolojo wrote:
Thu Jan 04, 2018 3:33 pm
hi everybody and happy new year!!!
2018 starts with a great question: does exist a real time OS for raspberry pi3?
My aim is to develop an agricultural application able to read some sensor outputs and able to drive some motors/valves in the tractors.
Could you give me some suggestions?
Thanks in advance
Paolo

viewtopic.php?f=56&t=201447
Take what I advise as advice not the utopian holy grail, and it is gratis !!

User avatar
joan
Posts: 15749
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: RTOS on raspberry pi3

Thu Jan 04, 2018 3:43 pm

Are you sure you need a RTOS?

A RTOS is not needed to read most sensors or drive most motors. Do you have a particular problem sensor or problem motor in mind?

User avatar
topguy
Posts: 7231
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: RTOS on raspberry pi3

Thu Jan 04, 2018 3:43 pm

FreeRTOS was ported some years ago: viewtopic.php?t=22423
But I dont know the current status of it.

How "hard" are your RT requirements really ? Are you sure they would not be fulfilled by standard Linux ?

paolojo
Posts: 117
Joined: Mon Oct 26, 2015 3:32 pm

Re: RTOS on raspberry pi3

Thu Jan 04, 2018 4:49 pm

Thanks for your replays.
My need is very easy: have a routine which reads the sensor output every 1ms or 5ms depend on the sensor without lags/delays.
Do you think raspbian is good for this type of need?

mattmiller
Posts: 2247
Joined: Thu Feb 05, 2015 11:25 pm

Re: RTOS on raspberry pi3

Thu Jan 04, 2018 5:44 pm

Probably better sticking to using an Arduino type device for that sort of RT application

User avatar
joan
Posts: 15749
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: RTOS on raspberry pi3

Thu Jan 04, 2018 5:52 pm

What sensors are you talking about. Why do they need reading at such precise intervals?

paolojo
Posts: 117
Joined: Mon Oct 26, 2015 3:32 pm

Re: RTOS on raspberry pi3

Thu Jan 04, 2018 9:22 pm

At the moment i don't know exactly which sensor..but in general i have the need to work without lags

mattmiller
Posts: 2247
Joined: Thu Feb 05, 2015 11:25 pm

Re: RTOS on raspberry pi3

Thu Jan 04, 2018 10:30 pm

At the moment i don't know exactly which sensor..
:)

Stick with Arduino just to be safe then

paolojo
Posts: 117
Joined: Mon Oct 26, 2015 3:32 pm

Re: RTOS on raspberry pi3

Thu Jan 04, 2018 10:55 pm

Why Arduino?

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 14184
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: RTOS on raspberry pi3

Thu Jan 04, 2018 10:59 pm

paolojo wrote:
Thu Jan 04, 2018 10:55 pm
Why Arduino?
arduino doesn't run a multi-tasking multi-user operating system, so doesn't have task switching pauses where it doesn't run your code.

murtaza
Posts: 1
Joined: Thu Oct 04, 2018 5:53 pm

Re: RTOS on raspberry pi3

Thu Oct 04, 2018 5:56 pm

For sophisticated real time application, you can use ROS(robot operating system). It is a framework works stably over UBUNTU.

softweyr
Posts: 2
Joined: Tue Nov 10, 2015 8:19 pm

Re: RTOS on raspberry pi3

Sun Dec 23, 2018 12:02 am

There was not a lot o real information shed in this thread, so I'll try to add some.

Some of the architectural decisions that went into the Rapsberry Pi family, that helped keep the functionality high and the price low, make it somewhat less than idea for a simple real-time OS. As an example, consider the ethernet interface out there in USB land. This requires a fairly sophisticated USB stack (which Linux of course has) to be apple to support an ethernet driver (already a fairly sophisticated driver) on top of it. A lot of small, free-ish RTOSes don't have sophisticated USB stacks, if any, so if you want to port your RTOS to the Pi, you have to become a USB expert too.

I would dare say if you can't find an existing, well-support port of whatever RTOS you are looking at already on whichever Raspberry Pi you want, doing so is going to be way beyond a hobby or even a junior professional programmer task. Someone suggested Arduino, which is completely orthogonal to the question at hand. If you think your task would be best accomplished using FreeRTOS or RTEMS, to name a couple, your search should start with boards that are known to work well with FreeRTOS or RTEMS and meet your goals.

If you don't know, and are just poking around trying to figure things out, you may want to look at the Arduino world. There are Arduinon (ish) that have, for instance, Ethernet, WiFi, or Bluetooth interfaces, and at least parts of a TCP/IP stack. The Adafruit Feather M0 Wifi, for instance.

Best of luck, if OP ever happens to come back here. :)

kosrodman
Posts: 1
Joined: Wed Feb 06, 2019 11:23 pm

Re: RTOS on raspberry pi3

Thu Feb 07, 2019 12:32 am

Hello forum. I have a similar problem. I use raspberry pi with MCC118 HAT on it to read sensors. In particular I am trying to read laser emitted binary code(light ON on 1 and OFF on 0) with known frequency. It starts well, as i am able to read exactly what I send to it from separate mcu, but then it drifts and "skips" one number and basically all prints shifted, and then more and more drift. And frequency is very little like 10Hz :oops: it reads signal from sensor and prints 1 or 0 on display in 32 number long lines.
MCC118 has its own crystal and so It should be reading it with good timing, yet it doesn't. I think it is my code inefficiency or it is a pi messing it up.

Also i tried to clock MCC118 with from other MCU(TIVA launchpad) and i am able to push up to 200 hz signal with code and everything remaining same. What baffles me is that TIVA has exactly the same crystal but on TIVA i use interrupt and it does much better job timing it.

I am a nubbie so any advice will help.

How would you suggest me to tackle this issue? I need it to be on a microcomputer and for it to be precise like mcu.

Code: Select all


#include "../../daqhats_utils.h"
#include <stdio.h>
#include <wiringPi.h>
int main(void)
{
    int result = RESULT_SUCCESS;
    uint8_t address = 0;
    char c;
    char display_header[512];
    int i;
    char channel_string[512];
    char options_str[512];

    // Set the channel mask which is used by the library function
    // mcc118_a_in_scan_start to specify the channels to acquire.
    // The functions below, will parse the channel mask into a
    // character string for display purposes.
    uint8_t channel_mask = {/*CHAN0 | CHAN1 | CHAN2 |*/ CHAN3};
    convert_chan_mask_to_string(channel_mask, channel_string);
    
    uint32_t samples_per_channel = 1000000;

    int max_channel_array_length = mcc118_info()->NUM_AI_CHANNELS;
    int channel_array[max_channel_array_length];
    uint8_t num_channels = convert_chan_mask_to_array(channel_mask, 
        channel_array);

    uint32_t internal_buffer_size_samples = 0;
    uint32_t user_buffer_size = 1000 * num_channels;
    double read_buf[user_buffer_size];
    int total_samples_read = 0;

    int32_t read_request_size = READ_ALL_AVAILABLE;

    // When doing a continuous scan, the timeout value will be ignored in the
    // call to mcc118_a_in_scan_read because we will be requesting that all
    // available samples (up to the default buffer size) be returned.
    double timeout = 5;

    double scan_rate = 10.0;
    double actual_scan_rate = 0.0;
    mcc118_a_in_scan_actual_rate(num_channels, scan_rate, &actual_scan_rate);

    uint32_t options = OPTS_CONTINUOUS | OPTS_EXTTRIGGER | OPTS_EXTCLOCK;

    uint16_t read_status = 0;
    uint32_t samples_read_per_channel = 0;


    // Select an MCC118 HAT device to use.
    if (select_hat_device(HAT_ID_MCC_118, &address))
    {
        // Error getting device.
        return -1;
    }

    printf ("\nSelected MCC 118 device at address %d\n", address);

    // Open a connection to the device.
    result = mcc118_open(address);
    STOP_ON_ERROR(result);

    convert_options_to_string(options, options_str);
    convert_chan_mask_to_string(channel_mask, channel_string) ;

    printf("\nMCC 118 continuous scan example\n");
    printf("    Functions demonstrated:\n");
    printf("        mcc118_a_in_scan_start\n");
    printf("        mcc118_a_in_scan_read\n");
    printf("        mcc118_a_in_scan_stop\n");
    printf("    Channels: %s\n", channel_string);
    printf("    Requested scan rate: %-10.2f\n", scan_rate);
    printf("    Actual scan rate: %-10.2f\n", actual_scan_rate);
    printf("    Options: %s\n", options_str);

    printf("\nPress ENTER to continue ...\n");
    scanf("%c", &c);

    // Configure and start the scan.
    // Since the continuous option is being used, the samples_per_channel 
    // parameter is ignored if the value is less than the default internal
    // buffer size (10000 * num_channels in this case). If a larger internal
    // buffer size is desired, set the value of this parameter accordingly.
    result = mcc118_a_in_scan_start(address, channel_mask, samples_per_channel,
        scan_rate, options);
    STOP_ON_ERROR(result);

    STOP_ON_ERROR(mcc118_a_in_scan_buffer_size(address,
        &internal_buffer_size_samples));
    printf("Internal data buffer size:  %d\n", internal_buffer_size_samples);


    printf("\nStarting scan ... Press ENTER to stop\n\n");


	printf("\nPress Trigger\n");


    // Create the header containing the column names.
    strcpy(display_header, "Samples Read    Scan Count    ");
    for (i = 0; i < num_channels; i++)
    {
        sprintf(channel_string, "Channel %d   ", channel_array[i]);
        strcat(display_header, channel_string);
    }
    strcat(display_header, "\n");
    printf("%s", display_header);

 int j=0,p=0,l=0,sum=0,code_array[1000];


    // Continuously update the display value until enter key is pressed
    do 
    {
        // Since the read_request_size is set to -1 (READ_ALL_AVAILABLE), this
        // function returns immediately with whatever samples are available (up
        // to user_buffer_size) and the timeout parameter is ignored.
        result = mcc118_a_in_scan_read(address, &read_status, read_request_size,
            timeout, read_buf, user_buffer_size, &samples_read_per_channel);
        STOP_ON_ERROR(result);
        if (read_status & STATUS_HW_OVERRUN)
        {
            printf("\n\nHardware overrun\n");
            break;
        }
        else if (read_status & STATUS_BUFFER_OVERRUN)
        {
            printf("\n\nBuffer overrun\n");
            break;
        }

        total_samples_read += samples_read_per_channel;

        // Display the last sample for each channel.
    //    printf("\r%12.0d    %10.0d ", samples_read_per_channel,
    //        total_samples_read);
  //   printf("%d",samples_read_per_channel);
        if (samples_read_per_channel > 0)
        {
            int index = samples_read_per_channel * num_channels - num_channels;
// printf("Check");
            for (i = 0; i < num_channels; i++)
            {
            //    printf("%10.5f V", read_buf[index + i]);
               if((read_buf[index+i]*100)<1)

	{l=1;
	}
	else{l=0;}

	sum=sum+l;
	// delay(100);
	if(sum>4){
	if (sum==5)
	{sum++;
		
	break;}
	
	if((read_buf[index+i]*100)<1)
	{l=1;
	}
	else{l=0;}
	   //
	   // delay(120);
		
	code_array[j]=l;

	printf("%d",code_array[j]);

	j++;
	if(j==32)
	{p++;
	printf("\n");
	j=0;
	}

   if ((j==0) && (p==4))
   {printf("\n");
	   
	   p=0;} 
	  

            }
          //  fflush(stdout);
        }

       // usleep(500000);
  } }
    while ((result == RESULT_SUCCESS) &&
           ((read_status & STATUS_RUNNING) == STATUS_RUNNING) && 
           !enter_press());

    printf("\n");

stop:
    print_error(mcc118_a_in_scan_stop(address));
    print_error(mcc118_a_in_scan_cleanup(address));
    print_error(mcc118_close(address));

    return 0;
}

timrowledge
Posts: 1384
Joined: Mon Oct 29, 2012 8:12 pm
Location: Vancouver Island
Contact: Website

Re: RTOS on raspberry pi3

Thu Feb 07, 2019 4:48 am

I’d consider using an ESP8266 to actually do your time-sensitive readings and them connect it to a Pi.
The nice thing about the esp is you can program it with the Arduino IDE (amongst other things) and it has WiFi built in. Treat it as a much faster Arduino. They’re very cheap too - $5 will get you one delivered to your door.
Connect to the Pi via mqtt, for example.
Making Smalltalk on ARM since 1986; making your Scratch better since 2012

rompelstilchen
Posts: 71
Joined: Thu Mar 03, 2016 10:37 am

Re: RTOS on raspberry pi3

Wed Jun 24, 2020 7:39 pm

paolojo wrote:
Thu Jan 04, 2018 10:55 pm
Why Arduino?
if you just need sensors reading, why raspberry pi ?

rompelstilchen
Posts: 71
Joined: Thu Mar 03, 2016 10:37 am

Re: RTOS on raspberry pi3

Wed Jun 24, 2020 7:40 pm

murtaza wrote:
Thu Oct 04, 2018 5:56 pm
For sophisticated real time application, you can use ROS(robot operating system). It is a framework works stably over UBUNTU.
nothing to do with real time

User avatar
topguy
Posts: 7231
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: RTOS on raspberry pi3

Thu Jun 25, 2020 12:01 am

if you just need sensors reading, why raspberry pi ?
Why answer a 16 months old thread...

Return to “Raspberry Pi OS”