Error when trying to launch nodes on reboot!


#1

Hello! I have some problems when trying to launch ros-nodes on boot. When I try to roslaunch the file after boot it doesn’t work, I need to source the catkin_ws before launching every time. I want the launch files that I put into the “user.launch” file to autostart when rebooting. So I either need some kind of auto-sourcing when booting or in some way save the source.

I have tried with adding “source /home/flytos/catkin_ws/devel/setup.bash” in the .bashrc too without success regarding autostart on reboot. This fixed the problem with needed source every time I wanted to roslaunch though.

BR,

Jonas


How do I autostart a node that needs sudo permission?
#2

Instead of adding the source command in .bashrc, add it to the end of /etc/bash.bashrc


#3

Ah, thanks for the response! It fixed my problem with the source but I still can’t launch the node that requires “sudo python” to run, do you have any solution for that? Tried with launch-prefix=“sudo” but it doesn’t work. It’s password protected btw.


#4

What is the content of user.launch file? Can you please share it over here.

Also what command do you to run to start your node?


#5

the content of user.launch file is:
flytos@flytos:/flyt/flytos/flytcore/share/core_api/launch$ cat user.launch
launch>
include file="/home/flytos/catkin_ws/src/fp_onboard/launch/fp_temp.launch"/>
include file="/home/flytos/catkin_ws/src/fp_onboard/launch/fp_led.launch"/>
</launch
I try to run the sudo python permitted code with “roslaunch fp_onboard fp_led.launch” from the workspace. The log file when the process dies is empty.
The command that does work is: “sudo python testdrone_led.py” or “sudo ./testdrone_led.py” .
I think the autolaunch when booting worked once when I made the sudo “passwordless” and added launch-prefix=“sudo” in the XML of “fp_led.launch” file.
With sudo visudo i added in the bottom: %flytos ALL=(root) NOPASSWD: /home/flytos/catkin_ws/src/fp_onboard/scripts/testdrone_led.py


#6

edit*
The XML code in the user.launch file has a < sign before launch and a > after </launch.
Had some brain-error posting it :slight_smile:

BR,
Jonas


#7

Don’t worry, it was not an error from your end. This renderer formats ‘<’ sign.
Please use ‘Preformatted text’ option (available in the top bar of this editor) when sharing code next time.

If possible please share your entire workspace source code, so that I could take a closer look at it. If not possible, please post the output when you run this command:

roslaunch fp_onboard fp_led.launch

Moreover, why does your code need ‘sudo’ permission?


#8

Need it because the code is for controlling addressable LEDs with Neopixel. (ws2812b)

That I will do :slight_smile:

This is the python code:
#!/usr/bin/env python
import time
from neopixel import *
import argparse
#import rospy
#from mavros_msgs.msg import State

# LED strip configuration:

LED_COUNT      = 28      # Number of LED pixels.

LED_PIN        = 18      # GPIO pin connected to the pixels (18 uses PWM!).

#LED_PIN        = 10      # GPIO pin connected to the pixels (10 uses SPI /dev/spidev0.0).

LED_FREQ_HZ    = 800000  # LED signal frequency in hertz (usually 800khz)

LED_DMA        = 10      # DMA channel to use for generating signal (try 10)

LED_BRIGHTNESS = 255     # Set to 0 for darkest and 255 for brightest

LED_INVERT     = False   # True to invert the signal (when using NPN transistor level shift)

LED_CHANNEL    = 0       # set to '1' for GPIOs 13, 19, 41, 45 or 53

#isArmed = False

#def state_callback(data):
#    global isArmed
#    mode, is_armed = data.mode, data.armed
#    isArmed = is_armed
    
def ClearLights(strip, color, wait_ms=0):
    for i in range(0, LED_COUNT):
        strip.setPixelColor(i, color)
        strip.show()
        time.sleep(wait_ms/1000.0)

def FrontRight(strip, color, wait_ms=0):
    for i in range(0, 7):
        strip.setPixelColor(i, color)
        strip.show()
        time.sleep(wait_ms/1000.0)

def FrontLeft(strip, color, wait_ms=0):
    for i in range(7, 14):
        strip.setPixelColor(i, color)
        strip.show()
        time.sleep(wait_ms/1000.0)

def Pause(strip, wait_ms=150):
    for i in range(0, LED_COUNT):
        strip.show()
        time.sleep(wait_ms/1000.0)


def FrontBlinkRight(strip, color, wait_ms=0):
    for i in range(5, 7):
        strip.setPixelColor(i, color)
        strip.show()
        time.sleep(wait_ms)
        for j in range(0, LED_COUNT):
            strip.setPixelColor(5,Color(255,255,255))
        for k in range(0, LED_COUNT):
            strip.setPixelColor(6, Color(255,255,255))

