ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

pawlass's profile - activity

2019-05-28 01:15:59 -0500 received badge  Taxonomist
2019-05-22 21:00:55 -0500 received badge  Notable Question (source)
2018-09-22 23:21:31 -0500 received badge  Famous Question (source)
2018-09-21 06:50:58 -0500 received badge  Notable Question (source)
2018-09-21 04:41:33 -0500 received badge  Popular Question (source)
2018-09-21 04:16:58 -0500 received badge  Citizen Patrol
2018-09-21 03:57:42 -0500 marked best answer How to use ROS Control on real robot?

Hi everyone,

I would like to control the motor/servo motor using ros_control. I did courses at robotingiteacademy, but I can't understand practically what I should do now. I need information how to read and transmit data from the encoder to ROS and how to send data to the engine to be able to control it. I would be grateful for also example. I put my code.

#define ROSSERIAL_ARDUINO_TCP
#include <Timers.h>
#include <ros.h>
#include <std_msgs/String.h>
#include <std_msgs/Float64.h>

byte mac[]= {
   0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};

IPAddress ip(10,3,2,25);
IPAddress server(10,3,2,51);
// Set the rosserial socket server port
const uint16_t serverPort = 11411;

void ros_set_current_limit( const std_msgs::Float64& cmd_msg); void ros_set_temp_limit( const std_msgs::Float64& 
cmd_msg); void ros_set_joint_min_position( const std_msgs::Float64& cmd_msg); void ros_set_joint_max_position( 
const std_msgs::Float64& cmd_msg); void ros_set_joint_position( const std_msgs::Float64& cmd_msg); float 
read_ADC(int pin, int ilosc_odczytow=1, bool odrzuc_brzegowe=0);

// CONSTANTS

const byte pin_TE   = A1; 

// VARIABLES
// ROS

ros::NodeHandle nh;
std_msgs::Float64 adc_msg;

Timer timer_adc_cs;

float odczytADC_CS  = 0.0; // aktualna wartosc czujnika pradu float odczytADC_TE  = 0.0;
temperatury float odczytADC_EN  = 0.0;

// Wartosci brzegowe
float max_current   =  10.0;

bool wystapila_komunikacja = 0;
- SECURITY

// Publishers
ros::Publisher publish_te("/sensors/temp/get",    &adc_msg); ros::Publisher publish_cs("/sensors/current/get", 
&adc_msg); ros::Publisher publish_en("/sensors/encoder/get", &adc_msg);

// Subscribers
ros::Subscriber <std_msgs::Float64>
subscriber_set_current_limit("/sensors/current/limit/set",
ros_set_current_limit);
ros::Subscriber <std_msgs::Float64>
subscriber_set_temp_limit("/sensors/temp/limit/set", ros_set_temp_limit); ros::Subscriber <std_msgs::Float64> 
subscriber_set_joint_position("/joint_position/set",
ros_set_joint_position);
ros::Subscriber <std_msgs::Float64>
subscriber_set_joint_min_position("/joint_position/min/set",
ros_set_joint_min_position);
ros::Subscriber <std_msgs::Float64>
subscriber_set_joint_max_position("/joint_position/max/set",
ros_set_joint_max_position);

// SETUP

void setup() {
   Serial.begin(115200);

   Ethernet.begin(mac, ip);

   Serial.println("aa");
   // DC Motor D9 (16bit), D4, D7
   // analogWriteResolution(12);

   pinMode(pin_PWM, OUTPUT);
   pinMode(pin_DCL, OUTPUT);
   pinMode(pin_DCR, OUTPUT);
   // // ADC A0, A1, A2
   pinMode(pin_CS, INPUT);
   pinMode(pin_TE, INPUT);
   pinMode(pin_EN, INPUT);

   nh.getHardware()->setConnection(server, serverPort);
   nh.initNode();

   delay(1000);
   nh.advertise(publish_cs);
   nh.advertise(publish_te);
   nh.advertise(publish_en);

   nh.subscribe(subscriber_set_temp_limit);
   nh.subscribe(subscriber_set_current_limit);
   nh.subscribe(subscriber_set_joint_position);
   nh.subscribe(subscriber_set_joint_min_position);
   nh.subscribe(subscriber_set_joint_max_position);

   delay(1000);

   timer_adc_cs.begin(FREQ(czestotliwosc_ADC_CS));
   timer_adc_te.begin(FREQ(czestotliwosc_ADC_TE));
   timer_adc_en.begin(FREQ(czestotliwosc_ADC_EN));

   timer_sec.begin(FREQ(czestotliwosc_SEC));
}

// LOOP
void loop() {
// ADC READ - temperature sensor

    if (timer_adc_te.available())ty
    {
      // int bledy = timer_adc_cs.errors();
      odczytADC_TE = read_ADC(pin_TE, 10, 1);
      // Wyslanie komunikatu ROS
      adc_msg.data = odczytADC_TE;
      publish_te.publish(&adc_msg);
      nh.spinOnce();

  //    timer_adc.resetErrors();
    }

  // ADC READ - current sensor
    if (timer_adc_cs.available())
    {
      // int bledy = timer_adc_cs.errors();
      odczytADC_CS = read_ADC(pin_CS, 10, 1);
      adc_msg.data = odczytADC_CS;
      // Wyslanie komunikatu ROS
      publish_cs.publish(&adc_msg);
      nh.spinOnce();

  //    timer_adc.resetErrors();
    }

    // ADC READ - motor encoder
    if (timer_adc_en.available())
    {
      // int bledy = timer_adc_cs.errors();
      odczytADC_EN = read_ADC(pin_EN, 10, 1);
      // Konwersja z ADC na wartosc odchylenia
      // adc_msg.data = 1.456;
      adc_msg.data = (odczytADC_EN / 1024) * 100;
      // Wyslanie komunikatu ROS
      publish_en.publish(&adc_msg);
      nh.spinOnce();
  //    timer_adc.resetErrors();
    }

   // SECURITY
   if (timer_sec.available()) // Gdy przekroczono time odczytu ADC, uruchom odczyty
   {
   }
}

// FUNKCJE
void helper_sortowanie(int a[], int size) {
   for ( int i = 0 ; i < ( size - 1 ) ; i++)
   {
     for ( int o = ( i + 1 ) ; o < size ; o++ )
     {
       if(a[o] > a ...
(more)
2018-09-21 03:57:42 -0500 received badge  Scholar
2018-09-21 03:51:06 -0500 asked a question How to use ROS Control on real robot?

How to use ROS Control on real robot? Hi everyone, I would like to control the motor/servo motor using ros_control. I di

2018-08-01 02:02:05 -0500 received badge  Enthusiast
2018-07-31 11:12:52 -0500 received badge  Popular Question (source)
2018-07-26 02:38:47 -0500 received badge  Supporter (source)
2018-07-24 02:20:13 -0500 edited question Traffic planning in rviz and execution in Gazebo problem

Traffic planning in rviz and execution in Gazebo problem Using the moveit package I wanted to create a controller contro

2018-07-24 02:20:13 -0500 received badge  Editor (source)
2018-07-24 02:16:28 -0500 edited question Traffic planning in rviz and execution in Gazebo problem

Traffic planning in rviz and execution in Gazebo problem Using the moveit package I wanted to create a controller contro

2018-07-23 11:06:08 -0500 asked a question Traffic planning in rviz and execution in Gazebo problem

Traffic planning in rviz and execution in Gazebo problem Using the moveit package I wanted to create a controller contro