raulzito234

A nerd blog about cs

Month: May, 2013

Installing ROS (Robot Operating System) on MAC

I’m following the manual here: ROS Manual Page When I try to make the program:


make -j8

I’m getting the following error:


Linking CXX shared library ../devel/lib/librospack.dylib

Linking CXX shared library ../devel/lib/librosconsole.dylib

Undefined symbols for architecture x86_64:
 "boost::filesystem3::path::wchar_t_codecvt_facet()", referenced from:
 boost::filesystem3::path::codecvt() in rospack.cpp.o

Undefined symbols for architecture x86_64:
 "boost::this_thread::get_id()", referenced from:
 ros::console::print(ros::console::FilterBase*, log4cxx::Logger*, ros::console::levels::Level, char const*, int, char const*, char const*, ...) in rosconsole.cpp.o
 ros::console::print(ros::console::FilterBase*, log4cxx::Logger*, ros::console::levels::Level, std::basic_stringstream<char, std::char_traits, std::allocator > const&, char const*, int, char const*) in rosconsole.cpp.o
 ros::console::ThreadToken::getString(log4cxx::helpers::ObjectPtrT const&) in rosconsole.cpp.o
ld: symbol(s) not found for architecture x86_64
 "boost::filesystem3::path::m_erase_redundant_separator(unsigned long)", referenced from:
 boost::filesystem3::path& boost::filesystem3::path::append(std::string const&, std::codecvt<wchar_t, char, __mbstate_t> const&) in rospack.cpp.o
 "boost::filesystem3::path::m_append_separator_if_needed()", referenced from:
 boost::filesystem3::path& boost::filesystem3::path::append(std::string const&, std::codecvt<wchar_t, char, __mbstate_t> const&) in rospack.cpp.o
 "boost::filesystem3::path::operator/=(boost::filesystem3::path const&)", referenced from:
 rospack::Rosstackage::exports_dry_package(rospack::Stackage*, std::string const&, std::string const&, std::vector<std::string, std::allocator >&) in rospack.cpp.o
 boost::filesystem3::operator/(boost::filesystem3::path const&, boost::filesystem3::path const&) in rospack.cpp.o
 "boost::filesystem3::detail::current_path(boost::system::error_code*)", referenced from:
 boost::filesystem3::current_path() in rospack.cpp.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [devel/lib/librosconsole.dylib] Error 1
 "boost::filesystem3::detail::dir_itr_close(void*&, void*&)", referenced from:
