20 #include <std_msgs/Int32.h> 23 #include <qegpioint.h> 24 #include <qemotoruser.h> 29 CQEMotorUser &
motor = CQEMotorUser::GetRef();
30 CQEGpioInt &
gpio = CQEGpioInt::GetRef();
40 void motorCb(
const std_msgs::Int32& motor13_msg){
41 int speed = motor13_msg.data;
42 printf(
"Received subscribed motor speed %d\n", speed);
43 motor.SetPWM(0, speed);
50 unsigned long diff(
struct timeval *ptv0,
struct timeval *ptv1)
54 val = ptv1->tv_usec - ptv0->tv_usec;
55 val += (ptv1->tv_sec - ptv0->tv_sec)*1000000;
64 void callback(
unsigned int io,
struct timeval *ptv,
void *userdata)
66 static struct timeval tv0;
78 sonarVal =
diff(&tv0, ptv);
81 range.data = sonarVal;
88 volatile unsigned int d;
98 gpio.SetDataDirection(0x0001);
104 gpio.SetInterruptMode(0, QEG_INTERRUPT_NEGEDGE);
105 gpio.SetInterruptMode(1, QEG_INTERRUPT_NEGEDGE);
110 gpio.SetData(0x0001);
111 for (d=0; d<120000; d++);
112 gpio.SetData(0x0000);
void publish(const boost::shared_ptr< M > &message) const
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
unsigned long diff(struct timeval *ptv0, struct timeval *ptv1)
ros::Publisher sonar1("sonar1",&range)
void motorCb(const std_msgs::Int32 &motor13_msg)
void callback(unsigned int io, struct timeval *ptv, void *userdata)
ros::Subscriber< std_msgs::Int32 > motorSub("motor13", motorCb)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)