for Robot Artificial Inteligence

82.프로그래머스[n명이 입국심사]

|

#include <string>
#include <vector>
#include <algorithm>
    // 이분 탐색을 이용해 문제를 해결, 모든 사람을 심사하는 시간의 min 1, max는 오래 걸리는 심사관이 모든 사람을 처리 할 때 걸리는 시간입니다. 따라서 max(times 중 가장 큰 원소 * n)
    // 어떤 시간이 주어졌을 때, 주어진 시간에 입국심사할 수 있는 모든 사람의 수를 합쳐 people_sum에 저장
    // people_sum이 n보다다 작다면 정답은 mid보다 크므로 min = mid+1;을 합니다. 반대로 people_sum이 n이상이라면 정답이 mid보다 작거나 같으므로 max = mid-1;
    // anwer = mid;를 합니다.

    // min이 max보다 커질 때까지 위의 과정을 반복합니다.
using namespace std;

long long solution(int n, vector<int> times) {

    long long answer = 0, people_sum;
    long long min =1, mid;
    long long max = *max_element(times.begin(), times.end()) * (long long)n;
    // 가장 심사 기간 제일 긴 사람이 처리하는 사람의 수의 곱을 통한 시간의 합
    answer = max;

    // 심사관당 처리할 수 있는 사람의 수를 구한다.
    while(min<=max)
    {
        people_sum = 0;
        mid = (min+max)/2;

        for(int i = 0; i<times.size(); i++)
        {
            people_sum += mid/times[i];
        }
        // 작을 경우 민값 미드 +1
        if(people_sum<n)
        {
            min = mid+1;

        }
        // 그렇지 않을 경우 맥스 미드-1
        else{
            max = mid-1;
            answer = mid;
        }
    }
    return answer;
}



Comment  Read more

How to create a ROS2 Workspace

|

COMMANDS TO USE:

  • mkdir -p my_ros2_ws/src
  • colcon build
  • source ~/my_ros2_ws/install/local_setup.bash

in, ros1 kind of

  • catkin_make
  • source ~devel/setup.bash.

Cocon build

colcon 는 OSRF(Open Source Robotics Foundation )에서 빌드한 명령줄 도구입니다. 이 서비스는 ROS 및 ROS2 애플리케이션의 빌드 및 번들링을 자동화하고, 을 즉시 대체할 수 있습니다.

colcon는 중첩된 폴더 구조를 지원하고 패키지를 자동으로 찾습니다.

예를 들어 intermediate_directory의 CMakeLists.txt는 필요하지 않습니다.

src/
├── package_1/
│ ├── package.xml
| └── CMakeLists.txt # okay
└── intermediate_directory/
    ├── package_2
    | ├── package.xml
    | └── CMakeLists.txt # okay
    ├── package_3
    | ├── package.xml
    | └── CMakeLists.txt  # okay
    └── CMakeLists.txt  # !!! remove !!!

colcon is a command line tool to improve the workflow of building, testing and using multiple software packages. It automates the process, handles the ordering and sets up the environment to use the packages.

Background

colcon is an iteration on the ROS build tools catkin_make, catkin_make_isolated, catkin_tools and ament_tools.

Basics

A ROS workspace is a directory with a particular structure. Commonly there is a src subdirectory. Inside that subdirectory is where the source code of ROS packages will be located. Typically the directory starts otherwise empty.

colcon does out of source builds. By default it will create the following directories as peers of the src directory:

  • The build directory will be where intermediate files are stored. For each package a subfolder will be created in which e.g. CMake is being invoked.

  • The install directory is where each package will be installed to. By default each package will be installed into a separate subdirectory.

  • The log directory contains various logging information about each colcon invocation.

Comment  Read more

How to create a Simple Publiser

|

COMMANDS TO USE:

  • source /opt/ros/crystal/setup.bash

참고 자료:

Comment  Read more

How to create a ROS2 Package for C++

|

COMMANDS TO USE:

  • ros2 pkg create ros2_cpp_pkg –build-type ament_cmake –dependencies rclcpp
  • colcon build –symlink-install

ROS1과 비슷하게 create 된 C++ 코드는 CMakeLists에 executes 스크립트를 써서 아래와 같이 execute할 수 있다

  • rosrun run ros2_cpp_pkg cpp_code

ament_cmake

ament_cmake is the build system for CMake based packages in ROS 2 (in particular, it will be used for most if not all C/C++ projects). It is a set of scripts enhancing CMake and adding convenience functionality for package authors.

the main role of ament_cmake is to provide CMake macros that will make your job easier when developing multiple packages that depend on each other. None of it is required to build a CMake based ROS package.

An example of such macro is ament_target_dependencies, it condenses the following cmake logic into a single call:

  • target_compile_definitions()
  • target_include_directories()
  • target_link_libraries()
  • setting link flags on the target

Another (the most?) important macro it provides is ament_package. This is what will handle the registration of your package in the ament index, generate the CMake config files for the project to be find_package’able, install the extra CMake config files you provide, install the package.xml of your package etc

You can find some information about ament_cmakein the section “Build type: ament_cmake” of https://design.ros2.org/articles/amen…

Comment  Read more

How to create a ROS2 Package for python

|

COMMANDS TO USE:

  • 만약 execute할 파일이 이미 있다면
  • launch folder를 만들고
  • execute.launch.py를 하여서 파이썬 스크립트로 런치파일을 한다
  • 물론 이전 launch 형식으로도 execute할 노드들을 런치 할 수 있다.
  • 마지막에다 CMakeLists에다 install launch files를 하여서 launch를 이용할 수록 한다.

py로하는 이유는, 노드 관리와 파라미터 관리가 편하다.

참고 자료: https://www.youtube.com/watch?v=FfMWmWdPPAM&list=PLK0b4e05LnzYNBzqXNm9vFD9YXWp6honJ&index=4

Comment  Read more