Skip to content

Commit 2ab227e

Browse files
committed
migrate the group from gitlab to github"
;
1 parent 8ee613c commit 2ab227e

File tree

3,166 files changed

+1444396
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

3,166 files changed

+1444396
-0
lines changed

.DS_Store

8 KB
Binary file not shown.

arduino_comm/.DS_Store

6 KB
Binary file not shown.

arduino_comm/.gitignore

+160
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
share/python-wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
MANIFEST
28+
29+
# PyInstaller
30+
# Usually these files are written by a python script from a template
31+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32+
*.manifest
33+
*.spec
34+
35+
# Installer logs
36+
pip-log.txt
37+
pip-delete-this-directory.txt
38+
39+
# Unit test / coverage reports
40+
htmlcov/
41+
.tox/
42+
.nox/
43+
.coverage
44+
.coverage.*
45+
.cache
46+
nosetests.xml
47+
coverage.xml
48+
*.cover
49+
*.py,cover
50+
.hypothesis/
51+
.pytest_cache/
52+
cover/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
.pybuilder/
76+
target/
77+
78+
# Jupyter Notebook
79+
.ipynb_checkpoints
80+
81+
# IPython
82+
profile_default/
83+
ipython_config.py
84+
85+
# pyenv
86+
# For a library or package, you might want to ignore these files since the code is
87+
# intended to run in multiple environments; otherwise, check them in:
88+
# .python-version
89+
90+
# pipenv
91+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
93+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
94+
# install all needed dependencies.
95+
#Pipfile.lock
96+
97+
# poetry
98+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99+
# This is especially recommended for binary packages to ensure reproducibility, and is more
100+
# commonly ignored for libraries.
101+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102+
#poetry.lock
103+
104+
# pdm
105+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106+
#pdm.lock
107+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108+
# in version control.
109+
# https://pdm.fming.dev/#use-with-ide
110+
.pdm.toml
111+
112+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113+
__pypackages__/
114+
115+
# Celery stuff
116+
celerybeat-schedule
117+
celerybeat.pid
118+
119+
# SageMath parsed files
120+
*.sage.py
121+
122+
# Environments
123+
.env
124+
.venv
125+
env/
126+
venv/
127+
ENV/
128+
env.bak/
129+
venv.bak/
130+
131+
# Spyder project settings
132+
.spyderproject
133+
.spyproject
134+
135+
# Rope project settings
136+
.ropeproject
137+
138+
# mkdocs documentation
139+
/site
140+
141+
# mypy
142+
.mypy_cache/
143+
.dmypy.json
144+
dmypy.json
145+
146+
# Pyre type checker
147+
.pyre/
148+
149+
# pytype static type analyzer
150+
.pytype/
151+
152+
# Cython debug symbols
153+
cython_debug/
154+
155+
# PyCharm
156+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158+
# and can be added to the global gitignore or merged into this file. For a more nuclear
159+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160+
#.idea/

