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

ros-noob's profile - activity

2021-01-17 06:31:45 -0500 received badge  Famous Question (source)
2020-09-13 14:53:22 -0500 received badge  Famous Question (source)
2020-08-04 11:28:11 -0500 received badge  Famous Question (source)
2020-06-24 08:19:27 -0500 received badge  Famous Question (source)
2020-06-23 14:25:20 -0500 received badge  Notable Question (source)
2020-05-23 04:58:27 -0500 received badge  Notable Question (source)
2020-04-04 03:05:40 -0500 received badge  Popular Question (source)
2020-04-04 02:51:29 -0500 received badge  Popular Question (source)
2020-04-04 02:51:29 -0500 received badge  Notable Question (source)
2020-03-21 15:56:35 -0500 received badge  Famous Question (source)
2020-02-15 00:29:34 -0500 received badge  Popular Question (source)
2020-01-31 19:47:42 -0500 received badge  Notable Question (source)
2020-01-26 05:19:18 -0500 asked a question Boustrophedon cellular decomposition on a map in ROS

Boustrophedon cellular decomposition on a map in ROS Hi, I'm trying to decompose a map I have into cells. Illustrated be

2020-01-17 11:37:44 -0500 received badge  Supporter (source)
2020-01-17 11:37:29 -0500 marked best answer Pose direction not correct on rViz.

Hi, I'm trying to work on a complete coverage problem of a static map.

So, just to begin, I assumed my map to have no obstacles.

#include <ros/ros.h>
#include <vector>
#include <std_msgs/String.h>
#include <geometry_msgs/Point.h>
#include <geometry_msgs/PointStamped.h>
#include <geometry_msgs/Pose.h>
#include <geometry_msgs/PoseArray.h>
#include <nav_msgs/OccupancyGrid.h>
#include <nav_msgs/GetMap.h>
#include <ros/console.h>
#include <ros/console.h>

int rows = 1000, columns = 1000;
std::vector<int> path;
int robot_radius = 5; // Assume circle for now 
int source_r = 100, source_c = 100; // Coordinates of the center of the circle
int current_r = source_r, current_c = source_c; // Current position of center
int dir = 1; // +ve for moving right
int map_2d[1000][1000];
ros::Publisher pub;
geometry_msgs::PoseArray pa;
geometry_msgs::Point p1;
geometry_msgs::Point p2;
geometry_msgs::Point p3;
geometry_msgs::PointStamped p01;
geometry_msgs::PointStamped p02;
geometry_msgs::PointStamped p03;

int index(int r, int c)
{
    return (r * 1000) + c;
}

void make_map(const nav_msgs::OccupancyGrid& map)
{
    for(int i = 0; i < 1000; i++)
        for(int j = 0; j < 1000; j++)
            map_2d[i][j] = map.data[index(i, j)];
}
bool free_left()
{
    for(int i = 0; i < 1000; i++)
    {
        for(int j = 0; j < 1000; j++)
            if(map_2d[i][j] == 0)
                return true;
    }
    return false;
}

void cover(const nav_msgs::OccupancyGrid& map)
{
    p1.x = source_r;
    p1.y = source_c;
    p1.z = 0; int count = 0;
    while(free_left())
    {
        if(dir == 1)
        {
            if(count == 1)
            {
                p3.x = current_r;
                p3.y = current_c;
                p3.z = 0;
            }
            count++;
            if(current_c + robot_radius < columns)
            {
                path.push_back(index(current_r, current_c));
                geometry_msgs::Pose p;
                p.position.x = current_r;
                p.position.y= current_c;
                p.position.z = 0;
                p.orientation.x = 0;
                pa.poses.push_back(p);
                map_2d[current_r][current_c] = 100;
                ROS_INFO("%i", path.back());
                // mark the cells as visited
                for(int i = -5; i < 5; i++)
                {
                    for(int j = -5; j < 5; j++)
                    {
                        map_2d[current_r+i][current_c+i] = 100;
                    }
                }
                // Increment position
                current_c += 2*robot_radius;
            }
            else
            {
                dir = -1; // Move in the left direction
                current_r += 2*robot_radius;
            }
        }
        else
        {
            if(current_c + robot_radius > 0)
            {
                path.push_back(index(current_r, current_c));
                geometry_msgs::Pose p;
                p.position.x = current_r;
                p.position.y= current_c;
                p.position.z = 0;
                p.orientation.x = 180;
                pa.poses.push_back(p);
                map_2d[current_r][current_c] = 100;
                ROS_INFO("%i", path.back());
                // mark the cells as visited
                for(int i = -5; i < 5; i++)
                {
                    for(int j = -5; j < 5; j++)
                    {
                        //visited[index(current_r + i, current_c + i)] = 100;
                        map_2d[current_r+i][current_c+i] = 100;
                    }
                }
                // Increment position
                current_c -= 2*robot_radius;
            }
            else
            {
                dir = 1; // Move in the right direction
                current_r += 2*robot_radius;
            }
        }
        if(index(current_r, current_c) == 999990)
            break;
    }
    p2.x = current_r;
    p2.y = current_c;
    p2.z = 0;
}

