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

aldolereste's profile - activity

2018-11-17 18:34:59 -0500 received badge  Good Question (source)
2018-07-13 08:05:44 -0500 received badge  Taxonomist
2018-06-25 06:56:36 -0500 received badge  Nice Question (source)
2018-01-25 09:19:26 -0500 received badge  Student (source)
2017-05-27 13:31:53 -0500 received badge  Famous Question (source)
2017-04-10 22:13:35 -0500 received badge  Notable Question (source)
2017-03-25 22:12:56 -0500 received badge  Popular Question (source)
2017-03-24 13:25:39 -0500 commented question Slow data rate from Camera vision

Just added the C++ node

2017-03-24 13:25:39 -0500 received badge  Commentator
2017-03-24 11:28:57 -0500 asked a question Slow data rate from Camera vision

I am using a Raspberry Pi 3B with Pi Camera and I set up the python code below to help me compute the position of a robot and publish it in order to use the data to control the robot. But I have an issue with the C++ code acting on those data. The code reacts way faster than the data are published making the robot to always stop ahead of the target position.

I am using the published data in a while loop in the C++ node controlling the robot. I tried to slow down the speed of the loop, but that does not seem to help.

Could you help me see through this?

#!/usr/bin/env python
import rospy
from std_msgs.msg import Float32

# import the necessary packages
from picamera.array import PiRGBArray
from picamera import PiCamera
from collections import deque
import datetime
import time
import cv2
import argparse
# import imutils  (removed)

# Math functions
import numpy as np

pub_x = rospy.Publisher('ball_pose_x', Float32, queue_size=10)
pub_y = rospy.Publisher('ball_pose_y', Float32, queue_size=10)
rospy.init_node('ball_tracking')

# initialize the camera and grab a reference to the raw camera capture
camera = PiCamera()
camera.resolution = (640, 480)
camera.framerate = 32
rawCapture = PiRGBArray(camera, size=(640, 480))

# allow the camera to warmup
time.sleep(0.1)

# ----- Basic definition -----------

# Args definition
# construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-v", "--video",
    help="path to the (optional) video file")
ap.add_argument("-b", "--buffer", type=int, default=64,
    help="max buffer size")
args = vars(ap.parse_args())


# define the lower and upper boundaries of the
# ball in the HSV color space, then initialize the
# list of tracked points
whiteLower = (0, 0, 230)
whiteUpper = (180, 25, 255)
pts = deque(maxlen=args["buffer"])

# ------ end definition ----------

# capture frames from the camera
for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
    # grab the raw NumPy array representing the image, then initialize the timestamp
    # and occupied/unoccupied text
    image = frame.array
    # print " "
    # print datetime.datetime.now()
    # -------------------- Modif start------------------

    # blurred = cv2.GaussianBlur(frame, (11, 11), 0)
    hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)

    # construct a mask for the color "white", then perform
    # a series of dilations and erosions to remove any small
    # blobs left in the mask
    mask = cv2.inRange(hsv, whiteLower, whiteUpper)
    mask = cv2.erode(mask, None, iterations=2)
    mask = cv2.dilate(mask, None, iterations=2)

    # find contours in the mask and initialize the current
    # (x, y) center of the ball
    cnts = cv2.findContours(mask.copy(), cv2.RETR_EXTERNAL,
        cv2.CHAIN_APPROX_SIMPLE)[-2]
    center = None

    # only proceed if at least one contour was found
    if len(cnts) > 0:
        # find the largest contour in the mask, then use
        # it to compute the minimum enclosing circle and
        # centroid
        c = max(cnts, key=cv2.contourArea)
        ((x, y), radius) = cv2.minEnclosingCircle(c)
        M = cv2.moments(c)
        center = (int(M["m10"] / M["m00"]), int(M["m01"] / M["m00"]))

        # Publishing data to ROS
        # print datetime.datetime.now()
        pub_x.publish(M["m10"] / M["m00"])
        pub_y.publish(M["m01"] / M["m00"])

        # only proceed if the radius meets ...
(more)
2017-03-15 09:21:45 -0500 marked best answer fatal error: ros/ros.h: No such file or directory

