-
Notifications
You must be signed in to change notification settings - Fork 2
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
Integrate ToF Sensor, Implement emergency Brake, and repellent field #4
base: wifi-with-cytron
Are you sure you want to change the base?
Changes from 19 commits
a507572
358cc26
4bade8e
a61cc99
fe9a3e8
d2a9d44
1d44b5a
d8f340b
5c86e50
3a75ac3
a182f4e
5bf5994
adbe730
942cc71
e5efc7a
e876461
9bdb4ad
197b61d
5c10155
748cf03
ada812e
31155ec
7e9d54b
73ff751
9558472
7d9e460
3960ee3
238624a
755654c
a4fb1c3
fe9119f
aedd093
28c50d2
61e36d8
af7ae5b
84af085
40b25f2
bd32c30
051e7a5
6406555
3da675c
5be0e12
0110972
2adaacc
5e99a2d
88a9f7f
f15a962
3519c60
e41d699
d62ac43
ff45f46
d3d6ab1
5b666d9
efa9bc2
f7e9df5
06e6c31
d0386da
679b873
b6935e6
d4f7255
0fad87f
eabad4e
8ada88f
638f887
1b0ef7d
398ef70
a5ee64f
1f7ddbf
d9af7dd
7e23a16
6f17f5a
904dfd2
b6aa824
6876bcd
4d6cadd
2efcda0
d0f5537
9d725d8
fdd0ca6
56af55b
b62220a
6ed6c3a
ce256c3
711cf49
ff433c3
5875bcf
5dd50b4
697b6c7
61ad4b7
37db21b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,115 @@ | ||
# ToF Setup | ||
|
||
documentation can be accsessed here : https://devanthro.atlassian.net/wiki/spaces/WS2223/pages/2747269188/AN+Software | ||
## Variables : | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. markdown is used incorrectly, code is not highlighted and headlines are not used correctly |
||
MAC ADDRESS ToF 1 : 3C:FB:96:DC:59:7E | ||
MAC ADDRESS ToF 2 : 3C:FB:96:DC:59:7F | ||
|
||
ROS_MASTER_URI=http://192.168.0.104:11311 | ||
|
||
For this documentation we use this Router Configuration : | ||
|
||
|
||
TOF1 | ||
MAC ADDRESS: 3C:FB:96:DC:59:7E | ||
IP: 192.168.0.122 | ||
|
||
TOF2 | ||
MAC ADDRESS: 3C:FB:96:DC:59:7F | ||
IP: 192.168.0.123 | ||
|
||
MASTER | ||
IP : 192.168.0.124 | ||
|
||
## Setup TOF 1 | ||
|
||
to setup tof1 do these command : | ||
|
||
cd etc | ||
nano rc.local | ||
|
||
and then add rc.local with these commands: | ||
|
||
#stops royale viewer entity | ||
systemctl stop royaleviewer | ||
source /opt/ros/melodic/setup.sh | ||
|
||
# if you use other ip for ros master then do “export ROS_MASTER_URI=http://{ROS_MASTER_IP}:11311” | ||
export ROS_MASTER_URI=http://192.168.0.124:11311 | ||
|
||
# if you use other ip for ToF2 then do “export ROS_HOSTNAME={TOF2_IP}” | ||
export ROS_HOSTNAME=192.168.0.122 | ||
roslaunch royale_ros_sample camera_driver.launch node_name:=”tof1” | ||
|
||
exit 0 | ||
|
||
Reset the ToF sensor then ToF should publish data to /tof1/... | ||
|
||
## Setup TOF 2 | ||
|
||
to setup tof2 do these command : | ||
|
||
cd etc | ||
nano rc.local | ||
|
||
and then add rc.local with these commands: | ||
|
||
#stops royale viewer entity | ||
systemctl stop royaleviewer | ||
source /opt/ros/melodic/setup.sh | ||
|
||
#if you use other ip for ros master then do “export ROS_MASTER_URI=http://{ROS_MASTER_IP}:11311” | ||
export ROS_MASTER_URI=http://192.168.0.124:11311 | ||
|
||
#if you use other ip for ToF2 then do “export ROS_HOSTNAME={TOF2_IP}” | ||
export ROS_HOSTNAME=192.168.0.123 | ||
roslaunch royale_ros_sample camera_driver.launch node_name:=”tof2” | ||
|
||
exit 0 | ||
|
||
Reset the ToF sensor then ToF should publish data to /tof2/... | ||
|
||
## MASTER | ||
|
||
Do these command on the ROS master device: | ||
|
||
#if you use other ip for ros master then do “export ROS_HOSTNAME={ROS_MASTER_IP}” | ||
export ROS_HOSTNAME=192.168.0.124 | ||
|
||
#if you use other ip for ros master then do “export ROS_MASTER_URI=http://{ROS_MASTER_IP}:11311” | ||
export ROS_MASTER_URI=http://192.168.0.124:11311 | ||
roscore | ||
|
||
these code start the ROS MASTER | ||
|
||
|
||
|
||
on a new terminal : | ||
|
||
git clone -b an_ToF_emergencyBrake https://github.com/ronggurmahendra/esp-wheelchair.git | ||
cd esp-wheelchair | ||
python3 software/tof_potential_field.py | ||
|
||
on a new terminal | ||
|
||
cd esp-wheelchair | ||
python3 software/twist_to_pwm.py | ||
|
||
on a new terminal | ||
|
||
rosrun teleop_twist_keyboard teleop_twist_keyboard.py | ||
|
||
SIMULATION | ||
|
||
to run the simulation | ||
|
||
#asuming you already done the http://wiki.ros.org/catkin/Tutorials/create_a_workspace if not then do so | ||
cd catkin_ws/src | ||
git clone https://github.com/ronggurmahendra/Robody_Sim | ||
cd .. | ||
catkin_make | ||
source devel/setup.sh | ||
|
||
#run gazebo world of your choice | ||
roslaunch gazebo_ros shapes_world.launch |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#export ROS_HOSTNAME=192.168.0.124 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this script belongs to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
# if you use other ip for ros master then do “export ROS_MASTER_URI=http://{ROS_MASTER_IP}:11311” | ||
#export ROS_MASTER_URI=http://192.168.0.124:11311 | ||
roscore & | ||
python3 software/twist_to_pwm.py & | ||
python3 software/tof.py & | ||
rosrun teleop_twist_keyboard teleop_twist_keyboard.py |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class ManualMode: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. docstrings for classes are missing, please add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
def __init__(self): | ||
return | ||
|
||
def control(self, inputLinear, inputAngular): | ||
return inputLinear,inputAngular |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class RepelentMode: | ||
def __init__(self): | ||
return | ||
|
||
def control(self, inputLinear, inputAngular, minDistFront, minDistBack): | ||
if inputLinear >= 0: | ||
outputLinear = minDistFront | ||
elif inputLinear < 0: | ||
outputLinear = -1*minDistBack | ||
|
||
return outputLinear,inputAngular |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import unittest | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. docstrings missing, wrong location of the script |
||
import rospy | ||
|
||
from std_msgs.msg import Float64 | ||
from sensor_msgs.msg import PointCloud2 | ||
from geometry_msgs.msg import Twist | ||
import pcl | ||
import ros_numpy | ||
import numpy as np | ||
import pcl.pcl_visualization | ||
import sys | ||
sys.path.insert(1, '../esp-wheelchair/software') | ||
|
||
from manual import * | ||
from repelent_field import * | ||
|
||
class Assisted_Navigation_Test(unittest.TestCase): | ||
def test_Repelent_Field(self): | ||
repelentMode = RepelentMode() | ||
inputLinear = 10 | ||
inputAngular = 11 | ||
minDistFront = 0.01 | ||
minDistBack = 10 | ||
|
||
outputLiner,outputAngular = repelentMode.control(inputLinear,inputAngular, minDistFront, minDistBack) | ||
# test | ||
# assert(outputLiner == 0 and outputAngular == outputAngular ) | ||
self.assertEqual((outputLiner, outputAngular), (0.01, inputAngular)) | ||
repelentMode = RepelentMode() | ||
inputLinear = -1 | ||
inputAngular = 2 | ||
minDistFront = 2 | ||
minDistBack = 0.1 | ||
|
||
outputLiner,outputAngular = repelentMode.control(inputLinear,inputAngular, minDistFront, minDistBack) | ||
# test | ||
self.assertEqual((outputLiner, outputAngular), (-0.1, inputAngular)) | ||
|
||
|
||
def test_Manual_Mode(self): | ||
manualMode = ManualMode() | ||
inputLinear = 10 | ||
inputAngular = 1 | ||
self.assertEqual(manualMode.control(inputLinear,inputAngular), (inputLinear, inputAngular)) | ||
|
||
inputLinear = -10 | ||
inputAngular = 1 | ||
self.assertEqual(manualMode.control(inputLinear,inputAngular), (inputLinear, inputAngular)) | ||
|
||
inputLinear = 0 | ||
inputAngular = -1 | ||
self.assertEqual(manualMode.control(inputLinear,inputAngular), (inputLinear, inputAngular)) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
# Usage: | ||
|
||
# cd esp-wheelchair | ||
# python3 software/tof.py | ||
|
||
import rospy | ||
from std_msgs.msg import Float64 | ||
from sensor_msgs.msg import PointCloud2 | ||
from geometry_msgs.msg import Twist | ||
import pcl | ||
import ros_numpy | ||
import numpy as np | ||
import pcl.pcl_visualization | ||
from manual import * | ||
from repelent_field import * | ||
useVisual = False | ||
|
||
emergencyStopThreshold = 0.1 | ||
if(useVisual): | ||
viewer_front = pcl.pcl_visualization.PCLVisualizering() | ||
viewer_back = pcl.pcl_visualization.PCLVisualizering() | ||
minDist_front = 9999 | ||
minDist_back = 9999 | ||
inputLinear = None | ||
inputAngular = None | ||
manualMode = ManualMode() | ||
repelentMode = RepelentMode() | ||
|
||
def getNearestDistance(points): | ||
min = 9999 | ||
for i in range(len(points)): | ||
if(min > points[i][2]): | ||
min = points[i][2] | ||
return min | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use numpy methods to find There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
def point_cloud_front_callback(msg): | ||
# change from pointcloud2 to numpy | ||
pc = ros_numpy.numpify(msg) | ||
height = pc.shape[0] | ||
width = pc.shape[1] | ||
np_points = np.zeros((height * width, 3), dtype=np.float32) | ||
np_points[:, 0] = np.resize(pc['x'], height * width) | ||
np_points[:, 1] = np.resize(pc['y'], height * width) | ||
np_points[:, 2] = np.resize(pc['z'], height * width) | ||
if(useVisual): | ||
p = pcl.PointCloud(np.array(np_points, dtype=np.float32)) | ||
viewer_front.AddPointCloud(p, b'scene_cloud_front', 0) | ||
viewer_front.SpinOnce() | ||
viewer_front.RemovePointCloud( b'scene_cloud_front', 0) | ||
# find the nearest point | ||
global minDist_front | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not global variables are allowed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
minDist_front = getNearestDistance(np_points) | ||
|
||
def point_cloud_back_callback(msg): | ||
# change from pointcloud2 to numpy | ||
pc = ros_numpy.numpify(msg) | ||
height = pc.shape[0] | ||
width = pc.shape[1] | ||
np_points = np.zeros((height * width, 3), dtype=np.float32) | ||
np_points[:, 0] = np.resize(pc['x'], height * width) | ||
np_points[:, 1] = np.resize(pc['y'], height * width) | ||
np_points[:, 2] = np.resize(pc['z'], height * width) | ||
if(useVisual): | ||
p = pcl.PointCloud(np.array(np_points, dtype=np.float32)) | ||
viewer_back.AddPointCloud(p, b'scene_cloud_back', 0) | ||
viewer_back.SpinOnce() | ||
viewer_back.RemovePointCloud( b'scene_cloud_back', 0) | ||
# find the nearest point | ||
global minDist_back | ||
minDist_back = getNearestDistance(np_points) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. copy paste antipattern, identical to point_cloud_front_callback, rewrite to 1 function that can be used for front and back There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
def user_input_callback(msg): | ||
inputLinear = msg.linear.x | ||
inputAngular = msg.angular.z | ||
|
||
# manual mode | ||
outputLinear,outputAngular = manualMode.control(inputLinear,inputAngular) | ||
|
||
if(minDist_front < emergencyStopThreshold and inputLinear > 0): # asume that this is the front ToF | ||
print ("ABOUT TO COLLIDE FRONT EMERGENCY BRAKE") | ||
outputLinear = 0 | ||
elif (minDist_back < emergencyStopThreshold and inputLinear < 0): # asume that this is the back ToF | ||
print ("ABOUT TO COLLIDE BACK EMERGENCY BRAKE") | ||
outputLinear = 0 | ||
|
||
# reppelent field | ||
# outputLinear,outputAngular = repelentMode.control(inputLinear,inputAngular,minDist_front,minDist_back) | ||
|
||
twist = Twist() | ||
twist.linear.x = outputLinear | ||
twist.angular.z = outputAngular | ||
assisted_navigation_pub.publish(twist) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. comments missing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
rospy.init_node('assisted_Navigation') | ||
|
||
assisted_navigation_pub = rospy.Publisher('/roboy/pinky/middleware/espchair/wheels/assisted_navigation', Twist, queue_size=10) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wrong topic name and message. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
user_input_sub = rospy.Subscriber('/cmd_vel', Twist, user_input_callback) | ||
# point_cloud_sub = rospy.Subscriber('/royale_camera_driver/point_cloud', PointCloud2, point_cloud_callback) | ||
|
||
point_cloud_front_sub = rospy.Subscriber('/tof1_driver/point_cloud', PointCloud2, point_cloud_front_callback) | ||
point_cloud__back_sub = rospy.Subscriber('/tof2_driver/point_cloud', PointCloud2, point_cloud_back_callback) | ||
|
||
print("publishing to /roboy/pinky/middleware/espchair/wheels/assisted_navigation. Spinning...") | ||
rospy.spin() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
# Usage: | ||
|
||
|
||
# rosrun rosserial_python serial_node.py tcp | ||
# plugin wheelchair power | ||
|
||
# cd esp-wheelchair | ||
# python software/twist_to_pwm.py | ||
# python3 software/twist_to_pwm.py | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this script is not used. why are there edits to it? |
||
|
||
# start ROS joystick node - atk3 is for logitech joystick | ||
# roslaunch teleop_twist_joy teleop.launch joy_config:=atk3 | ||
|
@@ -38,25 +37,22 @@ def mapPwm(x, out_min, out_max): | |
|
||
|
||
def cb(msg): | ||
if not rospy.get_param('wheelchair_emergency_stopped'): | ||
rospy.loginfo_throttle(5, "Publishing pwm..") | ||
x = max(min(msg.linear.x, 1.0), -1.0) | ||
z = max(min(msg.angular.z, 1.0), -1.0) | ||
|
||
l = (msg.linear.x - msg.angular.z) / 2.0 | ||
r = (msg.linear.x + msg.angular.z) / 2.0 | ||
|
||
lPwm = mapPwm(abs(l), PWM_MIN, PWMRANGE) | ||
rPwm = mapPwm(abs(r), PWM_MIN, PWMRANGE) | ||
rospy.loginfo_throttle(5, "Publishing pwm..") | ||
x = max(min(msg.linear.x, 1.0), -1.0) | ||
z = max(min(msg.angular.z, 1.0), -1.0) | ||
|
||
pub_l.publish(sign(l)*lPwm) | ||
pub_r.publish(sign(r)*rPwm) | ||
else: | ||
rospy.logwarn_throttle(1, "Emergency stop active. Ignoring cmd_vel") | ||
l = (msg.linear.x - msg.angular.z) / 2.0 | ||
r = (msg.linear.x + msg.angular.z) / 2.0 | ||
|
||
lPwm = mapPwm(abs(l), PWM_MIN, PWMRANGE) | ||
rPwm = mapPwm(abs(r), PWM_MIN, PWMRANGE) | ||
print(" left : ", sign(l)*lPwm, ", right : ",sign(r)*rPwm) | ||
pub_l.publish(sign(l)*lPwm) | ||
pub_r.publish(sign(r)*rPwm) | ||
|
||
|
||
sub = rospy.Subscriber("/cmd_vel", Twist, cb) | ||
InputTopic = "/roboy/pinky/middleware/espchair/wheels/assisted_navigation" | ||
sub = rospy.Subscriber(InputTopic, Twist, cb) | ||
|
||
rospy.loginfo("Subscribed to /cmd_vel, will publish wheelchair PWM. Spinning...") | ||
rospy.spin() | ||
rospy.loginfo("Subscribed to " + InputTopic + ", will publish wheelchair PWM. Spinning...") | ||
rospy.spin() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
everything related to ToF sensor setup belongs to your team's documentation page and not this repository