Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gazebo Tutorial and partial Oops assignment added. #2

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Shivam/Gazebo/my_robots/model.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<model>
<name>My Robot</name>
<version>1.0</version>
<sdf version='1.4'>model.sdf</sdf>

<author>
<name>My Name</name>
<email>[email protected]</email>
</author>

<description>
My awesome robot.
</description>
</model>
118 changes: 118 additions & 0 deletions Shivam/Gazebo/my_robots/model.sdf
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<?xml version='1.0'?>
<sdf version='1.4'>
<model name="my_robot">
<static>false</static>
<link name='chassis'>
<pose>0 0 0.1 0 0 0</pose>

<visual name='visual'>
<geometry>
<box>
<size>0.4 0.2 0.1</size>
</box>
</geometry>
</visual>

<collision name='collision'>
<geometry>
<box>
<size>.4 .2 .1</size>
</box>
</geometry>
</collision>



<visual name='caster_visual'>
<pose>-0.15 0 -.05 0 0 0</pose>
<geometry>
<sphere>
<radius>0.05</radius>
</sphere>
</geometry>
</visual>



<collision name='caster_collision'>
<pose>-0.15 0 -0.05 0 0 0</pose>
<geometry>
<sphere>
<radius>0.05</radius>
</sphere>
</geometry>
<surface>
<friction>
<ode>
<mu>0</mu>
<mu2>0</mu2>
<slip1>1.0</slip1>
<slip2>1.0</slip2>
</ode>
</friction>
</surface>
</collision>
</link>

<link name='left_wheel'>
<pose>0.1 0.13 0.1 0 1.5707 1.5707</pose>
<visual name="left_wheel_visual">
<geometry>
<cylinder>
<radius>0.1</radius>
<length>0.05</length>
</cylinder>
</geometry>
</visual>
<collision name="left_collision">
<geometry>
<cylinder>
<radius>0.1</radius>
<length>0.05</length>
</cylinder>
</geometry>
</collision>
</link>
<link name="right_wheel">
<pose>0.1 -0.13 0.1 0 1.5707 1.5707</pose>
<collision name="right_collision">
<geometry>
<cylinder>
<radius>0.1</radius>
<length>0.05</length>
</cylinder>
</geometry>
</collision>
<visual name="visual">
<geometry>
<cylinder>
<radius>.1</radius>
<length>.05</length>
</cylinder>
</geometry>
</visual>
</link>

<joint type="revolute" name="left_wheel_hinge">
<pose>0 0 -0.03 0 0 0</pose>
<child>left_wheel</child>
<parent>chassis</parent>
<axis>
<xyz>0 1 0</xyz>
</axis>
</joint>

<joint type="revolute" name="right_wheel_hinge">
<pose>0 0 0.03 0 0 0</pose>
<child>right_wheel</child>
<parent>chassis</parent>
<axis>
<xyz>0 1 0</xyz>
</axis>
</joint>


</model>
</sdf>


29 changes: 29 additions & 0 deletions Shivam/Oops1/Oops.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <iostream>
#include <opencv/highgui.h>
#include <opencv/cv.h>
#include "findCentroid.cpp"
#include "blobDetect.cpp"
#include "queue.h"

image img_class;

int main()
{
int flag1=1, flag2=1;
int count=0;
cv::Mat bin,edit;
bin=binary(img_class.img,190.0);
img_class.img_bin=bin;
count= img_class.bfs();
img_class.count=count;
img_class.findCentroid();
while (flag1==1 && flag2==1)
{
flag1=img_class.updatepos1();
flag2= img_class.updatepos2();
img_class.printScore();
}

std::cout<<"GAME OVER";
return 0;
}
59 changes: 59 additions & 0 deletions Shivam/Oops1/Oops_class.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#ifndef Oops_class_h
#define Oops_class_h

#include <iostream>
#include <opencv/highgui.h>
#include <opencv/cv.h>

class pos
{
public:
pos()
{
x=0,y=0;colour=0;
}
int x;
int y;
int colour;
};

class image
{ int score1;
int score2;
pos currentpos1;
pos currentpos2;

public:
int count;
cv::Mat img;
cv::Mat img_bin;
int **visited;
image();
pos *centroid;
int bfs();
int updatepos1();
int updatepos2();
void findCentroid();
void printScore();
};

image::image()
{
score1=0,score2=0;
count=0;
score1=0;
score2=0;
img = cv::imread("/home/aries/Desktop/1.jpg",0);
int rows=img.rows;
int cols=img.cols;
visited= new int*[rows];
for(int j=0;j<rows;j++)
{ visited[j]= new int[cols];
for(int i=0;i<cols;i++)
visited[i][j]=-1;
}
centroid= new pos[count];

}

#endif
71 changes: 71 additions & 0 deletions Shivam/Oops1/blobDetect.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#ifndef blobDetect_h
#define blobDetect_h
#include <iostream>
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <opencv2/imgproc/imgproc.hpp>
#include "Oops_class.h"
#include "queue.h"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have not included Oops_class.h in this file.



cv::Mat binary(cv::Mat img,float threshold)
{ cv::Mat img_gray,img_bin;
img=cv::imread("/home/aries/Desktop/1.jpg",1);
cvtColor(img,img_gray,CV_RGB2GRAY);
cv::threshold(img_gray,img_bin,threshold,255.0,cv::THRESH_BINARY);
cv::imwrite("img_bin3.jpg",img_bin);
return img_bin;

}

int image::bfs()
{
queue q;
int x=0,y=0;
int cols=img_bin.cols, rows=img_bin.rows;
int count=1;

for(int j=0;j<img_bin.rows;j++)
for(int i=0;i<img_bin.cols;i++)
{
if((img_bin.at<uchar>(i,j))==0)
{
if(visited[i][j]==-1)
{
q.enqueue(i,j);
q.queueFront(&x,&y);
visited[i][j]=0;

while(!q.isEmpty())
{ q.queueFront(&x,&y);
q.dequeue();
for(int l=y-1;l<=y+1;l++)
for(int k=x-1;k<=x+1;k++)
{
if(k>0 && k<cols && l>0 && l<rows && visited[k][l]==-1 && img_bin.at<uchar>(i,j)==0)
{
q.enqueue(k,l);
visited[k][l]=count;

}

}
visited[x][y]=count;
}
count++;
std::cout<<count<<std::endl;
}


}
}

return count;

}

#endif



Loading