I have created a package using catkin_create_pkg on my raspberry pi 3 where I have previously installed Ubuntu Xenial and ROS kinetic. But everytime I am trying to compile the cpp file included in the created package I get the following error

fatal error: ros/ros.h: No such file or directory
compilation terminated.

looks like it does not see any of the header files included in my cpp file.

I have all set up the same way on my other computer running ubuntu Trusty and ROS indigo. Not sure why this is happening here.

Edit: This is what I added to my package.xml

  <build_depend>roscpp</build_depend>
  <build_depend>rospy</build_depend>
  <build_depend>std_msgs</build_depend>
  <build_depend>geometry_msgs</build_depend>
  <build_depend>message_generation</build_depend>

  <run_depend>roscpp</run_depend>
  <run_depend>rospy</run_depend>
  <run_depend>std_msgs</run_depend>
  <run_depend>geometry_msgs</run_depend>
  <run_depend>message_runtime</run_depend>

here is the Cmakelist.txt:

cmake_minimum_required(VERSION 2.8.3)
project(sphero_move)

## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED)

include_directories(${catkin_INCLUDE_DIRS})

## System dependencies are found with CMake's conventions
# find_package(Boost REQUIRED COMPONENTS system)
find_package(catkin REQUIRED COMPONENTS 
  roscpp
  rospy
  std_msgs
  geometry_msgs
  message_generation
)

## Uncomment this if the package has a setup.py. This macro ensures
## modules and global scripts declared therein get installed
## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html
# catkin_python_setup()

################################################
## Declare ROS messages, services and actions ##
################################################

## To declare and build messages, services or actions from within this
## package, follow these steps:
## * Let MSG_DEP_SET be the set of packages whose message types you use in
##   your messages/services/actions (e.g. std_msgs, actionlib_msgs, ...).
## * In the file package.xml:
##   * add a build_depend tag for "message_generation"
##   * add a build_depend and a run_depend tag for each package in MSG_DEP_SET
##   * If MSG_DEP_SET isn't empty the following dependency has been pulled in
##     but can be declared for certainty nonetheless:
##     * add a run_depend tag for "message_runtime"
## * In this file (CMakeLists.txt):
##   * add "message_generation" and every package in MSG_DEP_SET to
##     find_package(catkin REQUIRED COMPONENTS ...)
##   * add "message_runtime" and every package in MSG_DEP_SET to
##     catkin_package(CATKIN_DEPENDS ...)
##   * uncomment the add_*_files sections below as needed
##     and list every .msg/.srv/.action file to be processed
##   * uncomment the generate_messages entry below
##   * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...)

## Generate messages in the 'msg' folder
# add_message_files(
#   FILES
#   Message1.msg
#   Message2.msg
# )

## Generate services in the 'srv' folder
# add_service_files(
#   FILES
#   Service1.srv
#   Service2.srv
# )

## Generate actions in the 'action' folder
# add_action_files(
#   FILES
#   Action1.action
#   Action2.action
# )

## Generate added messages and services with any dependencies listed here
# generate_messages(
#   DEPENDENCIES
#   std_msgs  # Or other packages containing msgs
# )

################################################
## Declare ROS dynamic reconfigure parameters ##
################################################

## To declare and build dynamic reconfigure parameters within this
## package, follow these steps:
## * In the file package.xml:
##   * add a build_depend and a run_depend tag for "dynamic_reconfigure"
## * In this file (CMakeLists.txt):
##   * add "dynamic_reconfigure" to
##     find_package(catkin REQUIRED COMPONENTS ...)
##   * uncomment the "generate_dynamic_reconfigure_options" section below
##     and list every .cfg file to be processed

## Generate dynamic reconfigure parameters in the 'cfg' folder
# generate_dynamic_reconfigure_options(
#   cfg/DynReconf1.cfg
#   cfg/DynReconf2 ...
(more)
2016-09-21 06:10:10 -0500 commented question callback function c++

I've updated it with errors. thanks

2016-09-19 00:11:36 -0500 received badge  Famous Question (source)
2016-09-18 14:32:56 -0500 received badge  Famous Question (source)
2016-09-16 10:02:12 -0500 commented question callback function c++

Do you still need me to add the errors? I think the problem is coming from the type of that

