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

Parth2851's profile - activity

2022-06-20 22:20:59 -0500 marked best answer How to extract the map matrix after subscribing to /map of map_server?

I need to run Dijkstra's algorithm on this map.

So till now, I've used map_server and got the /map and /map_metadata topics. I'm not quite sure how to proceed further.

This is what I've done so far.

#include < ros/ros.h>

void dijkstra() {

}

int main(int argc, char **argv) {

ros::init(argc, argv, "shortestpath");

ros::Nodehandle n("~");

ros::Subscriber sub = n.subscribe("/map", 1000, dijkstra);

}

/map gives a 1D array so I need to use it and convert it in a 2D matrix.

2021-10-10 12:46:36 -0500 received badge  Notable Question (source)
2021-10-10 12:46:36 -0500 received badge  Famous Question (source)
2020-12-05 06:22:16 -0500 received badge  Famous Question (source)
2020-12-04 10:08:21 -0500 received badge  Famous Question (source)
2020-10-25 21:03:15 -0500 received badge  Notable Question (source)
2020-10-25 21:03:15 -0500 received badge  Famous Question (source)
2020-06-25 05:03:04 -0500 received badge  Famous Question (source)
2020-05-18 05:46:37 -0500 received badge  Notable Question (source)
2020-04-19 22:35:36 -0500 received badge  Famous Question (source)
2020-03-24 19:15:23 -0500 received badge  Famous Question (source)
2020-01-21 04:13:51 -0500 received badge  Famous Question (source)
2020-01-20 07:27:37 -0500 received badge  Famous Question (source)
2019-12-25 05:30:54 -0500 edited question PoseArray not getting published

PoseArray not getting published Hi, so I'm trying to find the shortest path from source to destination using dijkstra's

2019-12-25 05:30:12 -0500 edited question PoseArray not getting published

PoseArray not getting published Hi, so I'm trying to find the shortest path from source to destination using dijkstra's

2019-12-25 04:08:39 -0500 edited question PoseArray not getting published

PoseArray not getting published Hi, so I'm trying to find the shortest path from source to destination using dijkstra's

2019-12-25 00:25:35 -0500 received badge  Notable Question (source)
2019-12-23 04:37:26 -0500 commented answer PoseArray not getting published

Okay, yes. I made a publisher in mainand then I declared a global poseArray and then published it in a loop something li

2019-12-22 12:32:58 -0500 commented answer PoseArray not getting published

This worked! thanks!

2019-12-22 12:32:25 -0500 marked best answer PoseArray not getting published

Hi, so I'm trying to find the shortest path from source to destination using dijkstra's algorithm.

In this program, I intend to first store the path in an array from which I retrieve it and publish it as a Pose Array. However, when I run this program I see no PoseArray topics.

I am trying to publish it from inside the dijkstra function.

#include <ros/ros.h>
#include <math.h>
#include <queue>
#include <vector>
#include <std_msgs/String.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>
#define FMAX 999999999.99


    int rows = 1000, columns = 1000, size = rows * columns;
    bool visited[1000000];
    float distance[1000000];
    int prev[1000000];
    int source = 15100, destination = 990500; // Random source and destination
    .
    .
    .

    void dijkstra(const nav_msgs::OccupancyGrid& map)
    {
        prev[source] = 0;
        node first = {source, 0.0}; 
        pq.push(first);
        while(!pq.empty())
        {
            .
                    .
            int rr, cc;
            for(int i = 0; i < 8; i++) // to calculate neighbours
            {
                .
                            .
                            .
                .
            }
        }

        poseArray.poses = pose_vector;
        ros::NodeHandle n("~");
        ros::Publisher pose_array_pub = n.advertise<geometry_msgs::PoseArray>("/poseArray", 1);
        pose_array_pub.publish(poseArray);
    }



    int main(int argc, char **argv)
    {
        init();
        distance[source] = 0;
        visited[source] = true;
        ros::init(argc, argv, "dijkstra");
        ros::NodeHandle n("~");
        ros::ServiceClient client = n.serviceClient<nav_msgs::GetMap>("/static_map");
        nav_msgs::OccupancyGrid my_map = srv.response.map;
        dijkstra(my_map);
        ros::spin();    
    }

EDIT - Deleted parts of my code to make the question more relevant.