arduino_comm/arduino_comm/__init__.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Copyright 2023 michael. All rights reserved.
2+
# Use of this source code is governed by a BSD-style
3+
# license that can be found in the LICENSE file.
4+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
# Copyright 2023 michael. All rights reserved.
2+
# Use of this source code is governed by a BSD-style
3+
# license that can be found in the LICENSE file.
4+
5+
import rclpy
6+
from rclpy.node import Node
7+
8+
from std_msgs.msg import String, Header, Float32
9+
from ackermann_msgs.msg import AckermannDriveStamped
10+
from roar_gokart_msgs.msg import VehicleStatus, EgoVehicleControl, Actuation
11+
from typing import Optional
12+
import socket
13+
import time
14+
import struct
15+
import json
16+
from pydantic import BaseModel
17+
from pydantic.types import confloat
18+
from rclpy.logging import LoggingSeverity
19+
import numpy as np
20+
21+
22+
class ArduinoActuationModel(BaseModel):
23+
throttle: float = 0.0
24+
steering: float = 0.0
25+
brake: float = 0.0
26+
reverse: bool = False
27+
28+
29+
class ArduinoVehicleStateModel(BaseModel):
30+
is_auto: bool = False
31+
is_left_limiter_ON: bool = False
32+
is_right_limiter_ON: bool = False
33+
angle: float = 0.0
34+
angular_velocity: float = 0.0
35+
speed: float = 0.0
36+
target_speed: float = 0.0
37+
target_steering_angle: float = 0.0
38+
current_actuation: ArduinoActuationModel = ArduinoActuationModel()
39+
40+
41+
class ArduinoEgoVehicleControlMsg(BaseModel):
42+
target_speed: float = 0.0
43+
steering_angle: float = 0.0
44+
brake: confloat(ge=0.0, le=1.0) = 0.0
45+
reverse: bool = False
46+
47+
48+
class ArduinoCommNode(Node):
49+
def __init__(self):
50+
super().__init__("arduino_comm_node")
51+
self.declare_parameter("ip_address", "10.0.0.9")
52+
self.declare_parameter("port", 1883)
53+
54+
self.declare_parameter("get_state_period", 0.1)
55+
self.declare_parameter("write_action_period", 0.1)
56+
57+
self.declare_parameter("write_timeout", 0.1)
58+
self.declare_parameter("vehicle_status_header", "base_link")
59+
60+
# timers
61+
get_state_period: float = (
62+
self.get_parameter("get_state_period").get_parameter_value().double_value
63+
)
64+
self.get_state_timer = self.create_timer(
65+
get_state_period, self.get_state_from_arduino
66+
)
67+
write_action_period: float = (
68+
self.get_parameter("write_action_period").get_parameter_value().double_value
69+
)
70+
self.write_action_timer = self.create_timer(
71+
write_action_period, self.write_action_callback
72+
)
73+
74+
# pub / sub
75+
self.cmd_sub_ = self.create_subscription(
76+
EgoVehicleControl, "ego_vehicle_control", self.cmd_recvd, 10
77+
)
78+
self.vehicle_state_publisher_ = self.create_publisher(
79+
VehicleStatus, "vehicle_status", 10
80+
)
81+
82+
self.state: Optional[VehicleStatus] = None
83+
self.latest_control_model: ArduinoEgoVehicleControlMsg = (
84+
ArduinoEgoVehicleControlMsg()
85+
)
86+
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
87+
88+
self._logger.set_level(LoggingSeverity.INFO)
89+
90+
def cmd_recvd(self, msg: EgoVehicleControl):
91+
self.latest_control_model = self.p_egoVehicleControlMsgToArduinoCmdActionModel(
92+
msg
93+
)
94+
self.get_logger().debug(f"Recevied: {self.latest_control_model}")
95+
96+
def get_state_from_arduino(self):
97+
message = b"s"
98+
self.sock.sendto(message, self.p_getIPAndPort())
99+
100+
data, addr = self.sock.recvfrom(1024) # Buffer size is 1024 bytes
101+
try:
102+
string_data = data.decode("utf-8")
103+
json_data = json.loads(string_data)
104+
latest_model = self.p_dataToVehicleState(json_data)
105+
self.p_publish_state(latest_model)
106+
self.get_logger().debug(f"Read: [{latest_model}]")
107+
except Exception as e:
108+
self.get_logger().error(f"Unable to convert [{data}]. Error: {e}")
109+
110+
def write_action_callback(self):
111+
message = self.latest_control_model.json().encode("utf-8")
112+
self.get_logger().debug(f"Wrote: {message}")
113+
self.sock.sendto(message, self.p_getIPAndPort())
114+
115+
def p_egoVehicleControlMsgToArduinoCmdActionModel(
116+
self, egoVehicleControlMsg: EgoVehicleControl
117+
) -> ArduinoEgoVehicleControlMsg:
118+
model = ArduinoEgoVehicleControlMsg()
119+
model.brake = np.clip(egoVehicleControlMsg.brake, 0, 1)
120+
model.reverse = egoVehicleControlMsg.reverse
121+
model.steering_angle = egoVehicleControlMsg.steering_angle
122+
model.target_speed = egoVehicleControlMsg.target_speed
123+
124+
return model
125+
126+
def p_getIPAndPort(self):
127+
ip_address = self.get_parameter("ip_address").get_parameter_value().string_value
128+
port = self.get_parameter("port").get_parameter_value().integer_value
129+
return (ip_address, port)
130+
131+
def p_dataToVehicleState(self, data: dict) -> ArduinoVehicleStateModel:
132+
model = ArduinoVehicleStateModel.parse_obj(data)
133+
return model
134+
135+
def p_publish_state(self, curr_state: ArduinoVehicleStateModel):
136+
header = Header()
137+
header.stamp = self.get_clock().now().to_msg()
138+
header.frame_id = (
139+
self.get_parameter("vehicle_status_header")
140+
.get_parameter_value()
141+
.string_value
142+
)
143+
act = Actuation()
144+
act.throttle = curr_state.current_actuation.throttle
145+
act.steering = curr_state.current_actuation.steering
146+
act.brake = curr_state.current_actuation.brake
147+
act.reverse = curr_state.current_actuation.reverse
148+
149+
msg = VehicleStatus()
150+
151+
msg.angle = curr_state.angle
152+
msg.is_auto = curr_state.is_auto
153+
msg.is_left_limiter_on = curr_state.is_left_limiter_ON
154+
msg.is_right_limiter_on = curr_state.is_right_limiter_ON
155+
msg.speed = curr_state.speed
156+
msg.target_speed = curr_state.target_speed
157+
msg.target_steering_angle = curr_state.target_steering_angle
158+
msg.actuation = act
159+
160+
self.vehicle_state_publisher_.publish(msg)
161+
162+
def destroy_node(self):
163+
super().destroy_node()
164+
165+
166+
def main(args=None):
167+
rclpy.init(args=args)
168+
node = ArduinoCommNode()
169+
170+
try:
171+
rclpy.spin(node)
172+
except KeyboardInterrupt:
173+
pass
174+
except Exception as e:
175+
print(e)
176+
finally:
177+
node.destroy_node()
178+
rclpy.shutdown()
179+
180+
181+
if __name__ == "__main__":
182+
main()

