Skip to content

Commit 41a6f21

Browse files
committed
update docstring; add new robostack script
1 parent 368e604 commit 41a6f21

File tree

7 files changed

+204
-35
lines changed

7 files changed

+204
-35
lines changed

Host_Setup/RoboStack/robotstack.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# Install ROBOSTACK ROS-Noetic
22
[RoboStack](https://robostack.github.io/index.html) is a bundling of the Robot Operating System (ROS) by Open Robotics for Linux, Mac and Windows using the Conda package manager. Traditionaly, ROS is only available to Linux and does not work well with Conda.
33

4+
# Update: 2023.2.5
5+
RoboStack has released a new version of ROS Noetic. It uses a more recent version of Boost, which allows use to use newer version of Jax, PyTorch, and HPP-FCL. This means your algorithms will run (potentially) faster and more stable. If you want to try out, please follow the instructions below.
6+
```
7+
./ros_conda_install_unix_new.sh
8+
```
9+
It will create a new environment called ```ros_base2```. You can activate it by ```conda activate ros_base2```. Your old environment ```ros_base``` will still be there.
10+
411
## Mac OS and Linux
512
If you are using Mac OS or Linux, we provide you a simple script to automate the process. Simply open a terminal, then run
613

Host_Setup/RoboStack/ros_conda_install_unix.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ mamba --version
8989

9090
# make sure we are in base
9191
echo -e "${BLUE}Setup RoboStack Env${NC}"
92+
for i in $(seq ${CONDA_SHLVL}); do
93+
conda deactivate
94+
done
9295
conda activate base
9396

9497
mamba create -n ros_base ros-noetic-desktop python=3.9 -c robostack -c robostack-experimental \
@@ -103,8 +106,6 @@ mamba install compilers cmake pkg-config make ninja -c conda-forge --override-ch
103106

104107
mamba install catkin_tools -c conda-forge -c robostack -c robostack-experimental --yes
105108

106-
mamba install networkx shapely -c conda-forge --yes
107-
108109
# reload environment to activate required scripts before running anything
109110
# on Windows, please restart the Anaconda Prompt / Command Prompt!
110111
conda deactivate
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
#!/bin/bash
2+
3+
# define color
4+
RED='\033[0;31m'
5+
GREEN='\033[0;32m'
6+
BLUE='\033[0;34m'
7+
NC='\033[0m' # No Color
8+
9+
cur_dir=$(pwd)
10+
11+
OS=$(uname -s)
12+
ARCH=$(uname -m)
13+
14+
# Check if conda installed
15+
if test -z "$(which $CONDA_EXE)" ; then
16+
echo -e "${RED} Conda is not installed, install Mambaforge ${NC}"
17+
# Mac OS
18+
if [[ $OS == 'Darwin' ]]; then
19+
if [[ $ARCH == 'arm64' ]]; then
20+
echo -e "${GREEN} You are using Mac OS with Apple Silicon${NC}"
21+
curl -L https://github.com/conda-forge/miniforge/releases/latest/download/Mambaforge-MacOSX-arm64.sh > Mambaforge-Installer.sh
22+
elif [[ $ARCH == 'x86_64' ]]; then
23+
echo -e "${GREEN} You are using Mac OS with X86${NC}"
24+
curl -L https://github.com/conda-forge/miniforge/releases/latest/download/Mambaforge-MacOSX-x86_64.sh > Mambaforge-Installer.sh
25+
else
26+
echo -e "${RED} Unrecognized arch type, Mac OS with ${ARCH}${NC}"
27+
return 1 2>/dev/null
28+
exit 1
29+
fi
30+
31+
elif [[ $OS == "Linux" ]]; then
32+
# Linux
33+
if [[ $ARCH == 'aarch64' ]]; then
34+
echo -e "${GREEN}You are using Linux with aarch64${NC}"
35+
curl -L https://github.com/conda-forge/miniforge/releases/latest/download/Mambaforge-Linux-aarch64.sh > Mambaforge-Installer.sh
36+
elif [[ $ARCH == 'x86_64' ]]; then
37+
echo -e "${GREEN}You are using Linux with X86${NC}"
38+
curl -L https://github.com/conda-forge/miniforge/releases/latest/download/Mambaforge-Linux-x86_64.sh > Mambaforge-Installer.sh
39+
else
40+
echo -e "${RED} Unrecognized arch type, Linux with ${ARCH}${NC}"
41+
return 1 2>/dev/null
42+
exit 1
43+
fi
44+
45+
else
46+
echo -e "${RED} OS: ${OS} not supported ${NC}"
47+
exit 1
48+
fi
49+
50+
# Install Mambaforge
51+
chmod +x Mambaforge-Installer.sh
52+
./Mambaforge-Installer.sh -b -f
53+
54+
cd ~/mambaforge/bin
55+
./conda config --set auto_activate_base false
56+
./conda init --all
57+
./mamba init --all
58+
59+
# manually enable conda and mamba
60+
eval "$(./conda shell.bash hook)"
61+
cd ~/mambaforge/etc/profile.d/
62+
. "mamba.sh"
63+
64+
cd $cur_dir
65+
rm Mambaforge-Installer.sh
66+
67+
echo -e "${Green} Finish install Mambaforge${NC}"
68+
69+
else
70+
echo -e "${BLUE}Found Conda in $CONDA_EXE${NC}, install Mamba to base environment"
71+
eval "$($CONDA_EXE shell.bash hook)"
72+
conda activate base
73+
conda install mamba -c conda-forge --yes
74+
mamba init --all
75+
76+
# manually enable mamba
77+
cd $(conda info --base)/etc/profile.d/
78+
. "mamba.sh"
79+
fi
80+
81+
cd $cur_dir
82+
83+
echo -e "Current Conda is running on ${GREEN}$CONDA_EXE${NC}"
84+
85+
conda --version
86+
mamba --version
87+
88+
# make sure we are in base
89+
echo -e "${BLUE}Setup RoboStack Env${NC}"
90+
for i in $(seq ${CONDA_SHLVL}); do
91+
conda deactivate
92+
done
93+
conda activate base
94+
95+
mamba create -n ros_base2 ros-noetic-desktop python=3.9 \
96+
-c robostack-staging -c conda-forge \
97+
--no-channel-priority --override-channels --yes
98+
99+
100+
echo -e "${BLUE}Finish Settting up RoboStack Env${NC}"
101+
102+
conda activate ros_base2
103+
104+
mamba install compilers cmake pkg-config make ninja -c conda-forge --override-channels --yes
105+
106+
mamba install catkin_tools -c conda-forge -c robostack-staging --yes
107+
108+
109+
# reload environment to activate required scripts before running anything
110+
# on Windows, please restart the Anaconda Prompt / Command Prompt!
111+
conda deactivate
112+
conda activate ros_base2
113+
114+
# if you want to use rosdep, also do:
115+
mamba install rosdep -c conda-forge -c robostack-staging --yes
116+
rosdep init # note: do not use sudo!
117+
rosdep update
118+
119+
echo -e "${BLUE}Install Dependency${NC}"
120+
121+
mamba install numpy scipy matplotlib jupyter notebook networkx shapely -c conda-forge --yes
122+
123+
echo -e "${BLUE}Install PySpline${NC}"
124+
# Mac OS
125+
if [[ $OS == 'Darwin' ]]; then
126+
if [[ $ARCH == 'arm64' ]]; then
127+
echo -e "${GREEN} You are using Mac OS with Apple Silicon${NC}"
128+
# this avoid segfault when importing hppfcl
129+
# mamba install eigenpy=2.7.10 --yes -c conda-forge
130+
pip install osx_arm/pyspline-1.5.2-py3-none-any.whl
131+
elif [[ $ARCH == 'x86_64' ]]; then
132+
echo -e "${GREEN} You are using Mac OS with X86${NC}"
133+
pip install osx/pyspline-1.5.2-py3-none-any.whl
134+
else
135+
echo -e "${RED} Unrecognized arch type, Mac OS with ${ARCH}. Cannot Install PySpline, Please compile from source${NC}"
136+
exit 1
137+
fi
138+
139+
elif [[ $OS == "Linux" ]]; then
140+
# Linux
141+
if [[ $ARCH == 'aarch64' ]]; then
142+
echo -e "${GREEN}You are using Linux with aarch64${NC}"
143+
pip install linux_aarch64/pyspline-1.5.2-py3-none-linux_aarch64.whl
144+
elif [[ $ARCH == 'x86_64' ]]; then
145+
echo -e "${GREEN}You are using Linux with X86${NC}"
146+
pip install linux/pyspline-1.5.2-py3-none-linux_x86_64.whl
147+
else
148+
echo -e "${RED} Unrecognized arch type, Linux with ${ARCH}. Cannot Install PySpline, Please compile from source${NC}"
149+
return 1 2>/dev/null
150+
exit 1
151+
fi
152+
else
153+
echo -e "${RED} OS: ${OS} not supported ${NC}"
154+
return 1 2>/dev/null
155+
exit 1
156+
fi
157+
158+
echo -e "${BLUE}Install Jax${NC}"
159+
# Instal Jax https://github.com/google/jax#conda-installation
160+
mamba install jax=0.4.2 'jaxlib=0.4.2=cpu*' -c conda-forge --yes
161+
162+
echo -e "${BLUE}Install Hpp-FCL${NC}"
163+
164+
mamba install -c conda-forge hpp-fcl --yes
165+
166+
echo -e "${Green}Finished! Reopen a new terminal to see if everything works. ${NC}"
740 KB
Loading

ROS_Core/src/Labs/Lab0/scripts/controller/utils/realtime_buffer.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,3 @@ def reset(self):
4646
Reset the buffer to None
4747
'''
4848
self.writeFromNonRT(None)
49-
self.new_data_available = False

ROS_Core/src/Labs/Lab0/scripts/controller/utils/ros_utility.py

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from geometry_msgs.msg import PoseStamped
33
from tf.transformations import quaternion_from_euler
44

5-
def get_ros_param(param_name, default):
5+
def get_ros_param(param_name: str, default):
66
'''
77
Read a parameter from the ROS parameter server. If the parameter does not exist, return the default value.
88
Args:
@@ -27,25 +27,3 @@ def get_ros_param(param_name, default):
2727
rospy.logwarn("Parameter '%s' not found, using default: %s", param_name, default)
2828
return default
2929

30-
31-
def state_to_pose_stamped(state, t, frame_id='map'):
32-
'''
33-
Convert a State Vector object to a PoseStamped message
34-
state: [x,y,v,yaw,delta]
35-
t: float time in seconds
36-
frame_id: string
37-
'''
38-
39-
pose = PoseStamped()
40-
pose.header.frame_id = frame_id
41-
pose.header.stamp =rospy.Time.from_sec(t)
42-
pose.pose.position.x = state[0]
43-
pose.pose.position.y = state[1]
44-
pose.pose.position.z = 0.0
45-
46-
q = quaternion_from_euler(0.0, 0.0, state[3])
47-
pose.pose.orientation.x = q[0]
48-
pose.pose.orientation.y = q[1]
49-
pose.pose.orientation.z = q[2]
50-
pose.pose.orientation.w = q[3]
51-
return pose

ROS_Core/src/Labs/Lab0/scripts/controller/utils/state_2d.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
import numpy as np
22
from scipy.spatial.transform import Rotation as R
33
from tf.transformations import euler_from_quaternion
4+
from nav_msgs.msg import Odometry
45

56
class State2D():
67
'''
78
2D vehicle state
89
'''
9-
def __init__(self, odom_msg = None) -> None:
10+
def __init__(self, odom_msg: Odometry = None) -> None:
11+
'''
12+
Constructor of the State2D class
13+
Parameters:
14+
odom_msg: nav_msgs.msg.Odometry,
15+
odometry message to initialize the state
16+
'''
1017

1118
self.t = 0 # time stamp
1219
self.x = 0 #x position
@@ -25,9 +32,12 @@ def __init__(self, odom_msg = None) -> None:
2532
if odom_msg is not None:
2633
self.from_odom_msg(odom_msg)
2734

28-
def from_odom_msg(self, odom_msg):
35+
def from_odom_msg(self, odom_msg: Odometry) -> None:
2936
'''
3037
Construct state from odometry message
38+
Parameters:
39+
odom_msg: nav_msgs.msg.Odometry,
40+
odometry message to initialize the state
3141
'''
3242
self.t = odom_msg.header.stamp.to_sec()
3343
self.x = odom_msg.pose.pose.position.x
@@ -46,11 +56,12 @@ def from_odom_msg(self, odom_msg):
4656

4757
self.initialized = True
4858

49-
def from_SE3(self, pose_base_to_world, twist_base, t):
59+
def from_SE3(self, pose_base_to_world: np.ndarray, twist_base: np.ndarray, t: float) -> None:
5060
'''
5161
Construct state from SE3 pose and twist
52-
pose_base_to_world: SE3 pose from world to base
53-
twist_base: twist of the base
62+
pose_base_to_world: np array, SE3 pose from world to base
63+
twist_base: np array, twist of the base
64+
t: float, time stamp
5465
'''
5566
self.t = t
5667
self.x = pose_base_to_world[0,3]
@@ -69,9 +80,16 @@ def from_SE3(self, pose_base_to_world, twist_base, t):
6980

7081
self.initialized = True
7182

72-
def from_state(self, x, y, v_long, psi, w, t):
83+
def from_state(self, x: float, y: float, v_long: float, psi: float, w: float, t: float) -> None:
7384
'''
7485
Construct state from a state object
86+
Parameters:
87+
x: float, x position
88+
y: float, y position
89+
v_long: float, longitudinal velocity
90+
psi: float, pose angle around z axis
91+
w: float, angular velocity around z axis
92+
t: float, time stamp
7593
'''
7694
self.t = t
7795
self.x = x
@@ -88,13 +106,13 @@ def from_state(self, x, y, v_long, psi, w, t):
88106

89107
self.initialized = True
90108

91-
def state_vector(self, delta):
109+
def state_vector(self, delta) -> np.ndarray:
92110
'''
93111
Return the state vector
94112
'''
95113
return np.array([self.x, self.y, self.v_long, self.psi, delta])
96114

97-
def transformation_matrix(self):
115+
def transformation_matrix(self) -> np.ndarray:
98116
'''
99117
Retrun Translation matrix from world to base
100118
'''
@@ -103,7 +121,7 @@ def transformation_matrix(self):
103121
[0, 0, 1]])
104122
return T
105123

106-
def __str__(self):
124+
def __str__(self) -> str:
107125
return f"State at [{np.round(self.x,3)}, {np.round(self.y,3)}] "+ \
108126
f"with pose {np.round(np.rad2deg(self.psi),3)} deg\n" + \
109127
f"Speed: {np.round(self.v,3)} pointing to {np.round(np.rad2deg(self.v_dir),3)} deg; Omega: {np.round(self.w,3)} \n"+ \

0 commit comments

Comments
 (0)