added broadcaster for l.mouse
Dependencies: QEI mbed ros_lib_kinetic
Fork of Mouse_ISR_broadcaster by
main.cpp@1:7ba9803d4e01, 2018-07-16 (annotated)
- Committer:
- apriljunio
- Date:
- Mon Jul 16 19:47:46 2018 +0000
- Revision:
- 1:7ba9803d4e01
- Parent:
- 0:1a95e3b1026a
- Child:
- 2:47663f3fec3a
ISR + ROS Publisher
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
apriljunio | 0:1a95e3b1026a | 1 | #include "mbed.h" |
apriljunio | 0:1a95e3b1026a | 2 | #include "QEI.h" |
apriljunio | 0:1a95e3b1026a | 3 | #include "ros.h" |
apriljunio | 0:1a95e3b1026a | 4 | #include "geometry_msgs/Quaternion.h" |
apriljunio | 0:1a95e3b1026a | 5 | |
apriljunio | 0:1a95e3b1026a | 6 | //PINA / PINB / INDEXPIN / PPR / ENCODING (X2 BY DEFAULT) |
apriljunio | 0:1a95e3b1026a | 7 | QEI leftEncoder(D3, D12, NC, 378); |
apriljunio | 0:1a95e3b1026a | 8 | QEI rightEncoder(D2, D13, NC, 378); |
apriljunio | 0:1a95e3b1026a | 9 | |
apriljunio | 0:1a95e3b1026a | 10 | ros::NodeHandle nh; |
apriljunio | 0:1a95e3b1026a | 11 | geometry_msgs::Quaternion wheelMsg; |
apriljunio | 0:1a95e3b1026a | 12 | ros::Publisher wheelPub("/odom_msg", &wheelMsg); |
apriljunio | 0:1a95e3b1026a | 13 | |
apriljunio | 1:7ba9803d4e01 | 14 | //rosserial does not like volatile ints |
apriljunio | 0:1a95e3b1026a | 15 | int leftPulseA=0; |
apriljunio | 0:1a95e3b1026a | 16 | int rightPulseA=0; |
apriljunio | 0:1a95e3b1026a | 17 | |
apriljunio | 1:7ba9803d4e01 | 18 | //timeL; |
apriljunio | 1:7ba9803d4e01 | 19 | //timeR; |
apriljunio | 0:1a95e3b1026a | 20 | |
apriljunio | 0:1a95e3b1026a | 21 | int main(){ |
apriljunio | 0:1a95e3b1026a | 22 | |
apriljunio | 0:1a95e3b1026a | 23 | nh.initNode(); |
apriljunio | 0:1a95e3b1026a | 24 | //nh.advertise(chatter); |
apriljunio | 0:1a95e3b1026a | 25 | nh.advertise(wheelPub); |
apriljunio | 0:1a95e3b1026a | 26 | // pc.baud(57600); |
apriljunio | 0:1a95e3b1026a | 27 | |
apriljunio | 0:1a95e3b1026a | 28 | |
apriljunio | 0:1a95e3b1026a | 29 | while(true){ |
apriljunio | 0:1a95e3b1026a | 30 | |
apriljunio | 0:1a95e3b1026a | 31 | leftPulseA=leftEncoder.getPulses(); |
apriljunio | 0:1a95e3b1026a | 32 | rightPulseA = rightEncoder.getPulses(); |
apriljunio | 1:7ba9803d4e01 | 33 | //timeL = tL.read(); |
apriljunio | 1:7ba9803d4e01 | 34 | //timeR = tL.read(); |
apriljunio | 0:1a95e3b1026a | 35 | |
apriljunio | 0:1a95e3b1026a | 36 | wheelMsg.x= leftPulseA; |
apriljunio | 1:7ba9803d4e01 | 37 | wheelMsg.y = 0.0;//timeL; |
apriljunio | 0:1a95e3b1026a | 38 | wheelMsg.z = rightPulseA; |
apriljunio | 1:7ba9803d4e01 | 39 | wheelMsg.w = 0.0;//timeR; |
apriljunio | 0:1a95e3b1026a | 40 | |
apriljunio | 0:1a95e3b1026a | 41 | |
apriljunio | 0:1a95e3b1026a | 42 | //pc.printf("Left pulses %i \n", leftPulseA); |
apriljunio | 0:1a95e3b1026a | 43 | //pc.printf("Right pulses %i \n", rightPulseA); |
apriljunio | 0:1a95e3b1026a | 44 | |
apriljunio | 0:1a95e3b1026a | 45 | //str_msg.data=hello; |
apriljunio | 0:1a95e3b1026a | 46 | //chatter.publish(&str_msg); |
apriljunio | 0:1a95e3b1026a | 47 | wheelPub.publish(&wheelMsg); |
apriljunio | 0:1a95e3b1026a | 48 | nh.spinOnce(); |
apriljunio | 0:1a95e3b1026a | 49 | wait(0.01); |
apriljunio | 0:1a95e3b1026a | 50 | } |
apriljunio | 0:1a95e3b1026a | 51 | } |