make[1]: *** [rosconsole/CMakeFiles/rosconsole.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
 boost::filesystem3::detail::dir_itr_imp::~dir_itr_imp() in rospack.cpp.o
 "boost::filesystem3::detail::create_directory(boost::filesystem3::path const&, boost::system::error_code*)", referenced from:
 boost::filesystem3::create_directory(boost::filesystem3::path const&) in rospack.cpp.o
 "boost::filesystem3::detail::directory_iterator_construct(boost::filesystem3::directory_iterator&, boost::filesystem3::path const&, boost::system::error_code*)", referenced from:
 boost::filesystem3::directory_iterator::directory_iterator(boost::filesystem3::path const&) in rospack.cpp.o
 "boost::filesystem3::detail::directory_iterator_increment(boost::filesystem3::directory_iterator&, boost::system::error_code*)", referenced from:
 boost::filesystem3::directory_iterator::increment() in rospack.cpp.o
 "boost::filesystem3::detail::status(boost::filesystem3::path const&, boost::system::error_code*)", referenced from:
 boost::filesystem3::is_directory(boost::filesystem3::path const&) in rospack.cpp.o
 boost::filesystem3::is_regular_file(boost::filesystem3::path const&) in rospack.cpp.o
 boost::filesystem3::exists(boost::filesystem3::path const&) in rospack.cpp.o
 "boost::filesystem3::path::parent_path() const", referenced from:
 rospack::Rosstackage::inStackage(std::string&) in rospack.cpp.o
 "boost::filesystem3::path::filename() const", referenced from:
 rospack::Rosstackage::isStackage(std::string const&) in rospack.cpp.o
 rospack::Rosstackage::crawlDetail(std::string const&, bool, int, bool, std::vector<rospack::DirectoryCrawlRecord*, std::allocator<rospack::DirectoryCrawlRecord*> >&, boost::unordered_set<std::string, boost::hash, std::equal_to, std::allocator >&) in rospack.cpp.o
 rospack::Rosstackage::inStackage(std::string&) in rospack.cpp.o
 rospack::Rosstackage::addStackage(std::string const&) in rospack.cpp.o

ld: symbol(s) not found for architecture x86_64

clang: error: linker command failed with exit code 1 (use -v to see invocation)

make[2]: *** [devel/lib/librospack.dylib] Error 1

make[1]: *** [rospack/CMakeFiles/rospack.dir/all] Error 2

make: *** [all] Error 2

The problem is when linking the following libraries: rospack and rosconsole To compile and link the libraries, the ROS package is using:

CMake

Cmake is a tool for helping software compilation. It creates the Makefiles necessary for compiling. To achieve that, it’s necessary to create files that will inform the dependencies and whatnot into the packages being built. These files containing the information of how to compile and what is necessary to compile these files are CMakeLists.txt. There is a command to include external libraries called find_package The problem seems to be that when finding the package, CMake is including a newer version of the library that I need (in my case boost). To include a specific version of a library, you can write the following:


find_package(<library_name> <version_number> EXACT)

In my case I wrote:


find_package(boost 1.47 EXACT)

Then when I tried to build the packages running:


make VERBOSE=1

It said that the library installed was not the one required, it was a new one in /usr/local/. So I installed an older version of the library with homebrew. Using the following commands:

$ brew versions boost
$ git checkout 57665ff /usr/local/Library/Formula/boost.rb
$ brew install boost
$ git checkout master

EDIT #1: It seems that this is a known issue.

EDIT #2: Running gdb with the program appears to show the probable problem that is causing the program to present the malloc issue. GDB is a tool to debug running code, allowing to see what is going on “inside” the program. I ran the following code:


$ gdb rospack

which outputs the following message:


warning: Could not find object file "/private/tmp/boost-HXkH/boost_1_47_0/bin.v2/libs/filesystem/build/darwin-4.2.1/release/threading-multi/v2/src/v2_operations.o" - no debug information available for "v2_operations.cpp".

warning: Could not find object file "/private/tmp/boost-HXkH/boost_1_47_0/bin.v2/libs/filesystem/build/darwin-4.2.1/release/threading-multi/v2/src/v2_path.o" - no debug information available for "v2_path.cpp".

warning: Could not find object file "/private/tmp/boost-HXkH/boost_1_47_0/bin.v2/libs/filesystem/build/darwin-4.2.1/release/threading-multi/v2/src/v2_portability.o" - no debug information available for "v2_portability.cpp".

warning: Could not find object file "/private/tmp/boost-HXkH/boost_1_47_0/bin.v2/libs/filesystem/build/darwin-4.2.1/release/threading-multi/v3/src/operations.o" - no debug information available for "operations.cpp".

warning: Could not find object file "/private/tmp/boost-HXkH/boost_1_47_0/bin.v2/libs/filesystem/build/darwin-4.2.1/release/threading-multi/v3/src/path.o" - no debug information available for "path.cpp".

warning: Could not find object file "/private/tmp/boost-HXkH/boost_1_47_0/bin.v2/libs/filesystem/build/darwin-4.2.1/release/threading-multi/v3/src/portability.o" - no debug information available for "portability.cpp".

warning: Could not find object file "/private/tmp/boost-HXkH/boost_1_47_0/bin.v2/libs/filesystem/build/darwin-4.2.1/release/threading-multi/v3/src/codecvt_error_category.o" - no debug information available for "codecvt_error_category.cpp".

warning: Could not find object file "/private/tmp/boost-HXkH/boost_1_47_0/bin.v2/libs/filesystem/build/darwin-4.2.1/release/threading-multi/v3/src/path_traits.o" - no debug information available for "path_traits.cpp".

warning: Could not find object file "/private/tmp/boost-HXkH/boost_1_47_0/bin.v2/libs/filesystem/build/darwin-4.2.1/release/threading-multi/v3/src/unique_path.o" - no debug information available for "unique_path.cpp".

warning: Could not find object file "/private/tmp/boost-HXkH/boost_1_47_0/bin.v2/libs/filesystem/build/darwin-4.2.1/release/threading-multi/v3/src/utf8_codecvt_facet.o" - no debug information available for "utf8_codecvt_facet.cpp".

.
warning: Could not find object file "/private/tmp/boost-HXkH/boost_1_47_0/bin.v2/libs/program_options/build/darwin-4.2.1/release/threading-multi/cmdline.o" - no debug information available for "cmdline.cpp".

warning: Could not find object file "/private/tmp/boost-HXkH/boost_1_47_0/bin.v2/libs/program_options/build/darwin-4.2.1/release/threading-multi/config_file.o" - no debug information available for "config_file.cpp".

warning: Could not find object file "/private/tmp/boost-HXkH/boost_1_47_0/bin.v2/libs/program_options/build/darwin-4.2.1/release/threading-multi/options_description.o" - no debug information available for "options_description.cpp".

warning: Could not find object file "/private/tmp/boost-HXkH/boost_1_47_0/bin.v2/libs/program_options/build/darwin-4.2.1/release/threading-multi/parsers.o" - no debug information available for "parsers.cpp".

warning: Could not find object file "/private/tmp/boost-HXkH/boost_1_47_0/bin.v2/libs/program_options/build/darwin-4.2.1/release/threading-multi/variables_map.o" - no debug information available for "variables_map.cpp".

warning: Could not find object file "/private/tmp/boost-HXkH/boost_1_47_0/bin.v2/libs/program_options/build/darwin-4.2.1/release/threading-multi/value_semantic.o" - no debug information available for "value_semantic.cpp".

warning: Could not find object file "/private/tmp/boost-HXkH/boost_1_47_0/bin.v2/libs/program_options/build/darwin-4.2.1/release/threading-multi/positional_options.o" - no debug information available for "positional_options.cpp".

warning: Could not find object file "/private/tmp/boost-HXkH/boost_1_47_0/bin.v2/libs/program_options/build/darwin-4.2.1/release/threading-multi/utf8_codecvt_facet.o" - no debug information available for "utf8_codecvt_facet.cpp".

warning: Could not find object file "/private/tmp/boost-HXkH/boost_1_47_0/bin.v2/libs/program_options/build/darwin-4.2.1/release/threading-multi/convert.o" - no debug information available for "convert.cpp".

warning: Could not find object file "/private/tmp/boost-HXkH/boost_1_47_0/bin.v2/libs/program_options/build/darwin-4.2.1/release/threading-multi/split.o" - no debug information available for "split.cpp".

.
warning: Could not find object file "/private/tmp/boost-HXkH/boost_1_47_0/bin.v2/libs/system/build/darwin-4.2.1/release/threading-multi/error_code.o" - no debug information available for "error_code.cpp".

Running Condor (CSAIL cluster)

Runing Code:

Create 2 files:

  1. Description file.
  2. Script.

Create this two files under the directory

/data/scratch/

1. The description file, in this case will be called echo.submit and it’s content is:

###standard condor headers for CSAIL###
# preserve your environment variables<br />GetEnv = True
# use the plain nothing special universe<br />Universe = vanilla
# only send email if there's an error<br />Notification = Error
# Allows you to run on different "filesystem domains"
#by copying the files around if needed
should_transfer_files = IF_NEEDED
WhenToTransferOutput = ON_EXIT
###END HEADER###
###job specific bits###
Executable = echo.sh
#Arguments =<br /># queue log (doesn't like to be on NFS due to locking needs)
Log = /tmp/echo.$ENV(USER).log
#What to do with stdin,stdout,stderr
# $(PROCESS) is replaced by the sequential
# run number (zero based) of this submission<br /># see "queue" below
#Input = input.$(PROCESS)
Error = err.$(PROCESS)
Output = out.$(PROCESS)
# how many copies of this job to queue
queue 1
####END job  specific bits###

2. The script contains the code that will run in the machine, in this case echo.sh:

<br /><br />#!/bin/sh<br />echo $PATH<br /><br />

Don’t forget to make the file runnable by you (the user):

>> chmod u+x echo.sh

Then run the code:

 >> condor_submit <description_file>

In my case I ran the command:

>> condor_submit echo.submit

Errors:

If you get the following error:

ERROR: Failed to parse command file (line 3).

Probably you are not using the correct description file or your description file does not contain the correct text.

When running the code I got the following error because I was entering the script file instead of the description file.

Managing Jobs:

The following code allows to manage submitted code:

>> condor_status -submitters

I’m able to see that the code that I submitted is being held. Therefore if you want to see if the code is run, then use the above code.

The following code may not show what jobs are queued or held:

For managing the submitted jobs, the manual says to use the following command to see all the submitted jobs by all users:

>> condor_q

Or the following command (to find jobs submitted by my user):

>> condor_q $USER

When I ran the above code the first times, I got the following response:

— Submitter: borg-login-1.csail.mit.edu : : borg-login-1.csail.mit.edu
ID OWNER SUBMITTED RUN_TIME ST PRI SIZE CMD

0 jobs; 0 completed, 0 removed, 0 idle, 0 running, 0 held, 0 suspended

I.e. the code that I submitted to the clusters seemed to not be submitted.

Some days after the command seemed to be working normally (weird).

Releasing Jobs (Held Jobs):

For many reasons your jobs can be held. One possible reason, for example, is that if you are running matlab you might not have sufficient licenses to run the program. After you run many jobs and have solved such issues you can free your jobs from being on hold using the following command:

>> condor_release -all

This command will release all held jobs. For more information on this go here.

Removing Jobs:

>> condor_rm $USER

Contour Identification and next steps.

My algorithm now compares contours of the same size and returns 1 if it’s of the same class and -1 if they are not from the same class. For achieving that I need to train the algorithm so it can create a SVM for the class.

The problem
The problem is that contours need to be the same size and I need to identify the center of the image to identify it as being as the same class.

The (not) solution
I will resize the image that represents  the contour to the size of the template. Then I will compare them.

But this solution does not work as I would expect. Here’s why:

When resizing the contour our intuition will not be the same as what actually resizing do FOR CONTOURS.

For example (in matlab):

Suppose you have the following matrix that represents the contour:

>> A = [1,0; 1,1]

A =

1 0
1 1

When using imresize, you get the following:

>> B = imresize(A, 2)

B =

1.0753 0.7826 0.1471 -0.1456

1.0560 0.8381 0.3650 0.1471

1.0143 0.9587 0.8381 0.7826

0.9951 1.0143 1.0560 1.0753

This is not the resized contour that we expected. First of all, the entries are not only either 0s or 1s. Because the default method for resizing the image is the bicubic method, meaning that each pixel is a weighted average of pixels in the nearest 4-by-4 neighborhood. 

Therefore if the input image is only of 0s and 1s, the output image will not necessarily be of only 0s and 1s.

One can tweak this by using other methods for resizing the image, but none of them will provide a satisfactory answer. For example using the method of Nearest Neighbor will give the following:

B = imresize(A,2,'nearest')

B =

1 1 0 0

1 1 0 0

1 1 1 1

1 1 1 1

The REAL solution:

The real solution is to get the input image (RGB) resize it to the size of the template model and then find the contour of the image and compare it to the template.

Generating C code from MATLAB code and the Art of Speeding up MATLAB Applications.

To generate C code from Matlab code is not as simple as it looks. MATLAB code does not map directly to c code, so it’s necessary to modify the code before transforming it to a C library.

Therefore there is a lot of rewriting the MATLAB code before transforming it to a C standalone library. For that it’s necessary to:

– Initialize each variable before its used by specifying its size and data type.

In the case that the variable needs to vary its size during execution, then you have 3 options:

1. Static allocation with fixed maximum size

2. Variable sizing with maximum size allocation.

3. Variable sizing with dynamic memory allocation.

In any case, this seems like a troublesome experience. For a more detailed description on how to do this, take a look here.

If the reason why you wanna generate C code from MATLAB code is that you want to speed up your application,  take a look here.

Dynamic libraries and make install

I finally solved the problem that has been hunting me since the beginning of this week. There are some lessons that I’ve learned doing this work:

Dynamic linking libraries at compiling time is different than dynamic linking then at runtime. Both need to be done.

To link during compile time you need to do the following:

Add the header files to the directories of header files that are included, the option -I does that.

For adding dynamic libraries, the option -L adds directories to the list of directories that the compiler will look for the libraries. The -l will add the library itself (the name)

For resolving the linking issues when running the binary:

Either you can create a install option, by doing the following:

1. Copying the libraries to the common library directorye

>> install:
>> cp ./lib/libsegmentImage.dylib /usr/lib

Or:

2. Change the $DYLD_LIBRARY_PATH to the directory of the libraries:

>> export DYLD_LIBRARY_PATH=/Applications/MATLAB/MATLAB_Compiler_Runtime/v81/runtime/maci64/

Other tips:

To debug problems when running a binary file, the following tool can help to find what and where the problem is happening:

>> dtruss ./KinectVideoHandler 2> out
>> less out

Another way of doing that is to:

Create a text file:

>>  #!/bin/sh
>>  # set dynamic preload library path
>>  export DYLD_LIBRARY_PATH=/Applications/MATLAB/MATLAB_Compiler_Runtime/v81/runtime/maci64/
>>  ./KinectVideoHandler