def FrontBlinkLeft(strip, color, wait_ms=0):
    for i in range(12, 14):
        strip.setPixelColor(i, color)
        strip.show()
        time.sleep(wait_ms)
        for j in range(0, LED_COUNT):
            strip.setPixelColor(12,Color(255,255,255))
        for k in range(0, LED_COUNT):
            strip.setPixelColor(13, Color(255,255,255))

def RearBlink1(strip, color, wait_ms=0):
    for i in range(14, LED_COUNT):
        strip.setPixelColor(i, color)
        strip.show()
        time.sleep(wait_ms)
        for j in range(14, LED_COUNT):
            strip.setPixelColor(i, 0)
            strip.show()
            for k in range(14, LED_COUNT):
                strip.setPixelColor(i, 0)
                strip.show()


def RearBlink2(strip, color, wait_ms=0):
    for i in range(14, LED_COUNT):
        strip.setPixelColor(i, color)
        strip.show()
        time.sleep(wait_ms)
        for j in range(14, LED_COUNT):
            strip.setPixelColor(i, 0)
            strip.show()
            for k in range(14, LED_COUNT):
                strip.setPixelColor(i, 0)
                strip.show()

# Main program logic follows:

if __name__ == '__main__':

    rospy.init_node('callback_ledsArmed', anonymous=False)
    state_sub = rospy.Subscriber(("/flytos/flyt/state"), State, state_callback)

    # Process arguments

    parser = argparse.ArgumentParser()

    parser.add_argument('-c', '--clear', action='store_true', help='clear the display on exit')

    args = parser.parse_args()

    # Create NeoPixel object with appropriate configuration.

    strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL)

    # Intialize the library (must be called once before other functions).

    strip.begin()

    print ('Press Ctrl-C to quit.')

    if not args.clear:

        print('Use "-c" argument to clear LEDs on exit')


    while not rospy.is_shutdown():
        try:

            #if isArmed == True:
                FrontRight(strip, Color(255, 0, 0)) # Green Right
                FrontLeft(strip, Color(0, 255, 0)) # Red Left
                Pause(strip, )
                FrontBlinkLeft(strip, Color(255, 255, 255)) # White Blink Front Left
                FrontBlinkRight(strip, Color(255, 255, 255)) # White Blink Front Right
                RearBlink1(strip, Color(255, 255, 255)) # White Blink Rear
                RearBlink2(strip, Color(255, 255, 255))
            #elif isArmed == False:
                #ClearLights(strip, Color(0,0,0))

        except rospy.ROSInterruptException:   

            if args.clear:  

                ClearLights(strip, Color(0,0,0))

This is the output when running

... logging to /home/flytos/.ros/log/792d9192-a776-11e8-ac9a-b827eb7e3870/roslaunch-flytos-11607.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://flytos:43788/

SUMMARY
========

PARAMETERS
 * /rosdistro: kinetic
 * /rosversion: 1.12.13

NODES
  /
    fp_led (fp_onboard/testdrone_led.py)

ROS_MASTER_URI=http://localhost:11311

process[fp_led-1]: started with pid [11654]
usage: testdrone_led.py [-h] [-c]
testdrone_led.py: error: unrecognized arguments: __name:=fp_led __log:=/home/flytos/.ros/log/792d9192-a776-11e8-ac9a-b827eb7e3870/fp_led-1.log
[fp_led-1] process has died [pid 11654, exit code 2, cmd /home/flytos/catkin_ws/src/fp_onboard/scripts/testdrone_led.py __name:=fp_led __log:=/home/flytos/.ros/log/792d9192-a776-11e8-ac9a-b827eb7e3870/fp_led-1.log].
log file: /home/flytos/.ros/log/792d9192-a776-11e8-ac9a-b827eb7e3870/fp_led-1*.log
all processes on machine have died, roslaunch will exit
shutting down processing monitor...
... shutting down processing monitor complete
done

Thanks for the fast response!


#9

some parts in the code is commented out, because at the moment I “crontab” launch it when reboot. It’s working with the mavros state too, but due to the error autolaunching I went back to the “old” code without rospy. e.g. I commented out:
#except rospy.ROSInterruptException:
and used
except KeyboardInterrupt

same with:
#while not rospy.is_shutdown():

try:
    while True:

since I commented out rospy*.


#10

According to the log, the issue seems to be in the launch file itself.
Please share the launch file ‘fp_led.launch’


#11

Okey, I see. Here’s the launch-file:

<launch>
<node pkg="fp_onboard" type="testdrone_led.py" name="fp_led" launch-prefix="sudo" />
</launch>

#12

So the issue is indeed with the launch file.

testdrone_led.py expects arguments which the launch file is not providing.
Use the args feature.
For more info, check here.