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

Final noetic nav version #38

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Empty file added ws/a.out
Empty file.
5 changes: 5 additions & 0 deletions ws/map.pgm

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions ws/map.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
image: map.pgm
resolution: 0.050000
origin: [-10.000000, -10.000000, 0.000000]
negate: 0
occupied_thresh: 0.65
free_thresh: 0.196

14 changes: 13 additions & 1 deletion ws/src/actions/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,24 @@ add_service_files(
CreateGoal.srv
)


# ## Generate actions in the 'action' folder

## Generate actions in the 'action' folder

# add_action_files(
# DIRECTORY action
# FILES
# navServ.action
# moveAction.action

# )

# ## Generate added messages and services with any dependencies listed here
# generate_messages(
# DEPENDENCIES
# actionlib_msgs std_msgs geometry_msg
# moveAction.action
# )
## Generate added messages and services with any dependencies listed here
# generate_messages(
# DEPENDENCIES
Expand Down Expand Up @@ -113,7 +123,9 @@ add_service_files(
catkin_package(
# INCLUDE_DIRS include
# LIBRARIES actionlib_tutorial

CATKIN_DEPENDS actionlib actionlib_msgs move_base_msgs geometry_msgs roscpp rospy std_msgs message_runtime sensor_msgs

# DEPENDS system_lib
)

Expand Down
14 changes: 7 additions & 7 deletions ws/src/actions/action/navServ.action
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#goal definition
uint8 NAV_MODE = 0
uint8 FORWARD = 1
uint8 BACKWARD = 2
uint8 DOOR_SIGNAL = 3
# #goal definition
# uint8 NAV_MODE = 0
# uint8 FORWARD = 1
# uint8 BACKWARD = 2
# uint8 DOOR_SIGNAL = 3

string target_location
uint8 goal_type
# string target_location
# uint8 goal_type
geometry_msgs/PoseStamped target_pose
---
#result definition
Expand Down
3 changes: 3 additions & 0 deletions ws/src/actions/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
<build_depend>actionlib</build_depend>
<build_depend>actionlib_msgs</build_depend>
<build_depend>move_base_msgs</build_depend>
<build_depend>frida_navigation_interfaces</build_depend>
<build_depend>message_generation</build_depend>
<build_depend>geometry_msgs</build_depend>
<build_depend>roscpp</build_depend>
Expand All @@ -61,6 +62,7 @@
<build_export_depend>actionlib</build_export_depend>
<build_export_depend>actionlib_msgs</build_export_depend>
<build_export_depend>move_base_msgs</build_export_depend>
<build_export_depend>frida_navigation_interfaces</build_export_depend>
<build_export_depend>geometry_msgs</build_export_depend>
<build_export_depend>roscpp</build_export_depend>
<build_export_depend>rospy</build_export_depend>
Expand All @@ -69,6 +71,7 @@
<exec_depend>actionlib</exec_depend>
<exec_depend>geometry_msgs</exec_depend>
<exec_depend>move_base_msgs</exec_depend>
<exec_depend>frida_navigation_interfaces</exec_depend>
<exec_depend>actionlib_msgs</exec_depend>
<exec_depend>message_generation</exec_depend>
<exec_depend>roscpp</exec_depend>
Expand Down
54 changes: 54 additions & 0 deletions ws/src/actions/scripts/goalCreatorClient.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/python3

import rospy
from frida_navigation_interfaces.srv import CreateGoal
from geometry_msgs.msg import PoseStamped


class GoalCreator:
def __init__(self) -> None:
self.goal_creator_service = rospy.ServiceProxy(
"/create_goal", CreateGoal
)
self.goal_creator_service.wait_for_service()

self.og_pub = rospy.Publisher("/og_goal", PoseStamped, queue_size=10)
self.pub = rospy.Publisher("/test_goal", PoseStamped, queue_size=10)

rospy.loginfo("Goal Creator Service is ready")

# Receive target pose and offset to goal
def call_service(self):
target = PoseStamped()
target.header.frame_id = "laser_frame"
target.pose.position.x = 0.0
target.pose.position.y = 0.0
target.pose.position.z = 0.0
target.pose.orientation.x = 0.0
target.pose.orientation.y = 0.0
target.pose.orientation.z = 0.0
target.pose.orientation.w = 1.0

self.og_pub.publish(target)

x_offset = 1.0
y_offset = 0.0

try:
response = self.goal_creator_service(target, x_offset, y_offset)
print(response)
except rospy.ServiceException as e:
print(f"Service call failed: {e}")
return

self.pub.publish(response.goal)

if __name__ == "__main__":
rospy.init_node("goal_caller", anonymous=False)
goalCreator = GoalCreator()

while not rospy.is_shutdown():
goalCreator.call_service()
rospy.sleep(1)


4 changes: 2 additions & 2 deletions ws/src/actions/scripts/navClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def createMsg(self):

def nav_goal(self, target):
class NavGoalScope:
target_location = target
target_location = "kitchen table"
result = False
pose = PoseStamped()

Expand All @@ -70,7 +70,7 @@ def get_result_callback(state, result):

rospy.loginfo("Sending Nav Goal")
self.client.send_goal(
navServGoal(target_location = NavGoalScope.target_location, goal_type = navServGoal.BACKWARD, target_pose = NavGoalScope.pose),
navServGoal(target_location = NavGoalScope.target_location),
feedback_cb=nav_goal_feedback,
done_cb=get_result_callback)

Expand Down
25 changes: 18 additions & 7 deletions ws/src/actions/scripts/navServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import tf2_geometry_msgs
from move_base_msgs.msg import MoveBaseAction, MoveBaseGoal
from frida_navigation_interfaces.msg import navServAction, navServGoal, navServResult
from frida_navigation_interfaces.srv import getLocations
import tf2_ros
from sklearn.linear_model import RANSACRegressor

Expand Down Expand Up @@ -80,8 +81,12 @@ def __init__(self, name):

# Initialize Navigation Action Server
self._as = actionlib.SimpleActionServer(self._action_name, navServAction, execute_cb=self.execute_cb, auto_start = False)
self.info_keeper = actionlib.SimpleActionServer("get_locations", getLocations, execute_cb=self.get_locations, auto_start=False)
self._as.start()

def get_locations(self, goal):
rospy.loginfo("Getting locations")
self.info_keeper.set_succeeded(getLocations(locations=str(self.placesPoses)))

def initPlaces(self):
# create a dictionary of places and their poses using the json file which has the following format
Expand Down Expand Up @@ -109,30 +114,29 @@ def initPlaces(self):
def execute_cb(self, goal):
rospy.loginfo("[INFO] Executing goal")
target = str(goal.target_location)
goal_type = goal.goal_type
goal_pose = self.get_goal(target) if target != "" else goal.target_pose
cmd_vel = Twist()
if (goal_type == goal.NAV_MODE):
if (True):
if goal_pose is None:
rospy.loginfo("[ERROR] Invalid target")
self._as.set_succeeded(navServResult(result=False))

self.send_goal(goal_pose)
rospy.loginfo("[INFO] Robot Moving Towards " + target if target != "" else goal.target_pose)
self._as.set_succeeded(navServResult(result=True))
elif (goal_type == goal.FORWARD):
elif (False):
if goal_pose is None:
rospy.loginfo("[ERROR] Invalid target")
self._as.set_succeeded(navServResult(result=False))

self.move_forward(cmd_vel, goal_pose)
rospy.loginfo("[INFO] Robot approached " + target)
self._as.set_succeeded(navServResult(result=self.success))
elif (goal_type == goal.BACKWARD):
elif (False):
self.move_backward(cmd_vel)
rospy.loginfo("[INFO] Robot moved backward")
self._as.set_succeeded(navServResult(result=self.success))
elif (goal_type == goal.DOOR_SIGNAL):
elif (False):
self.door_signal()
rospy.loginfo("[INFO] Detected door signal")
self._as.set_succeeded(navServResult(result=self.success))
Expand All @@ -142,7 +146,13 @@ def execute_cb(self, goal):


def get_goal(self, target : str):
keys = target.split(" ")
print(f"quiere ir a : {target}")
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this lines. Avoid this type of approach

if "living" in target:
keys = target.split(" ")
keys[0] = "living_room"
keys.pop(1)
print(keys)


if (len(keys) <= 1):
if (keys[0] in self.placesPoses):
Expand All @@ -156,7 +166,8 @@ def get_goal(self, target : str):
elif (len(keys) <= 2 and keys[0] in self.placesPoses and keys[1] in self.placesPoses[keys[0]]):
rospy.loginfo(f"Robot Moving Towards Safe Place POSE: {self.placesPoses[keys[0]][keys[1]]}")
return self.placesPoses[keys[0]][keys[1]]

else:
return self.placesPoses[keys[0]]["safe_place"]
rospy.loginfo("Invalid target")
return None

Expand Down
29 changes: 29 additions & 0 deletions ws/src/actions/scripts/roomGetterClient.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#! /usr/bin/env python3

import rospy
from geometry_msgs.msg import PointStamped
from frida_navigation_interfaces.srv import RoomGetter


def main():
rospy.init_node("room_getter_client")
rospy.loginfo("Room Getter client is ready")
rospy.wait_for_service('room_getter')
try:
room_getter = rospy.ServiceProxy('room_getter', RoomGetter)
goal = PointStamped()
x= -6.475536823272705
y= 4.268789291381836
z= 0.0057659149169921875
goal.point.x = x
goal.point.y = y
goal.point.z = 0
goal.header.frame_id = "map"
resp1 = room_getter(goal)
print(f"Room: {resp1.room}")
except rospy.ServiceException as e:
print("Service call failed: %s"%e)
rospy.spin()

if __name__ == "__main__":
main()
Loading