diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..b5870a3 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "ros_ws/src/arudino/razor-9dof-ahrs"] + path = ros_ws/src/arudino/razor-9dof-ahrs + url = https://github.com/MST-Robotics/razor-9dof-ahrs.git diff --git a/ros_ws/src/arudino/imu/imu.ino b/ros_ws/src/arudino/imu/imu.ino deleted file mode 100644 index 85389a3..0000000 --- a/ros_ws/src/arudino/imu/imu.ino +++ /dev/null @@ -1,179 +0,0 @@ -#include - -#define GYROADDR 0x68 -#define COMPASSADDR 0x1e -#define ACCELADDR 0x53 - -union XYZBuffer { - struct { - short x,y,z; - } value; - byte buff[6]; -}; - -void changeEndian(union XYZBuffer *xyz) { - for (int i=0;i<6;i+=2) { - byte t=xyz->buff[i]; - xyz->buff[i]=xyz->buff[i+1]; - xyz->buff[i+1]=t; - } -} - -// Generically useful reading into a union type -void readXYZ(int device,union XYZBuffer *xyz) { - Wire.requestFrom(device, 6); - long start=millis(); - while (!Wire.available() && (millis()-start)<100); - if (millis()-start<100) { - for (int i=0;i<6;i++) - xyz->buff[i]=Wire.read(); - } -} - -void setupAccel(int device) { - // Check ID to see if we are communicating - Wire.beginTransmission(device); - Wire.write(0x00); // One Reading - Wire.endTransmission(); - Wire.requestFrom(device,1); - while (!Wire.available()); - byte ch=Wire.read(); - Serial.print("Accel id is 0x"); - Serial.println(ch,HEX); - // Should output E5 - - // https://www.sparkfun.com/datasheets/Sensors/Accelerometer/ADXL345.pdf - // Page 16 - Wire.beginTransmission(device); - Wire.write(0x2d); - Wire.write(0x08); - Wire.endTransmission(); - Wire.beginTransmission(device); - Wire.write(0x38); - Wire.write(0x84); - Wire.endTransmission(); - -} -void readAccel(int device,union XYZBuffer *xyz) { - Wire.beginTransmission(device); - Wire.write(0x32); // One Reading - Wire.endTransmission(); - readXYZ(device,xyz); -} - -void setupCompass(int device) { - // Check ID to see if we are communicating - Serial.print("Compass id is "); - Wire.beginTransmission(device); - Wire.write(10); // One Reading - Wire.endTransmission(); - Wire.requestFrom(device,2); - while (!Wire.available()); - char ch=Wire.read(); - Serial.print(ch); - ch=Wire.read(); - Serial.println(ch); - // Should output H4 - -// Page 18 -// at http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Sensors/Magneto/HMC5883L-FDS.pdf - Wire.beginTransmission(device); - Wire.write(0x00); Wire.write(0x70); - Wire.endTransmission(); - Wire.beginTransmission(device); - Wire.write(0x01); Wire.write(0xA0); - Wire.endTransmission(); - Wire.beginTransmission(device); - Wire.write(0x02); Wire.write(0x00); // Reading - Wire.endTransmission(); - delay(6); -} -void readCompass(int device,union XYZBuffer *xyz) { - readXYZ(device,xyz); - changeEndian(xyz); - Wire.beginTransmission(device); - Wire.write(0x03); - Wire.endTransmission(); -} - -void setupGyro(int device) { - // Check ID to see if we are communicating - Wire.beginTransmission(device); - Wire.write(0x00); // One Reading - Wire.endTransmission(); - Wire.requestFrom(device,1); - while (!Wire.available()); - byte ch=Wire.read(); - Serial.print("Gyro id is 0x"); - Serial.println(ch,HEX); - // Should output 69 -} -void readGyro(int device,union XYZBuffer *xyz) { - // https://www.sparkfun.com/datasheets/Sensors/Gyro/PS-ITG-3200-00-01.4.pdf - // page 20 - Wire.beginTransmission(device); - Wire.write(0x1d); - Wire.endTransmission(); - readXYZ(device,xyz); - changeEndian(xyz); -} - -void pad(int width,int number) { - int n=abs(number); - int w=width; - if (number<0) w--; - while (n>0) { - w--; - n/=10; - } - if (number==0) w--; - for (int i=0;i +#include +#include +#include + +class Orientation +{ + private: + /** + * @brief The ros nodehandle + */ + ros::NodeHandle nh; + + /** + * @brief The subscriber to the message from the imu, expects an rpy message + */ + ros::Subscriber imu_sub; + + /** + * @brief The publisher of the imu message + */ + ros::Publisher orientation_pub; + + /** + * @brief The orientation of the robot + */ + sensor_msgs::Imu orientation; + + /** + * @brief The callback function for the rpy message + * + * This function will accept rpy messages and will publish this information to an imu message + * + * @param msg The message received from the rpy publisher + */ + void rpyCallback(const localization::rpy::ConstPtr& msg); + + public: + Orientation(); + + void update(); +}; + + +#endif //PROJECT_ORIENTATION_H diff --git a/ros_ws/src/localization/msg/rpy.msg b/ros_ws/src/localization/msg/rpy.msg new file mode 100644 index 0000000..84885f7 --- /dev/null +++ b/ros_ws/src/localization/msg/rpy.msg @@ -0,0 +1,3 @@ +float32 roll +float32 pitch +float32 yaw \ No newline at end of file diff --git a/ros_ws/src/localization/package.xml b/ros_ws/src/localization/package.xml new file mode 100644 index 0000000..2f24f5a --- /dev/null +++ b/ros_ws/src/localization/package.xml @@ -0,0 +1,26 @@ + + + localization + 0.0.0 + The localization package + + Matt Anderson + + BSD + + http://robotics.mst.edu + https://github.com/MST-Robotics/IGVC + + Matt Anderson + + catkin + roscpp + std_msgs + message_generation + tf + roscpp + std_msgs + message_generation + tf + + \ No newline at end of file diff --git a/ros_ws/src/localization/src/localization/orientation.cpp b/ros_ws/src/localization/src/localization/orientation.cpp new file mode 100644 index 0000000..f9f5696 --- /dev/null +++ b/ros_ws/src/localization/src/localization/orientation.cpp @@ -0,0 +1,26 @@ +/** + * @file orientation.cpp + * @class Orientation + * @brief The class implementation file for the orientation class + */ +#include "orientation.h" + +Orientation::Orientation() +{ + // Initialize the imu subscriber + imu_sub = nh.subscribe("imu", 1, &Orientation::rpyCallback, this); + orientation_pub = nh.advertise("orientation", 1); +} + +void Orientation::rpyCallback(const localization::rpy::ConstPtr &msg) +{ + orientation.header.stamp = ros::Time::now(); + orientation.header.frame_id = "camera_link"; + orientation.orientation = tf::createQuaternionMsgFromRollPitchYaw(msg->roll, msg->pitch, msg->yaw); +} + +void Orientation::update() +{ + orientation_pub.publish(orientation); +} + diff --git a/ros_ws/src/localization/src/localization/orientation_node.cpp b/ros_ws/src/localization/src/localization/orientation_node.cpp new file mode 100644 index 0000000..dc9b5ed --- /dev/null +++ b/ros_ws/src/localization/src/localization/orientation_node.cpp @@ -0,0 +1,25 @@ +/** + * @file orientation_node.cpp + * @brief The orientation node source file + */ + +#include +#include "orientation.h" + +int main(int argc, char** argv) +{ + ros::init(argc, argv, "orientation_node"); + + Orientation o; + + // Spin at 30hz + ros::Rate loop_rate(30); + + // Spin forever as long as ros is okay + while (ros::ok()) + { + ros::spinOnce(); + o.update(); + loop_rate.sleep(); + } +} \ No newline at end of file