
Communication script for senior design
Dependencies: ros_lib_indigo mbed
Revision 0:583c5af1418c, committed 2019-04-23
- Comitter:
- roger_wee
- Date:
- Tue Apr 23 18:37:20 2019 +0000
- Commit message:
- Senior design communication script
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Apr 23 18:37:20 2019 +0000 @@ -0,0 +1,55 @@ +#include "mbed.h" +#include <ros.h> +#include <std_msgs/Int16.h> + +//--------- GLOBAL VARIABLES LOCAL TO STM32 MAIN ----------- +DigitalOut my_led(LED1); + +int data_recieved = 0; + +//-------- END GLOBAL VARIABLES DECLARATION --------------- + + +//--------- ROS NODE CONFIGURATION ------------------------- +ros::NodeHandle nh; + +// Ros message data containers +std_msgs::Int16 recieve_msg; +std_msgs::Int16 transmit_msg; + +// Set up Publishers +ros::Publisher acknowledge_publisher("acknowledge", &transmit_msg); + +// Set up Subscribers +void reciever_callback( const std_msgs::Int16& msg) +{ + // Assign msg.data to local variables + data_recieved = msg.data; +} + +ros::Subscriber<std_msgs::Int16> reciever_subscriber("test", reciever_callback); + + +//---------- END CONFIGURATION ---------------------------- + +int main() { + + // Initialize Node and publisher/subscriber + nh.initNode(); + nh.advertise(acknowledge_publisher); + nh.subscribe(reciever_subscriber); + + while(1) { + + // Use local variables for computations here + + + // Publish any data necessary to be fed back to pc + transmit_msg.data = data_recieved; + acknowledge_publisher.publish(&transmit_msg); + + // Spin ROS Node -- get data from callbacks + nh.spinOnce(); + wait_ms(5); + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Apr 23 18:37:20 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ros_lib_indigo.lib Tue Apr 23 18:37:20 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/garyservin/code/ros_lib_indigo/#fd24f7ca9688