# GPSD
# setting gpsd
## check whehter device alive
```
stty -F /dev/ttyXXX ispeed 4800 && cat </dev/ttyXXX
```
ttyXXX usually is /dev/ttyUSB0 or /dev/ttyS0
using this commoand to check which /dev/ttyUSB is used
```
ls -l /dev/ttyUSB*
```
## install
```
sudo apt-get update
sudo apt install gpsd gpsd-clients
sudo apt-get install libgps-dev
```
## gpsd usage
### start gpsd
```
sudo systemctl start gpsd
```
### stop gbsd (if gpsd start failed, we need to stop and restart gpsd)
```
systemctl stop gpsd
systemctl stop gpsd.socket
```
### check gpsd status
```
sudo systemctl status gpsd
```
### setting priviledge to make non-root could use
```
sudo usermod -a -G dialout $USER
```
### setting configuration
in /etc/default/gpsd
```
# Devices gpsd should collect to at boot time.
# They need to be read/writeable, either by user gpsd or the group dialout.
DEVICES="/dev/ttyUSB0"
# Other options you want to pass to gpsd
GPSD_OPTIONS="-F /var/run/gpsd.socket"
# Automatically hot add/remove USB GPS devices via gpsdctl
USBAUTO="true"
```
in /lib/systemd/system/gpsd.service
```
[Unit]
Description=GPS (Global Positioning System) Daemon
Requires=gpsd.socket
# Needed with chrony SOCK refclock
After=chronyd.service
[Service]
Type=forking
EnvironmentFile=-/etc/default/gpsd
ExecStart=/usr/sbin/gpsd $GPSD_OPTIONS $OPTIONS $DEVICES
[Install]
WantedBy=multi-user.target
Also=gpsd.socket
```
restart gpsd after setting
### testing
```
cgps
```
```
gpsmon
```
## convert gpsd message to autoware
[gps_umd](https://github.com/swri-robotics/gps_umd.git)
after building and source, call
```
ros2 launch gpsd_client gpsd_client-launch.py
```
## rewrite autoware gnss.xml
```
<launch>
<arg name="launch_driver" default="true"/>
<!--<arg name="gnss_receiver" default="ublox" description="ublox(default) or septentrio"/>-->
<arg name="gnss_receiver" default="garmin" description="ublox(default), septentrio or <YOUR-GNSS-SENSOR>"/>
<group>
<push-ros-namespace namespace="gnss"/>
<!-- Switch topic name -->
<let name="navsatfix_topic_name" value="ublox/nav_sat_fix" if="$(eval "'$(var gnss_receiver)'=='ublox'")"/>
<let name="navsatfix_topic_name" value="septentrio/nav_sat_fix" if="$(eval "'$(var gnss_receiver)'=='septentrio'")"/>
<let name="navsatfix_topic_name" value="garmin/fix" if="$(eval "'$(var gnss_receiver)'=='garmin'")/">
<let name="orientation_topic_name" value="/autoware_orientation"/>
<!-- Ublox Driver -->
<group if="$(eval "'$(var gnss_receiver)'=='ublox'")">
<node pkg="ublox_gps" name="ublox" exec="ublox_gps_node" if="$(var launch_driver)" respawn="true" respawn_delay="1.0">
<remap from="~/fix" to="~/nav_sat_fix"/>
<param from="$(find-pkg-share ublox_gps)/c94_f9p_rover.yaml"/>
</node>
</group>
<!-- Septentrio GNSS Driver -->
<group if="$(eval "'$(var launch_driver)' and '$(var gnss_receiver)'=='septentrio'")">
<include file="$(find-pkg-share septentrio_gnss_driver)/launch/mosaic_x5_rover.launch.xml"/>
</group>
<!-- Garmin GNSS Driver -->
<group if="$(eval "'$(var launch_driver)' and '$(var gnss_receiver)'=='garmin'")">
<include file="$(find-pkg-share gpsd_client)/launch/gpsd_client-launch.py"/>
</group>
<!-- NavSatFix to MGRS Pose -->
<include file="$(find-pkg-share gnss_poser)/launch/gnss_poser.launch.xml">
<arg name="input_topic_fix" value="$(var navsatfix_topic_name)"/>
<arg name="input_topic_orientation" value="$(var orientation_topic_name)"/>
<arg name="output_topic_gnss_pose" value="pose"/>
<arg name="output_topic_gnss_pose_cov" value="pose_with_covariance"/>
<arg name="output_topic_gnss_fixed" value="fixed"/>
<arg name="use_gnss_ins_orientation" value="true"/>
<arg name="gnss_frame" value="gnss_link"/>
</include>
</group>
</launch>
```
## rewrite gpsd_client-launch.py => remap
```
"""Launch a talker and a listener in a component container."""
import os
import launch
from launch_ros.actions import ComposableNodeContainer
from launch_ros.descriptions import ComposableNode
import ament_index_python.packages
import yaml
gpsd_client_share_dir = ament_index_python.packages.get_package_share_directory('gpsd_client')
gpsd_client_params_file = os.path.join(gpsd_client_share_dir, 'config', 'gpsd_client.yaml')
with open(gpsd_client_params_file, 'r') as f:
gpsd_client_params = yaml.safe_load(f)['gpsd_client']['ros__parameters']
def generate_launch_description():
"""Generate launch description with multiple components."""
container = ComposableNodeContainer(
name='fix_and_odometry_container',
namespace='',
package='rclcpp_components',
executable='component_container',
composable_node_descriptions=[
ComposableNode(
package='gpsd_client',
plugin='gpsd_client::GPSDClientComponent',
name='gpsd_client',
parameters=[gpsd_client_params],
remappings=[('fix','garmin/fix')]
),
ComposableNode(
package='gps_tools',
plugin='gps_tools::UtmOdometryComponent',
name='utm_gpsfix_to_odometry_node')
],
output='screen',
)
return launch.LaunchDescription([container,
launch.actions.RegisterEventHandler(
event_handler=launch.event_handlers.OnProcessExit(
target_action=container,
on_exit=[launch.actions.EmitEvent(
event=launch.events.Shutdown())]
))
])
```
## reference
[install](https://gpsd.gitlab.io/gpsd/installation.html)