auviitkgp / kraken_3.0

Source code of Team AUV, IIT Kharagpur
http://auviitkgp.github.io
BSD 3-Clause Clear License
39 stars 58 forks source link

[ros-indigo] [14.04] Keyboard control: Code working, Bash script not working. #40

Closed icyflame closed 9 years ago

icyflame commented 9 years ago

I added all the code that is required for the keyboard control module, as in the current master tree.

Then, I copied the script runKraken_keyboard.sh from the master tree. (find the file here)

I am using zsh as my default shell. I get the following error when I run ./Scripts/runKraken_keyboard.sh:

➜  kraken_3.0 git:(indigo-devel) ✗ ./Scripts/runKraken_keyboard.sh 
./Scripts/runKraken_keyboard.sh: 9: ./Scripts/runKraken_keyboard.sh: roscd: not found
./Scripts/runKraken_keyboard.sh: 10: cd: can't cd to kraken_3.0/Scripts/
./Scripts/runKraken_keyboard.sh: 11: ./Scripts/runKraken_keyboard.sh: ./kraken_visualization_launcher: not found
./Scripts/runKraken_keyboard.sh: 19: ./Scripts/runKraken_keyboard.sh: roscd: not found
./Scripts/runKraken_keyboard.sh: 20: cd: can't cd to kraken_3.0/simulator_stack/joystick_control/src/
python: can't open file 'main.py': [Errno 2] No such file or directory

The interesting (and the thing I just can't figure out) is that it all works fine when I run the commands in the script one by one. i.e.

➜  kraken_3.0 git:(indigo-devel) ✗ ./Scripts/kraken_visualization_launcher &
[1] 20896
➜  kraken_3.0 git:(indigo-devel) ✗ Starting UWSim...
Loading SimulatedDevices plugin: 'ForceSensor_Factory'
Loading SimulatedDevices plugin: 'SimDev_Echo_Factory'
processROSInterface:: unexpected child: visualize
. Setting localized world: 0.00021s
Loading URDF robot... 
· package://kraken_visualization/kraken/robot/new_model_kraken.3ds: 0.025633s
· : 1e-06s
· : 1e-06s
· : 1e-06s
· : 1e-06s
· : 1e-06s
· : 1e-06s
· : 1e-06s
· : 1e-06s
· : 1e-06s
· : 1e-06s
· : 1e-06s
· Linking links...Robot successfully loaded. Total time: 0.010515s
0.036292s
Loading URDF robot... 
· package://kraken_visualization/kraken/terrain/pool.osg: 0.013931s
· package://kraken_visualization/kraken/objects/gate_obstacle.osg: 0.017827s
· package://kraken_visualization/kraken/objects/buoy_blue.osg: 0.013402s
· package://kraken_visualization/kraken/objects/buoy_green.osg: 0.013979s
· package://kraken_visualization/kraken/objects/buoy_red.osg: 0.013215s
· package://kraken_visualization/kraken/objects/bins.osg: 0.014361s
· package://kraken_visualization/kraken/objects/marker.osg: 0.011685s
· package://kraken_visualization/kraken/objects/marker.osg: 0.011733s
· package://kraken_visualization/kraken/objects/marker.osg: 0.012311s
· package://kraken_visualization/kraken/objects/marker.osg: 0.011685s
· package://kraken_visualization/kraken/objects/shooter.osg: 0.016706s
· Linking links...Robot successfully loaded. Total time: 0.01213s
0.163365s
[ INFO] [1418747219.275247232]: ROSOdomToPAT subscriber on topic /kraken/simulator/dataNavigator
[ INFO] [1418747219.275396047]: ArmToROSJointState publisher on topic /kraken/simulator/joint_state
[ INFO] [1418747219.275604584]: ROSJointStateToArm subscriber on topic /kraken/simulator/joint_state_command
[ INFO] [1418747219.275849858]: VirtualCameraToROSImage publisher on topic /kraken/front_camera_info
[ INFO] [1418747219.305694880]: VirtualCameraToROSImage publisher on topic /kraken/bottom_camera_info
[ INFO] [1418747219.330693642]: Imu publisher on topic /kraken/simulator/imu
[ INFO] [1418747219.330979466]: ROSTwistToPAT subscriber on topic /kraken/simulator/twist
[ INFO] [1418747219.331109929]: PressureSensor publisher on topic /kraken/simulator/depth
[ INFO] [1418747219.331272760]: DVLSensor publisher on topic /kraken/simulator/dvl
[ INFO] [1418747219.331468791]: ROSPoseToPAT subscriber on topic /kraken/simulator/pose

➜  kraken_3.0 git:(indigo-devel) ✗ rosrun simulator_physics_model start_auv_model /kraken/physics_model/pose:=/kraken/simulator/pose &
[2] 21134
➜  kraken_3.0 git:(indigo-devel) ✗ rosrun joystick_control keyboard_control &
[3] 21247
➜  kraken_3.0 git:(indigo-devel) ✗ python simulator_stack/joystick_control/src/main.py 
...
➜  kraken_3.0 git:(indigo-devel) ✗ 

And everything works as expected.

(I have tried to run the script from bash too, but that doesn't work either.)

Please help me figure this out. All of my code has been pushed to the indigo-devel branch at my fork.

icyflame commented 9 years ago

Fixed by adding the following code to the top of the runKraken_keyboard.sh script.

#!/bin /bash
WS=$ROS_WORKSPACE 
source /opt/ros/indigo/setup.bash
export ROS_WORKSPACE=$WS
export ROS_PACKAGE_PATH=$ROS_WORKSPACE:$ROS_PACKAGE_PATH
nevalsar commented 9 years ago

While this certainly works, the following approach is recommended to make scripts portable across different UNIX systems.

#!/usr/bin/env bash

Refer this link for more details.

icyflame commented 9 years ago

Edited the runKraken_keyboard.sh script accordingly. See https://github.com/iit-kgp-auv-team/kraken_3.0/commit/f5df94bc83018e06806dd5206cf1e3f2c30f3380