ball_pose
2016-09-16 09:58:52 -0500 answered a question callback function c++

Was making a mistake, and finally found it.

void poseCallback(const std_msgs::Float32::ConstPtr & pose_message){ ball_pose.data = pose_message->data;}

thanks

2016-09-16 07:45:00 -0500 commented answer callback function c++

did not find it yet!

2016-09-14 14:26:52 -0500 received badge  Notable Question (source)
2016-09-14 14:05:40 -0500 commented answer callback function c++

I've just updated the code.

2016-09-14 14:03:43 -0500 edited question callback function c++

I have been trying to implement a call back function with no success.

Here is the problem. I have a subscriber that is supposed to listen to a topic. Let's call it A. A is of type std_msgs/Float32

How can I implement a callback function?

#include "ros/ros.h"
#include "geometry_msgs/Twist.h"
#include "std_msgs/Float32.h"
#include <sstream>

using namespace std;

ros::Publisher velocity_publisher;
ros::Subscriber pose_sub;
std_msgs::Float32 ball_pose;

void poseCallback(const std_msgs::Float32::ConstPtr & pose_message);
//void moveUp(std_msgs::Float32 distance_tolerance);

int main(int argc, char **argv)
{
    ros::init(argc, argv, "sphero_move");
    ros::NodeHandle n;

    velocity_publisher = n.advertise<geometry_msgs::twist>("/cmd_vel", 1000);
    pose_sub = n.subscribe("/ball_pose_x", 10, poseCallback);   
    ros::Rate loop_rate(0.5);

    //moveUp(30.00);
    loop_rate.sleep();

    ros::spin();

    return 0;
}

void poseCallback(const std_msgs::Float32::ConstPtr & pose_message)
{
    ball_pose = pose_message->data;
}

/**void moveUp(std_msgs::Float32 distance_tolerance)
{
    geometry_msgs::Twist vel_msg;
    ros::Rate loop_rate(10);

    do{
        vel_msg.linear.x = 25;
        vel_msg.linear.y = 0;
        vel_msg.linear.z = 0;

        velocity_publisher.publish(vel_msg);

        ros::spinOnce();
        loop_rate.sleep();

        }while((ball_pose-500)<distance_tolerance); }**="" <="" pre="">

I want to be able to update the position of the robot in every iteration to be able to act on the current position, since the robot is moving.

Here is the error I am receiving.

/home/sphero/catkin_ws/src/sphero_controller/src/sphero_move.cpp: In function ‘void poseCallback(const ConstPtr&)’: /home/sphero/catkin_ws/src/sphero_controller/src/sphero_move.cpp:34:12: error: no match for ‘operator=’ (operand types are ‘std_msgs::Float32 {aka std_msgs::Float32_<std::allocator<void> >}’ and ‘const _data_type {aka const float}’) ball_pose = pose_message->data; ^ In file included from /home/sphero/catkin_ws/src/sphero_controller/src/sphero_move.cpp:3:0: /opt/ros/kinetic/include/std_msgs/Float32.h:22:8: note: candidate: std_msgs::Float32_<std::allocator<void> >& std_msgs::Float32_<std::allocator<void> >::operator=(const std_msgs::Float32_<std::allocator<void> >&) struct Float32_ ^ /opt/ros/kinetic/include/std_msgs/Float32.h:22:8: note: no known conversion for argument 1 from ‘const _data_type {aka const float}’ to ‘const std_msgs::Float32_<std::allocator<void> >&’ sphero_controller/CMakeFiles/sphero_move_node.dir/build.make:62: recipe for target 'sphero_controller/CMakeFiles/sphero_move_node.dir/src/sphero_move.cpp.o' failed make[2]: * [sphero_controller/CMakeFiles/sphero_move_node.dir/src/sphero_move.cpp.o] Error 1 CMakeFiles/Makefile2:808: recipe for target 'sphero_controller/CMakeFiles/sphero_move_node.dir/all' failed make[1]: [sphero_controller/CMakeFiles/sphero_move_node.dir/all] Error 2 Makefile:138: recipe for target 'all' failed make: ** [all] Error 2

2016-09-14 10:09:42 -0500 received badge  Popular Question (source)