int main(int argc, char** argv)
{
    ros::init(argc, argv, "planner");
    ros::NodeHandle n("~");
    ros::ServiceClient client = n.serviceClient<nav_msgs::GetMap>("/static_map");
    nav_msgs::GetMap srv;
    client.call(srv);
    nav_msgs::OccupancyGrid my_map = srv.response.map;
    pub = n.advertise<geometry_msgs::PoseArray>("/poseArray", 1);
    ros::Publisher point_pub1 = n.advertise<geometry_msgs::PointStamped>("/point_1", 1);
    ros::Publisher point_pub2 = n.advertise<geometry_msgs::PointStamped>("/point_2", 1);
    ros::Publisher point_pub3 = n.advertise<geometry_msgs::PointStamped>("/point_3", 1);
    pa.header.frame_id ...
(more)
2020-01-17 11:37:29 -0500 commented answer Pose direction not correct on rViz.

Thank you for your answer. I will look into it.

2020-01-15 23:31:44 -0500 asked a question Pose direction not correct on rViz.

Pose direction not correct on rViz. Hi, I'm trying to work on a complete coverage problem of a static map. So, just to

2020-01-15 05:47:33 -0500 received badge  Enthusiast
2020-01-13 12:20:57 -0500 asked a question Coverage planner for an indoor map for a vacuum cleaner

Coverage planner for an indoor map for a vacuum cleaner I have an indoor map of a room which needs to be cleaned. Now my

2020-01-07 04:23:21 -0500 received badge  Notable Question (source)
2020-01-02 06:07:17 -0500 received badge  Popular Question (source)
2020-01-01 09:34:38 -0500 marked best answer How to make a nav_msgs/OccupancyGrid manually?

Suppose I have a .png extension map in which the blocked paths are in black and free spots are white. Using OpenCV, how can I get an OccupancyGrid without using any external libraries?

2020-01-01 09:34:27 -0500 commented answer How to make a nav_msgs/OccupancyGrid manually?

Check this out. It might solve your issue as well.

2020-01-01 08:58:29 -0500 commented answer OccupancyGrid not getting published - Python.

That seems do it! Thanks a lot!

2020-01-01 08:58:03 -0500 marked best answer OccupancyGrid not getting published - Python.

Hi, so I want to publish an occupancy grid of a map.png file I have.

After running this node, I do rostopic list but it doesn't show me any published map. Can someone tell what am I doing wrong?

#!/usr/bin/env python

import rospy 
import cv2 as cv
from nav_msgs.msg import *
from std_msgs.msg import *

grid = OccupancyGrid()
def load():
    img = cv.imread('map.png', 0)

    for i in range(len(img)):
        img[i] = (img[i] / 255) * 100

    grid.data = img
    pub.publish(grid)


def main():
    rospy.init_node('loadmap', anonymous = True)
    global pub
    pub = rospy.Publisher('/map', OccupancyGrid, queue_size = 10)
    load()
    rospy.spin

if __name__ == '__main__':
    try:
        main()
    except rospy.ROSInterruptException:
        pass
2020-01-01 08:58:03 -0500 received badge  Scholar (source)
2020-01-01 02:03:45 -0500 asked a question OccupancyGrid not getting published - Python.

OccupancyGrid not getting published - Python. Hi, so I want to publish an occupancy grid of a map.png file I have. Afte

2019-12-30 18:51:30 -0500 received badge  Popular Question (source)
2019-12-30 13:34:05 -0500 commented answer How to make a nav_msgs/OccupancyGrid manually?

Oh okay. Pretty interesting indeed hahaha

2019-12-30 11:50:00 -0500 commented answer How to make a nav_msgs/OccupancyGrid manually?

Okay so, after making the changes to the array I'll just publish it as an OccupancyGrid right?

2019-12-30 03:24:32 -0500 asked a question How to make a nav_msgs/OccupancyGrid manually?

How to make a nav_msgs/OccupancyGrid manually? Suppose I have a .png extension map in which the blocked paths are in bla