ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

erjohn's profile - activity

2018-08-02 10:45:04 -0500 received badge  Famous Question (source)
2018-07-28 00:53:59 -0500 received badge  Famous Question (source)
2018-07-27 09:03:56 -0500 marked best answer USB camera does not take any pictures when ROS is launched at system startup

I have been trying to take pictures using a USB cam connected to my Jetson TX2. My code works pretty well when I execute it from terminal using the command roslaunch my_ros my_launch_file.launch and takes the pictures and saves them in a particular path. However, when I run the launch file at system startup, the code runs and the USB camera is triggered (the light on the camera tuns on) but no images are generated in the given path. Here is my code along with the explanations.

import rospy
from std_msgs.msg import Float32MultiArray
import cv2
import commands
import time

no_of_cameras = 2 # define number of attached cameras
time.sleep(120) # allow some time for the system see the usb camera

# this function returns the number of connected cameras
def getCameraInfo():

   Res=commands.getoutput("ls -l /dev/video*") #search for cameras attached
   CamCnt=Res.count("video") #getting number of cameras attached the board
   return CamCnt/2 

def process_image(frame, i):
    ###
    ### Image Processing code comes here
    ###
    if i == 6:
        res = True
    if i != 6:
        res = False    
    return res      

def talker():
    pub = rospy.Publisher('servo', Float32MultiArray, queue_size=10)
    rospy.init_node('talker', anonymous=True)
    # check for the number of cameras continuously 
    while True: 
        er = getCameraInfo()
        if er > 1:
            break 
        time.sleep(5)

    cap = cv2.VideoCapture(1) # indicator light on my usb cam is turned ON when this command is executed

    rate1 = rospy.Rate(0.5)

    forward_slow = Float32MultiArray()  
    dont_move = Float32MultiArray()
    forward_slow.data = [90,84]
    dont_move.data = [90,90]

    i = 0
    while not rospy.is_shutdown():
        image_name = "/home/nvidia/Desktop/my_ros/cam" + str(i) + ".png" # define path and name of the image
        ret,frame=cap.read()
        cv2.imwrite(image_name, frame)
        res = process_image(frame, i) # image processing function. not related to to the problem

        if res:
            rospy.loginfo(dont_move)
            pub.publish(dont_move)
            rospy.sleep(1)  

        if not res:
            rospy.loginfo(forward_slow)
            pub.publish(forward_slow)
            rospy.sleep(1)

        i = i + 1
        rate1.sleep()
    cap.release() # indicator light on my usb cam is turned OFF when this command is executed

if __name__ == '__main__':    
    try:
        talker()
    except rospy.ROSInterruptException:
        pass

What I am basically trying to do here is to take pictures with predefined intervals and then process them. According to the result of image processing, I will control robot with some basic commands (go forward, dont move,...). But I cannot figure out what sort of problem may be preventing the program from saving images when it is run automatically at system startup. Any kind of comments are appreciated (ros distro: kinetic)

2018-07-27 09:03:04 -0500 answered a question USB camera does not take any pictures when ROS is launched at system startup

I solved the problem by following the solution given here. I used to call roslaunch in my rc.local file as su ubuntu

2018-07-26 03:45:29 -0500 received badge  Student (source)
2018-07-26 00:45:04 -0500 received badge  Enthusiast
2018-07-25 15:15:42 -0500 received badge  Popular Question (source)
2018-07-25 15:15:42 -0500 received badge  Notable Question (source)
2018-07-25 02:51:39 -0500 asked a question USB camera does not take any pictures when ROS is launched at system startup

USB camera does not take any pictures when ROS is launched at system startup I have been trying to take pictures using a

2018-07-18 23:58:35 -0500 received badge  Supporter (source)
2018-07-18 23:58:32 -0500 marked best answer run ros terminal commands within a python script

I have my ros program ready, and I can control my robot using the terminal commands. Now, I am trying to write a python script to control the robot as I do with the terminal commands. For this purpose, I have been trying several methods explained by others. As expected, I begin with starting the roscore. However, I get error and cannot proceed. Here are what I have done so far:

1- As given here, I ran the following code

import subprocess 
roscore = subprocess.Popen('roscore') 
time.sleep(1)

and got this error:

>>> runfile('/opt/ros/kinetic/bin/run_roscore.py', wdir='/opt/ros/kinetic/bin')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 699, in runfile
    execfile(filename, namespace)
  File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 81, in execfile
    builtins.execfile(filename, *where)
  File "/opt/ros/kinetic/bin/run_roscore.py", line 20, in <module>
    roscore = subprocess.Popen('roscore')
  File "/usr/lib/python2.7/subprocess.py", line 711, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1343, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

2- Trying the same code with shell=True option,

roscore = subprocess.Popen('roscore', shell=True)

gives the output:

runfile('/opt/ros/kinetic/bin/run_roscore.py', wdir='/opt/ros/kinetic/bin')
/bin/sh: 1: roscore: not found

3- I also tired other libaries: os and commands

import os
os.system('roscore')

and

import commands
a=commands.getoutput('roscore')
print a

to get the same error:

runfile('/opt/ros/kinetic/bin/run_roscore.py', wdir='/opt/ros/kinetic/bin')
sh: 1: roscore: not found

4- I can run general linux commands with no error. For example the codes below successfully lists the files:

os.system('ls -l')
subprocess.Popen('ls -l', shell=True)
a=commands.getoutput('ls -l')
print a

Here, run_roscore.py is my python file and I placed it in the same directory with roscore file.

According to my intuition, it looks like a problem with setup.bash file, but I cannot figure out what the problem is.

I am using ROS Kinetic and Ubuntu 16.04 LTS on Nvidia Jetson TX2 developer kit

When giving your answer please, keep in mind that I am not experienced with ROS and Ubuntu environments. So I appreciate if you provide the steps clearly.

Also, please note that starting the roscore is an error I encountered at the beginning of my ultimate goal. At the next steps, I will need to run other commands such as

rostopic pub servo std_msgs/UInt16 80

and

rosrun rosserial_python serial_node.py /dev/ttyACM0

So you may also provide a general recommendation covering my overall goal.

2018-07-18 23:58:32 -0500 received badge  Scholar (source)
2018-07-13 03:34:26 -0500 received badge  Notable Question (source)
2018-07-12 12:33:34 -0500 received badge  Popular Question (source)
2018-07-12 07:51:51 -0500 asked a question run ros terminal commands within a python script

run ros terminal commands within a python script I have my ros program ready, and I can control my robot using the termi