Ask Your Question

Cry-A-Lot's profile - activity

2020-08-26 13:38:55 -0500 received badge  Popular Question (source)
2020-08-26 03:41:53 -0500 edited question how to use static library which find_package() by another catkin package

how to use static library which find_package() by another catkin package this is my workspace tree . └── src

2020-08-26 03:41:35 -0500 edited question how to use static library which find_package() by another catkin package

how to use static library which find_package() by another catkin package this is my workspace tree . └──

2020-08-26 03:41:22 -0500 asked a question how to use static library which find_package() by another catkin package

how to use static library which find_package() by another catkin package this is my workspace tree . └── src

2020-08-05 04:53:04 -0500 received badge  Student (source)
2020-08-05 04:32:14 -0500 edited question how to include catkin package ?

how to include catkin package ? suppose i have directory tree like this : . ├── .catkin_tools │ ├── CATKIN_IGNORE │

2020-08-05 04:03:24 -0500 edited question how to include catkin package ?

how to include catkin package ? suppose i have directory tree like this : . ├── .catkin_tools │ ├── CATKIN_IGNORE │

2020-08-05 04:02:12 -0500 edited question how to include catkin package ?

how to include catkin package ? suppose i have directory tree like this : . ├── .catkin_tools │ ├── CATKIN_IGNORE │

2020-08-05 03:59:59 -0500 edited question how to include catkin package ?

how to include catkin package ? suppose i have directory tree like this : . ├── .catkin_tools │ ├── CATKIN_IGNORE │

2020-08-05 03:59:00 -0500 marked best answer how to include catkin package ?

suppose i have directory tree like this :

.
├── .catkin_tools
│   ├── CATKIN_IGNORE
│   ├── profiles
│   │   └── default
│   ├── README
│   └── VERSION
└── src
    ├── pkg_a
    │   ├── CMakeLists.txt
    │   ├── mutiply.cpp
    │   ├── package.xml
    │   └── sumfunc.cpp
    └── pkg_b
        ├── CMakeLists.txt
        ├── main.cpp
        └── package.xml

6 directories, 10 files

how can i edit CMakeLists.txt So that i can use those file in pkg_a inside pkg_b/main.cpp like this :

#include <pkg_a/mutiply.cpp>
#include <pkg_a/sumfunc.cpp>
#include <pkg_a/someheader.h>// or maybe this one

int main(void) {
    int sum_result = sum(5,5);
    int muli_result = muti(5,5);
    return 0;
}

NOTE : i already take a look at this recommend but i not quite understand it.

Edit :

after @Weasfas Answer i have create func_terminal.h file in pkg_a and have this tree file :

└── src
    ├── pkg_a
    │   ├── CMakeLists.txt
    │   ├── func_terminal.h
    │   ├── mutiply.cpp
    │   ├── package.xml
    │   └── sumfunc.cpp
    └── pkg_b
        ├── CMakeLists.txt
        ├── main.cpp
        └── package.xml

and add some command in cmakeList.txt in pkg_b : add find package

find_package(catkin REQUIRED COMPONENTS roscpp pkg_a)

add include_directories

include_directories(
  include
  ${catkin_INCLUDE_DIRS}

)

add catkin package

catkin_package(
  CATKIN_DEPENDS pkg_a
)

and in building

add_executable(main_node main.cpp) 
target_link_libraries(main_node ${catkin_LIBRARIES}) 
add_dependencies(main_node ${catkin_EXPORTED_TARGETS})

then edit package.xml by add these line

  <build_depend>pkg_a</build_depend>
  <build_export_depend>pkg_a</build_export_depend>
  <exec_depend>pkg_a</exec_depend>

but i will get an error

fatal error: pkg_a/func_terminal.h: No such file or directory

from catkin build if i try to add this line #include <pkg_a/func_terminal.h> in pkg_b/main.cpp file

Edit #2(RECAP):

I'll explain the solution i have got thank to @Weasfas steb by steb here : first i need to create a proper catkin_work_space for example in my case i use these command :

mkdir tryCatkin && mkdir tryCatkin/src && cd tryCatkin && catkin_make

then i can either use catkin_create_pkg command or just create out of of nowhere by following catkin package format which will create directory tree like this:

├── src
│   ├── CMakeLists.txt -> /opt/ros/kinetic/share/catkin/cmake/toplevel.cmake
│   ├── pkg_a
│   │   ├── CMakeLists.txt
│   │   ├── include
│   │   │   └── pkg_a
│   │   │       └── fuction_terminal.hpp
│   │   ├── package.xml
│   │   └── src
│   │       └── function_terminal.cpp
│   └── pkg_b
│       ├── CMakeLists.txt
│       ├── include
│       │   └── pkg_b
│       ├── package.xml
│       └── src
│           └── main.cpp

in pkg_b/src/main.cpp :

#include <iostream>
#include <pkg_a/fuction_terminal.hpp>

int main(void) {
    int sum_result = sumation(5,5); ///sumation is function in func_terminal.hpp
    std::cout << "test :  " << sum_result;

    return 0;
}

then setup those package.xml and CmakeList.txt which i follow from @Weasfas instruction. first in pkg_a/Cmakelist.txt :

cmake_minimum_required(VERSION 2.8.3)
project(pkg_a)

find_package(catkin REQUIRED COMPONENTS)

catkin_package(
  INCLUDE_DIRS include
  LIBRARIES SumFunc
)

include_directories(
  include
  ${catkin_INCLUDE_DIRS}
)

add_library(SumFunc
   src/function_terminal.cpp
)

pkg_b/CmakeList.txt :

cmake_minimum_required(VERSION 2.8.3)
project(pkg_b)


