neurali:ros_esempio_nodo_cpp
Differences
This shows you the differences between two versions of the page.
Previous revision | |||
— | neurali:ros_esempio_nodo_cpp [2020/06/08 22:20] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | [[neurali: | ||
+ | esempio di nodo | ||
+ | |||
+ | <code cpp> | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | |||
+ | class TeleopTurtle | ||
+ | { | ||
+ | public: | ||
+ | TeleopTurtle(); | ||
+ | |||
+ | private: | ||
+ | void joyCallback(const sensor_msgs:: | ||
+ | | ||
+ | |||
+ | // | ||
+ | ros:: | ||
+ | |||
+ | int linear_, angular_; // inizializzati a 1 e 2 | ||
+ | double l_scale_, a_scale_; | ||
+ | ros:: | ||
+ | ros:: | ||
+ | | ||
+ | }; | ||
+ | |||
+ | |||
+ | TeleopTurtle:: | ||
+ | linear_(1), | ||
+ | angular_(2) | ||
+ | { | ||
+ | // i param sono in un dizionario gestito nel server | ||
+ | nh_.param(" | ||
+ | // legge un param, ma se non lo trova mette un suo default | ||
+ | nh_.param(" | ||
+ | nh_.param(" | ||
+ | nh_.param(" | ||
+ | |||
+ | // comunica a master che ci sara' un topic con 1 valore | ||
+ | // restituisce un Publisher necessario alla successiva pubblicazione | ||
+ | vel_pub_ = nh_.advertise< | ||
+ | |||
+ | |||
+ | // segnala interesse a ricevere su un topic " | ||
+ | // ogni mess. ricevuto è passato a TeleopTurtle:: | ||
+ | // l' | ||
+ | |||
+ | //This message should not be changed in place, as it is shared with any other subscriptions to this topic. | ||
+ | joy_sub_ = nh_.subscribe< | ||
+ | | ||
+ | // ros::Rate loop_rate(10); | ||
+ | } | ||
+ | |||
+ | void TeleopTurtle:: | ||
+ | { | ||
+ | while (ros::ok()) | ||
+ | { | ||
+ | geometry_msgs:: | ||
+ | vel.angular = a_scale_*joy-> | ||
+ | vel.linear = l_scale_*joy-> | ||
+ | vel_pub_.publish(vel); | ||
+ | |||
+ | // std_msgs:: | ||
+ | // msg.data = "hello world " + parole; | ||
+ | // ROS_INFO(" | ||
+ | // pubblicatore.publish(msg); | ||
+ | | ||
+ | loop_rate.sleep(); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | int main(int argc, char** argv) | ||
+ | { | ||
+ | ros:: | ||
+ | |||
+ | TeleopTurtle teleop_turtle; | ||
+ | | ||
+ | ros:: | ||
+ | |||
+ | } | ||
+ | </ |
neurali/ros_esempio_nodo_cpp.txt · Last modified: 2020/06/08 22:20 by 127.0.0.1