lemueltra

arduino pub_pot

Oct 9th, 2019
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <ros.h>
  2. #include <std_msgs/Float64.h>
  3.  
  4. const int pot_pin = A0;
  5.  
  6. int posicao = 0, sensor = 0;
  7.  
  8. ros::NodeHandle nh;
  9.  
  10. std_msgs::Float64 posi;
  11. //std_msgs::Float64 corr;
  12.  
  13. //void contr_callback(const std_msgs::Float64& msg){
  14. //    termo_pd_escalonado = msg.data;
  15. //}
  16.  
  17. //ros::Subscriber<std_msgs::Float64> sc("controle", &contr_callback);
  18. //ros::Subscriber<std_msgs::Float64> ss("setpt", &setpoint_callback);
  19.  
  20. ros::Publisher p("posicao_mestre", &posi);
  21. //ros::Publisher c("corrente_mestre", &corr);
  22.  
  23. void setup() {
  24.   nh.initNode();
  25.   nh.advertise(p);
  26.  
  27. }
  28.  
  29. void loop() {
  30.   sensor = analogRead(pot_pin);            
  31.   posicao = map(sensor, 0, 1023, 0, 180);  
  32.  
  33.   posi.data = posicao;
  34.  
  35.   p.publish( &posi );
  36.  
  37.   nh.spinOnce();
  38.   delay(20);
  39. }
Advertisement
Add Comment
Please, Sign In to add comment