###### tags: `ROSKY2` `ROS2` `Jetson Nano` `reComputer-J1010` `lidar detection` # CH 3: ROSKY2 - Detect distance with lidar In this note, user will use lidar to detect distance of specific direction ## Hardware user have to prepare before doing... 1. [ROSKY2](https://www.icshop.com.tw/product-page.php?28598) 2. A host machine with the operating system is Window 10(above) or Ubuntu. --- ## Some things user should know before operating... Please check the note and documentation below: - [CH 1. ROSKY2 - remotely log in](https://hackmd.io/@weichih-lin/ROSKY2_log_in_remotely) - [ros2 service documentation](https://docs.ros.org/en/foxy/Tutorials/Beginner-CLI-Tools/Understanding-ROS2-Services/Understanding-ROS2-Services.html) Now let’s go ahead to use lidar. --- ## Step 1. Open Terminator in ROSKY2 through remote desktop ### Step 1-1. Open terminal on the remote desktop Because of the keyboard shortcut keys in NoMachine, user can not use the keyboard keys 【ctrl】+【alt】+【T】to open the terminal quickly. Please right-click the mouse on the remote desktop to open the menu item and then choose【Open Terminal】to open terminal. Once user see the roe_menu is shown on the terminal, please choose【2】to start the operating environment for ROSKY2. ![Open terminal on the remote desktop](https://i.imgur.com/zsH0Zuq.png) ### Step 1-2. Open terminator on the remote desktop Terminator is a nice terminal emulator, please check the [Terminator’s documentation](https://terminator-gtk3.readthedocs.io/en/latest/) to know more detail. User can type the command command to start terminator: ```bash= $ terminator ``` Once start the terminator successfully, user can see ros_menu is shown on the terminator. Like the operation in [step 1-1](#Step-1-1-Open-terminal-on-the-remote-desktop), user have to choose [2] to start the environment for ROSKY2. ![Open terminator on the remote desktop](https://i.imgur.com/dgprdav.png) More keyboard shortcut in the terminator user can find on the [Terminator’s documentation - Using the keyboard](https://terminator-gtk3.readthedocs.io/en/latest/gettingstarted.html#using-the-keyboard). ## Step 2. Start the communication with all sensors, motor control board and more on ROSKY2 Now user just running the system on the SBC and it can not send/receive data from sensor and more. Hence, user have to start the communication with these to send/receive data. > **Note** > Seneors on ROSKY2 will start running after typing the command below. Please make sure **no more things** result in stopping these sensor work, such as **something is on the LiDAR**, **transfer cable connect between host machine and ROSKY2** and more. Please type the command below in the terminator to start the communication: ```bash= $ ros2 launch rosky2_bringup bringup.launch.py ``` ![launch bringup.launch.py](https://i.imgur.com/eCJKtdZ.png) ## Step 3. Run node "detect_distance" Awesome! User start the communication between ROSKY2 and sensors. Now user can see lidar is rotating now. From [Step 1-2 in this note](#Step-1-2-Open-terminator-on-the-remote-desktop), user can know that use the keyboard shortcut 【ctrl】+【shift】+【E】 in terminator to split terminal vertically. The same thing is choosing 【2】 to start the environment for ROSKY2 after user opening ros_menu successfully. ![split terminal vertically](https://i.imgur.com/hYP1edP.png) Now is ready to detect the distance from specific direction, please type the command below in terminal to start the node "detect_distance": ```bash= $ ros2 run wall_follower detect_distance --ros-args -r /detect_distance/scan:=/scan ``` ![run the node "detect_distance"](https://i.imgur.com/tCkm8gG.png) After running successfully, user can see the distance form the direction "BACK": ![detect the distance from specific direction](https://i.imgur.com/0Scftf7.png) Please feel free to put something behind ROSKY2 and then check what the information happen on the terminal. ## Step 4. Change direction to detect distance If user want to chang the direction to detect distance, please use the keyboard shortcut 【ctrl】+【shift】+【O】in terminator to split terminal horizontally and choose【2】to start the environment for ROSKY2 after user opening ros_menu successfully. ![split terminal horizontally](https://i.imgur.com/LiS6SVY.jpg) Next, please type the command below to call the ROS2 service "/detect_distance/update_direction" for changing the direction detect: ```bash= $ ros2 service call /detect_distance/update_direction rosky2_interfaces/srv/DirectionUpdate "{data: [direction]}" ``` > **Note** > **User have to type the direction to replace [direction]. Until now, just these direction can use: back, right, front, left.** Below the image is the example that change the direction from back to front: ![Changer direction](https://i.imgur.com/xbzmhiu.png) And user can find infromation change from "BACK" to "FRONT" in the window that the node "detect_distance" running. ## Step 5. Shutdown all running node. If user finished the keyboard teleop for ROSKY2, please remember to shutdown all running node through the shortcut key 【ctrl】+【C】 in terminal. ## Next User can continue the note -> [CH4: wall_fallower](https://hackmd.io/@weichih-lin/ROSKY2_wall_follower) Please have fun to use ROSKY2 :)