using ros serial to publish joint angles
Dependencies: mbed ros_lib_indigo
Revision 0:6370e1a55ca5, committed 2017-09-26
- Comitter:
- robot_fan4
- Date:
- Tue Sep 26 10:39:00 2017 +0000
- Commit message:
- rosserial;
Changed in this revision
diff -r 000000000000 -r 6370e1a55ca5 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Sep 26 10:39:00 2017 +0000 @@ -0,0 +1,91 @@ +///* +// * rosserial ADC Example +// * +// * This is a poor man's Oscilloscope. It does not have the sampling +// * rate or accuracy of a commerical scope, but it is great to get +// * an analog value into ROS in a pinch. +// */ +// +//#include "mbed.h" +//#include <ros.h> +//#include <geometry_msgs/Vector3Stamped.h> +//#include <ros/time.h> +// +////AnalogIn analog_value1(A0); +////AnalogIn analog_value2(A1); +////AnalogIn analog_value3(A2); +//DigitalOut led(LED1); +// +//ros::NodeHandle nh; +// +//geometry_msgs::Vector3Stamped joint_angle; +// +//ros::Publisher p("adc", &joint_angle); +// +// +////We average the analog reading to elminate some of the noise +//int averageAnalog(PinName pin) { +// int v=0; +// for (int i=0; i<4; i++) v+= AnalogIn(pin).read_u16(); +// return v/4; +//} +// +//int main() { +// nh.initNode(); +// nh.advertise(p); +// +// while (1) { +// joint_angle.vector.x= averageAnalog(A0); +// joint_angle.vector.y= averageAnalog(A1); +// joint_angle.vector.z= averageAnalog(A2); +// joint_angle.header.stamp = nh.now(); +// p.publish(&joint_angle); +// nh.spinOnce(); +// wait_ms(10); +// } +//} + +/* + * rosserial ADC Example + * + * This is a poor man's Oscilloscope. It does not have the sampling + * rate or accuracy of a commerical scope, but it is great to get + * an analog value into ROS in a pinch. + */ + +#include "mbed.h" +#include <ros.h> +#include <std_msgs/Float64.h> +#include <ros/time.h> + +//AnalogIn analog_value1(A0); +//AnalogIn analog_value2(A1); +//AnalogIn analog_value3(A2); +DigitalOut led(LED1); + +ros::NodeHandle nh; + +std_msgs::Float64 feedback; + +ros::Publisher p("state", &feedback); + + +//We average the analog reading to elminate some of the noise +int averageAnalog(PinName pin) { + int v=0; + for (int i=0; i<4; i++) v+= AnalogIn(pin).read(); + return v*2000/4-1000; +} + +int main() { + nh.initNode(); + nh.advertise(p); + + while (1) { + feedback.data = averageAnalog(A0); + p.publish(&feedback); + nh.spinOnce(); + wait_ms(10); + } +} +
diff -r 000000000000 -r 6370e1a55ca5 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Sep 26 10:39:00 2017 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/675da3299148 \ No newline at end of file
diff -r 000000000000 -r 6370e1a55ca5 ros_lib_indigo.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ros_lib_indigo.lib Tue Sep 26 10:39:00 2017 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/users/garyservin/code/ros_lib_indigo/#fd24f7ca9688