arduino_comm/launch/arduino.launch.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from launch import LaunchDescription
2+
from ament_index_python.packages import get_package_share_directory
3+
import launch_ros.actions
4+
import os
5+
import yaml
6+
from launch.substitutions import EnvironmentVariable
7+
import pathlib
8+
import launch.actions
9+
from launch.actions import DeclareLaunchArgument
10+
from pathlib import Path
11+
12+
13+
def generate_launch_description():
14+
return LaunchDescription(
15+
[
16+
launch_ros.actions.Node(
17+
package="arduino_comm",
18+
executable="arduino_comm_node",
19+
name="arduino_comm_node",
20+
remappings=[
21+
("ego_vehicle_control", "/roar/gokart/control"),
22+
("vehicle_status", "/roar/gokart/status"),
23+
],
24+
),
25+
]
26+
)

arduino_comm/package.xml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0"?>
2+
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
3+
<package format="3">
4+
<name>arduino_comm</name>
5+
<version>0.0.0</version>
6+
<description>TODO: Package description</description>
7+
<maintainer email="[email protected]">michael</maintainer>
8+
<license>TODO: License declaration</license>
9+
10+
<exec_depend>roar_gokart_msgs</exec_depend>
11+
<build_depend>rosidl_default_generators</build_depend>
12+
<exec_depend>rosidl_default_runtime</exec_depend>
13+
<member_of_group>rosidl_interface_packages</member_of_group>
14+
<test_depend>ament_copyright</test_depend>
15+
<test_depend>ament_flake8</test_depend>
16+
<test_depend>ament_pep257</test_depend>
17+
<test_depend>python3-pytest</test_depend>
18+
19+
<export>
20+
<build_type>ament_python</build_type>
21+
</export>
22+
</package>

arduino_comm/resource/arduino_comm

Whitespace-only changes.

0 commit comments

Comments
 (0)