Exercise 3.1 catkin_make errors>error: 'Rosbot' was not declared in this scope

I haven’t tried the answer code yet but I can’t seem to get this to work! Where is my error?


#include "rosbot_control/rosbot_class.h"
#include <ros/ros.h>

#include <iostream>
#include <list>
#include <map>
#include <string>

using namespace std;

list<float> move_and_inform(Rosbot Class rosbot, int n_secs) {
  rosbot.move_forward(n_secs);
  float x = rosbot.get_position(1);
  float y = rosbot.get_position(2);
  list<float> list_coordinates({x, y});
  return list_coordinates;
}

int main(int argc, char **argv) {
  ros::init(argc, argv, "rosbot_node");
  Rosbotclass rosbot;
  int n_secs;
  cout << "Enter the number of seconds that you want the robot to move: "
       << endl;
  cin << int n_secs;
  list<float> list_coordinates = move_and_inform(rosbot, n_secs);
  for (float number : list_coordinates) {
    cout << number << ", ";
  }

  return 0;
}
  • List item

The problem is in this function:

list move_and_inform(Rosbot Class rosbot, int n_secs) {
    rosbot.move_forward(n_secs);
    float x = rosbot.get_position(1);
    float y = rosbot.get_position(2);
    list list_coordinates({x, y});

    return list_coordinates;
}

in data type you put Rosbot Class rosbot, remember that when you specify a parameter it has only two parts:

  1. data type
  2. variable name

you are specifying 3 parts:

  1. Rosbot
  2. Class
  3. rosbot

there is the hint of the problem. The datatype is RosbotClass so it should be something like this:

list move_and_inform(RosbotClass rosbot, int n_secs) {
    rosbot.move_forward(n_secs);
    float x = rosbot.get_position(1);
    float y = rosbot.get_position(2);
    list list_coordinates({x, y});

    return list_coordinates;
}
1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.