ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

For those interested in adding a cheap angular rate gyro to their robot designs for helping with odometry calcs, here's some pseudo code for calculating the orientation that might help:

calibration = [] // array for building calibration offset
loop() {
  gyro_adc = get_gyro_value_from_analog()
  if (robotIsNotMoving) {
      calibration.push_back(gyro_adc)
      total = 0;
      for each( float reading, calibration )
      {
        total += reading;
      }
      cal_offset = total / calibration.size()
  }

  this_reading_time = get_current_time()
  dt = this_reading_time - last_reading_time
  max_value = 255; // 8 bit ADC 
  v_ref = 5; // arduino is a 5V ref
  zero_rate_v = cal_offset * v_ref / max_value
  sensitivity = 0.013 // get from gyro data sheet

  rate = (gyro_adc * v_ref / max_value - zero_rate_v) / sensitivity

  orientation += rate * dt
  // do something with orientation (put it in an IMU msg, etc.)
  // ...
  last_reading_time = this_reading_time
}