Monday, July 23, 2018

ทดสอบการทำงาน YDLIDAR X4 บนระบบ ROS

Create YDLIDAR ROS driver package

(1)Switch your computer to the src directory of a ROS workspace and replace catkin_ws with your ROS workspace.

$cd ~/catkin_ws/src

(2)Clone the ydlidar project into the src directory under your ROS workspace.

$git clone https://github.com/EAIBOT/ydlidar

$cd ..

(3)The compiler generates ydlidar_node and ydlidar_client.

$catkin_make --pkg ydlidar


Run YDLIDAR ROS driver package
 
(1)Create YDLIDAR Radar Serial Alias [/dev/ydlidar].

$roscd ydlidar/startup

$sudo chmod 0777 *

$sudo sh initenv.sh

** Reboot OS **

(2) Open lidar.launch and change the baud rate for different models of lidar. The following is the configuration of X4.

$roscd ydlidar/launch

$vim lidar.launch


There are two ways to run YDLIDAR ROS driver package:

(1) Run ydlidar_node and rviz

$roslaunch ydlidar lidar_view.launch


(2) Run ydlidar_node and ydlidar_client

$roslaunch ydlidar lidar.launch

$rosrun ydlidar ydlidar_client

###data output on computer



Sunday, July 22, 2018

วิธีแก้จอดำก่อน login ใน Ubuntu

วิธีแก้ไขชั่วคราว(ก่อน boot เข้า Ubuntu)

  • ให้กดปุ่ม escape ก่อน_boot เข้า ubuntu เพื่อเข้าสู่ Grub Menu.
  • กดปุ่ม e เพื่อแก้ไข
  • หาบรรทัดที่ขึ้นต้น "linux " หาข้อความ "quiet splash".
  • จากนั้นให้เพิ่มคำว่า nomodeset ด้านหลัง "quiet splash nomodeset".
  • กดปุ่ม ctrl + x.

วิธีแก้ไขหลังจาก boot เข้า Ubuntu ได้แล้ว

  • เปิด terminal ขึ้นมา
  • พิมพ์คำสั่ง sudo gedit /etc/default/grub
  • หาบรรทัดที่มีข้อความ GRUB_CMDLINE_LINUX_DEFAULT="quiet splash" จากนั้นให้เพิ่มคำว่า nomodeset --> GRUB_CMDLINE_LINUX_DEFAULT="quiet splash nomodeset"
  • ทำการบันทึกและออกจากโปรแกรม gedit
  • พิมพ์คำสั่ง sudo update-grub
ขอบคุณที่มา http://shuklas664.blogspot.com/2015/07/black-screen-in-ubuntu-before-login.html

Thursday, July 12, 2018

สร้าง package teleop_twist_keyboard เพื่อทดสอบ การทำงานของหุ่นยนต์ (Base Controller)

1) cd ~/catkin_ws/src
2) git clone https://github.com/ros-teleop/teleop_twist_keyboard
3) cd ~/catkin_ws
4) catkin_make
5) source ~/catkin_ws/devel/setup.bash
6) source ~/.bashrc
ข้อ 5-6 ถ้าเคยทำแล้วข้ามได้เลยครับ

Saturday, July 7, 2018

ตัวอย่าง Hello World: สร้าง Publisher ด้วย Arduino ติดต่อกับ ROS

1.โค้ดตัวอย่าง File->Examples->Rosserial Arduino Library->HelloWorld


/*
 * rosserial Publisher Example
 * Prints "hello world!"
 */

// Use the following line if you have a Leonardo or MKR1000 
//#define USE_USBCON 

#include <ros.h>
#include <std_msgs/String.h>

ros::NodeHandle nh;

std_msgs::String str_msg;
ros::Publisher chatter("chatter", &str_msg);

char hello[13] = "hello world!";

void setup()
{
  nh.initNode();
  nh.advertise(chatter);
}

void loop()
{
  str_msg.data = hello;
  chatter.publish( &str_msg );
  nh.spinOnce();
  delay(1000);
}

อัพโหลดโค้ดเข้าสู่ Arduino (ผมใช้ arduino uno r3)

2.นำสาย USB Arduino ไปเสียบที่ port USB ของ Workstation(Raspberry pi 3)

3.จากนั้น เปิด Terminal ใหม่แล้วใช้คำสั่ง

roscore

เปิด Terminal ใหม่แล้วใช้คำสั่ง

rosrun rosserial_python serial_node.py /dev/ttyACM0
*** หากเกิด Error -> could not open port /dev/ttyACM0: [Errno 13] Permission denied: '/dev/ttyACM0'
แก้ไขด้วยการเพิ่ม username เข้าไปใน dailout group


sudo adduser <username> dialout
***  <username> ของผมคือ Pi
จากนั้นให้ Restart Workstation(Raspberry pi 3) แล้วเรียกคำสั้่ง

rosrun rosserial_python serial_node.py /dev/ttyACM0
อีกครั้ง จากนั้นเปิด Terminal ใหม่แล้วใช้คำสั่ง

rostopic echo chatter

วิธีทำให้ ROS ติดต่อกับ ARDUINO

1.ติดตั้ง rosserial บน Ubuntu บน Raspberry pi 3(ROS workstation)
sudo apt-get install ros-indigo-rosserial-arduino
sudo apt-get install ros-indigo-rosseria
2.ทำการ clone Rosserial  ไลบารี่และ package จาก github เข้าสู่ ROS workstation

  cd <ws>/src
  git clone https://github.com/ros-drivers/rosserial.git
  cd <ws>
  catkin_make
** ws คือ catkin workspace ของเรา

3.ติดตั้งไลบารี rosserial ใน Arduino IDE 

ให้ไปที่เมนู  Sketch -> Include Library -> Manage Library แล้วค้นหา "rosserial"



ขอบคุณที่มา : http://wiki.ros.org/rosserial_arduino/Tutorials/Arduino%20IDE%20Setup