1. Package Download

    GitHub - ros-drivers/microstrain_mips

  2. IMU connect

    IMU port 확인하기

    <aside> 💡 $ cd /home && $ ls /dev/tty 까지 하고 Tab 누르기

    </aside>

    IMU 연결 전

    Screenshot from 2022-04-02 15-11-34.png

    IMU 연결 후

    Screenshot from 2022-04-02 15-11-17.png

    ttyACM0이 추가된 것을 확인할 수 있다.

    <aside> 💡 tty란? tele type의 약자로 사용자와 시스템 사이를 중계하는 역할을 한다. 사용자가 입력하는 키보드의 입력은 tty를 통해서 시스템에 전달되고 시스템에서 내보내는 출력 역시 tty을 통과해서 사용자에게 전달된다.

    </aside>

  3. microstrain.launch file 수정

    처음 package를 다운 받으면 밑과 같은 launch file을 확인할 수 있다.

    cf) launch파일의 위치는 package의 launch파일 안의 microstrain.launch를 보면 확인할 수 있다.

    Screenshot from 2022-04-01 19-41-54.png

    6번째 줄의 port name을 위에서 확인했던 /dev/ttyACM0으로 바꿔준다.

    <aside> 💡 현재는 IMU만 연결했기 때문에 ACM0으로 잘 들어왔으나, GPS, LiDAR등 여러 센서들이 추가될 경우 반드시 확인해야함

    </aside>

  4. Setup & Use IMU

  5. catkin_make

    <aside> 💡 $ cd ~/catkin_ws && $ catkin_make

    </aside>

  6. source devel/setup.bash

    <aside> 💡 $ cd ~/catkin_ws && $ source devel/setup.bash

    </aside>

  7. 권한 주기

    <aside> 💡 $ sudo chmod 777 /dev/ttyACM0

    </aside>

  8. Execute IMU

    <aside> 💡 $ roslaunch micorstrain_mips microstrain.launch

    </aside>

  9. IMU Data 확인

    1. rostopic

    Screenshot from 2022-04-01 19-44-59.png

    1. rostopic echo /gx5/imu/data

    Screenshot from 2022-04-01 19-45-35.png

    1. Quaternion to Euler

      #!/usr/bin/env python
      import rospy
      import math
      import tf
      import time
      
      from sensor_msgs.msg import NavSatFix
      from geometry_msgs.msg import Pose
      from sensor_msgs.msg import MagneticField
      from nav_msgs.msg import Odometry
      from sensor_msgs.msg import Imu
      
      # define
      magnet_OFF = [0, 0, 0]
      PI = 3.141592
      msg = Odometry()
      
      def IMU_Calculation(data):
          quaternion = (data.orientation.x,
              data.orientation.y,
              data.orientation.z,
              data.orientation.w)
      
          euler = tf.transformations.euler_from_quaternion(quaternion)
      
          msg.twist.twist.angular.x = euler[0]*180/PI # Pitch
          msg.twist.twist.angular.y = euler[1]*180/PI # Roll
          msg.twist.twist.angular.z = euler[2]*180/PI # Yaw
          
          # Angle detail control
          #msg.twist.twist.angular.z -= 30 ##################################################
          #msg.twist.twist.angular.z = abs(360 - msg.twist.twist.angular.z%360)
      
          msg.twist.twist.angular.z += 0 ##################################################
          msg.twist.twist.angular.z = msg.twist.twist.angular.z%360
      
          msg.pose.pose.position.z = msg.twist.twist.angular.z
      
          if (msg.pose.pose.position.z > 180): 
              msg.pose.pose.position.z -= 360
         
          orientation = tf.transformations.quaternion_from_euler(msg.twist.twist.angular.y*PI/180, msg.twist.twist.angular.x*PI/180, msg.pose.pose.position.z*PI/180)
      
          msg.pose.pose.orientation.y = orientation[0]
          msg.pose.pose.orientation.x = orientation[1]
          msg.pose.pose.orientation.z = orientation[2]
          msg.pose.pose.orientation.w = orientation[3]
      
          # print(msg.twist.twist.angular.z)
      
          print("roll:", msg.twist.twist.angular.x)
      
          print("pitch:", msg.twist.twist.angular.y)
          
          print("yaw:", msg.twist.twist.angular.z)
      
      # pub = rospy.Publisher('/pose', Odometry, queue_size = 1)
      rospy.init_node("IMU",anonymous=True)
      # rospy.Subscriber('/gps_data/fix',NavSatFix,GPS_IMU)
      rospy.Subscriber('/gx5/imu/data', Imu, IMU_Calculation)
      rate = rospy.Rate(500)
      rospy.spin()
      

      imu.py