find_package(catkin REQUIRED COMPONENTS
  pkg_a
)
catkin_package()

include_directories(
  ${catkin_INCLUDE_DIRS}
)

add_executable(main_node src/main.cpp)

target_link_libraries(main_node
  ${catkin_LIBRARIES}
)

and then in pkg_b/package.xml add this line:

  <depend>pkg_a</depend>
2020-08-05 03:58:21 -0500 commented answer how to include catkin package ?

it work now, THANK!!!

2020-08-05 03:58:06 -0500 edited question how to include catkin package ?

how to include catkin package ? suppose i have directory tree like this : . ├── .catkin_tools │ ├── CATKIN_IGNORE │

2020-08-04 06:56:16 -0500 commented answer how to include catkin package ?

if i replace package_a with pkg_a it still give an error : Project 'pkg_a' specifies 'include' as an include dir, which

2020-08-04 06:56:04 -0500 commented answer how to include catkin package ?

if i replace package_a with pkg_a it still give an error : "Project 'pkg_a' specifies 'include' as an include dir, which

2020-08-04 06:52:57 -0500 commented answer how to include catkin package ?

if i replace package_a with pkg_a it still give an error : "Project 'pkg_a' specifies 'include' as an include dir, which

2020-08-04 02:14:11 -0500 commented answer how to include catkin package ?

it only occur when i add package_a inside find_package(catkin REQUIRED COMPONENTS roscpp std_msgs # package_a)

2020-08-04 02:09:37 -0500 commented answer how to include catkin package ?

it only occur when i add package_a inside find_package(catkin REQUIRED COMPONENTS roscpp std_msgs # package_a)

2020-08-03 02:59:08 -0500 commented answer how to include catkin package ?

i have follow instruction from you EDIT section , but i still doesn't work with me and got an error : "Could not find a

2020-08-02 23:51:51 -0500 received badge  Notable Question (source)
2020-07-31 02:37:17 -0500 received badge  Enthusiast
2020-07-30 02:02:26 -0500 edited question how to include catkin package ?

how to include catkin package ? suppose i have directory tree like this : . ├── .catkin_tools │ ├── CATKIN_IGNORE │

2020-07-30 02:01:45 -0500 edited question how to include catkin package ?

how to include catkin package ? suppose i have directory tree like this : . ├── .catkin_tools │ ├── CATKIN_IGNORE │

2020-07-30 02:01:45 -0500 received badge  Editor (source)
2020-07-30 01:59:02 -0500 edited question how to include catkin package ?

how to include catkin package ? suppose i have directory tree like this : . ├── .catkin_tools │ ├── CATKIN_IGNORE │

2020-07-29 16:46:38 -0500 received badge  Popular Question (source)
2020-07-29 10:11:17 -0500 received badge  Popular Question (source)
2020-07-29 02:40:18 -0500 commented answer how to include catkin package ?

i try to edit like you said but i still got an error: "fatal error: pkg_a/func_terminal.h: No such file or directory" wh

2020-07-24 05:35:51 -0500 asked a question how to include catkin package ?

how to include catkin package ? suppose i have directory tree like this : . ├── .catkin_tools │ ├── CATKIN_IGNORE │

2020-07-17 05:45:50 -0500 marked best answer rospy Subscriber callback threading test

I try to use rospy Subscriber callback handler to manipulate some object but it doesn't work like i would like to.

In,subscriber handler is look like this :

import rospy from std_msgs.msg import String import time

verboser = True

def counter() :
    counter = 0
    while(verboser and counter < 20 ):
        counter += 1
        time.sleep(1)
        print(counter)

def callback(data):
    print("data INcoming : ",data.data)
    if int(data.data) == 1:
        counter()
    else :
        global verboser
        verboser = False

def main():
    rospy.init_node('listener')
    sub = rospy.Subscriber('chatter', String,callback)

if __name__ == '__main__':
    main()
    rospy.spin()

if i try to command counter() function with code like this :

import rospy
from std_msgs.msg import String
import time

def talker():
    pub = rospy.Publisher('chatter', String, queue_size=10)
    rospy.init_node('talker', anonymous=True)
    hello_str = "1"
    pub.publish(hello_str)
    time.sleep(5)
    hello_str = "0"
    pub.publish(hello_str)

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

it produce this output :

data INcoming :  1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
data INcoming :  0

but if i change talker to publish only one and re-run it with change variable 'hello_str' it seem counter() function does stop after run the process

import rospy
from std_msgs.msg import String
import time

def talker():
    pub = rospy.Publisher('chatter', String, queue_size=10)
    rospy.init_node('talker', anonymous=True)
    hello_str = "1"
    pub.publish(hello_str)

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

ouput :

data INcoming :  1
1
2
3
4
5
6
data INcoming :  0
7

and i try to check if publisher publish after sleep 5 second via 'rostopic echo /chatter' and it seem it does send. so i think the rospy.Subscriber() is refuse to new threading callback that have been publish from the same process until it finish. Is there anyway to config rospy to accept this ?

2020-07-17 05:45:50 -0500 received badge  Scholar (source)
2020-07-17 05:45:49 -0500 received badge  Supporter (source)
2020-07-17 05:45:47 -0500 commented answer rospy Subscriber callback threading test

so, even though ros publisher is asynchronous, pyros still has it own limitation that there is only one thread that all

2020-07-16 06:32:29 -0500 commented question rospy Subscriber callback threading test

the point in this test is i try to start then stop it by using the same subscriber,but it doesn't work out when i usin

2020-07-14 06:24:41 -0500 asked a question rospy Subscriber callback threading test

rospy Subscriber callback threading test I try to use rospy Subscriber callback handler to manipulate some object but it