2019-12-22 11:40:19 -0500 received badge  Popular Question (source)
2019-12-22 07:22:15 -0500 asked a question PoseArray not getting published

PoseArray not getting published Hi, so I'm trying to find the shortest path from source to destination using dijkstra's

2019-12-19 13:56:00 -0500 marked best answer How to save nav_msgs/GetMap service and pass it into a function?

So, what I'm going for is to rather having a callback function I want to make my node a client to that service and then pass it to the another function.

        ros::init(argc, argv, "dijkstra");
        ros::NodeHandle n("~");
        ros::ServiceClient client = n.serviceClient<nav_msgs::GetMap>("map");
        nav_msgs::GetMap srv;
        client.call(srv);
        nav_msgs::OccupancyGrid = srv.response;

Running the above code gives me the error-

 error: expected unqualified-id before ‘=’ token
   nav_msgs::OccupancyGrid = srv.response;

I need to pass the map to a function void dijkstra(???)

2019-12-19 05:11:26 -0500 commented answer How to save nav_msgs/GetMap service and pass it into a function?

Okay, yes I did that. nav_msgs::OccupancyGrid map = srv.response; I'm getting this- error: conversion from ‘nav_msgs::G

2019-12-19 04:58:07 -0500 commented answer How to save nav_msgs/GetMap service and pass it into a function?

Okay, yes I did that. nav_msgs::OccupancyGrid map = srv.response; I'm getting this- error: conversion from ‘nav_msgs::G

2019-12-19 00:39:25 -0500 received badge  Popular Question (source)
2019-12-18 15:10:14 -0500 asked a question How to save nav_msgs/GetMap service and pass it into a function?

How to save nav_msgs/GetMap service and pass it into a function? So, what I'm going for is to rather having a callback f

2019-12-17 14:20:03 -0500 asked a question What does bt mean in gdb?

What does bt mean in gdb? I am trying to debug my node which implements dijkstra's algorithm. I am using gdb for this.

2019-12-17 09:57:37 -0500 asked a question Segmentation fault - dijkstra's algorithm

Segmentation fault - dijkstra's algorithm I am making a ros node to implement dijkstra's algorithm on a 1000x1000 pixel

2019-12-16 22:23:17 -0500 received badge  Popular Question (source)
2019-12-16 15:48:19 -0500 commented question Segmentation fault(core dumped)

Updated the question. The error just says "Segmentation fault(core cumped)" after rosrun.

2019-12-16 15:47:21 -0500 edited question Segmentation fault(core dumped)

Segmentation fault(core dumped) Hello, I am trying to run dijkstra's algorithm on a map that I have. This may seem tri

2019-12-16 15:35:36 -0500 asked a question Segmentation fault(core dumped)

Segmentation fault(core dumped) Hello, I am trying to run dijkstra's algorithm on a map that I have. This may seem tri

2019-12-16 15:25:23 -0500 asked a question How to debug using gdb

How to debug using gdb Hello, I am trying to debug a node which implements dijkstra's algorithm. I have made a launch fi

2019-12-16 07:07:10 -0500 received badge  Notable Question (source)
2019-12-15 10:45:28 -0500 marked best answer Rosrun can not find an executable file.

So I have a package called dijkstra, it contains a cpp program in the src folder called algorithm_1.cpp which I need to run.

First I run the command source devel/setup.bash to set up the environment. After that I do, rosrun dijkstra and press tab twice, but it doesn't find any executable file.

This is the CMake-

cmake_minimum_required(VERSION 2.8.3)
project(dijkstra)

find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
geometry_msgs
)

include_directories(include ${catkin_INCLUDE_DIRS})

add_executable(${PROJECT_NAME} src/algorithm_1.cpp)

target_link_libraries(${PROJECT_NAME}
${catkin_LIBRARIES}
)

EDIT-

This is the error I get -

parth@Parth:~/catkin_ws/src$ rosrun dijkstra dijkstra.cpp
[rosrun] Couldn't find executable named dijkstra.cpp below /home/parth/catkin_ws/src/dijkstra
[rosrun] Found the following, but they're either not files,
[rosrun] or not executable:
[rosrun]   /home/parth/catkin_ws/src/dijkstra/src/dijkstra.cpp