Skip to content

3d printer added #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

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
37b5d16
Starting point of the implementation. All the ROS2 packages are curre…
LoicMosser Apr 3, 2023
6a31e58
Deleting some trash I've done
LoicMosser Apr 3, 2023
3ebf12b
Update .gitignore
LoicMosser Apr 3, 2023
8f128fe
Here is the beginning of something ! everything compil and nothing wo…
LoicMosser Apr 3, 2023
918cd85
A new service arrive allowing the user to add a camera to the printin…
LoicMosser Apr 4, 2023
69778dd
Deleting renamed files
LoicMosser Apr 4, 2023
2bd1f9b
end of the day. The four packages are working. The printing routine m…
LoicMosser Apr 4, 2023
6675954
I've found how to add the right filepath in the gitignore for the ext…
LoicMosser Apr 4, 2023
f72c716
base before precommit
LoicMosser Apr 14, 2023
381dac7
Necessary updates to compil the different nodes using ROS2 Humble
LoicMosser Apr 17, 2023
241a868
added some calibration code plus adjusting some hyperparameters
LoicMosser Apr 18, 2023
5e251ed
precommit run
Apr 18, 2023
512cd16
manually add corrections to the code
Apr 18, 2023
df3d465
precommit and uncrustify are chellenging each other
Apr 19, 2023
0bf90ca
changed Namespace in gocatorNode
Apr 19, 2023
ec2a549
Error colcon build
LoicMosser Apr 19, 2023
a8dd512
colcon error corrected
Apr 19, 2023
5b27cf4
split driver features with launch files
LoicMosser Aug 30, 2023
490e7ab
add config YAML file to printer manager pkg
LoicMosser Aug 30, 2023
48e435c
adding a point processing package
LoicMosser Aug 30, 2023
f211c11
Point processing package dev on 5 of September
LoicMosser Sep 5, 2023
d1325c0
correction of namespace error + beggining of retraction implementation
LoicMosser Sep 5, 2023
d1532bf
successfully integrated retraction of filament before scanning and im…
LoicMosser Sep 6, 2023
3297975
gcode capture code used for paper (update 1)
LoicMosser Sep 7, 2023
1d51c9d
gcode capture code used for paper (update 2)
LoicMosser Sep 8, 2023
2f43aff
Keyence package add to the repo
LoicMosser May 3, 2024
f0f2ab4
adding __pycache__ to .gitignore
LoicMosser May 3, 2024
2707ecf
node launch update
LoicMosser May 3, 2024
b31c871
Point_cloud processing work
LoicMosser May 3, 2024
c793a58
Readme update + pointcloud processing
LoicMosser May 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,10 @@ build/
log/
install/
.vscode/
3D_Printer/build
3D_Printer/install
3D_Printer/log
3D_printer/src/printer3d_profile_capture/external
3D_printer/src/printer3d_keyence_profile_capture/src/driver
3D_printer/src/printer3d_keyence_profile_capture/launch/__pycache__
3D_printer/src/printer3d_keyence_data_acquisition_test/launch/__pycache__
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ repos:
# Spellcheck in comments and docs
# skipping of *.svg files is not working...
- repo: https://github.com/codespell-project/codespell
rev: v2.2.2
rev: v2.2.4
hooks:
- id: codespell
args: ['--write-changes']
Expand Down
45 changes: 45 additions & 0 deletions 3D_printer/src/printer3d_driver/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
cmake_minimum_required(VERSION 3.5)
project(printer3d_driver)

# Default to C99
if(NOT CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 99)
endif()

# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)

# Install the python module for this package
# ament_python_install_package(nodes/)

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
# the following line skips the linter which checks for copyrights
# uncomment the line when a copyright and license is not present in all source files
#set(ament_cmake_copyright_FOUND TRUE)
# the following line skips cpplint (only works in a git repo)
# uncomment the line when this package is not in a git repo
#set(ament_cmake_cpplint_FOUND TRUE)
ament_lint_auto_find_test_dependencies()
endif()

# Install python scripts

install(
PROGRAMS
nodes/gcode_monitor_node.py
DESTINATION lib/${PROJECT_NAME}
)

ament_package()
Empty file.
146 changes: 146 additions & 0 deletions 3D_printer/src/printer3d_driver/nodes/gcode_monitor_node.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
#!/usr/bin/env python3
# Copyright 2023 ICube Laboratory, University of Strasbourg
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import rclpy
from rclpy.node import Node
import time
import serial
from printer3d_msgs.srv import GcodeCommand


def openSerialPort(port, baud):
"""
Handle the opening of the serial port and exit if the port haven't been opened.

Args:
-------
port (string): supposed to be "COM" plus the number associated to the
baud (int): baudrate of the port communication (commonly 9600, 115200, 250000 ...)

Returns
-------
pyserial object: an object allowing to send and receive data through USB

"""
print('Opening Serial Port...')
try:
s = serial.Serial(port, baud)
if (s.isOpen() is True):
print(port + " has opened successfully.")
return s
else:
print(port + " has failed to open.")
exit()
except Exception:
print("An error occurred while opening " + port)
exit()


def removeComment(string):
"""
Remove the comments from a gcode line stored as a string.

Args
-------
string (string): gcode line with a possible comment inside

Returns
-------
string: input string without comment

"""
if (string.find(';') == -1):
return string
else:
return string[:string.index(';')]


class GcodeMonitorNode(Node):
def __init__(self):
"""Gcodemonitornode class constructor."""
super().__init__('printer_gcode_monitor')
self.serialPort = openSerialPort('/dev/ttyACM0', 250000)
self.serialPort.write(b"\n\n")
time.sleep(2)
self.gcodeService = self.create_service(GcodeCommand, 'send_gcode', self.execute_gcode_sending)

def execute_gcode_sending(self, request, response):
"""
Execute this function of the service send_gcode provided by this ROS2 node.

Args
-------
request (list of string): list of gcode lines to be sended through the serial communication
response (bool): True

Returns
-------
bool: True

"""
gcode = request.gcode_strings
# self.get_logger().info('Executing Gcode')
feedback = 0.0
self.serialPort.flushInput()
self.i = 0
self.total = len(gcode)
self.increment = 0.0

for line in gcode:
# feedback publication
feedback = (self.i/self.total)*100
if feedback - self.increment > 1:
self.increment = feedback

# Gcode Sending

line = removeComment(line)
line = line.strip()
self.i += 1
if (line.isspace() is False and len(line) > 0):
if ' E' in line:
self.lastExtrusionSended = float(line.split('E')[1])
self.serialPort.write((line + "\n").encode('ascii'))
grbl_out = self.serialPort.readline() # wait for response from printer
grbl_out = grbl_out.strip().decode('ascii')
while 'ok' not in grbl_out:
grbl_out = self.serialPort.readline() # wait for response from printer
grbl_out = grbl_out.strip().decode('ascii')

self.serialPort.write(b"M400\n")
grbl_out = self.serialPort.readline() # wait for response from printer
grbl_out = grbl_out.strip().decode('ascii')
while 'ok' not in grbl_out:
grbl_out = self.serialPort.readline() # wait for response from printer
grbl_out = grbl_out.strip().decode('ascii')

self.serialPort.write(b"M400\n")
grbl_out = self.serialPort.readline() # wait for response from printer
grbl_out = grbl_out.strip().decode('ascii')
while 'ok' not in grbl_out:
grbl_out = self.serialPort.readline() # wait for response from printer
grbl_out = grbl_out.strip().decode('ascii')

# self.get_logger().info('gcode sending completely finished')
response.validation = True

return response


if __name__ == '__main__':
rclpy.init()
gcode_monitor_node = GcodeMonitorNode()
rclpy.spin(gcode_monitor_node)
rclpy.shutdown()
18 changes: 18 additions & 0 deletions 3D_printer/src/printer3d_driver/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>printer3d_driver</name>
<version>0.0.0</version>
<description>TODO: Package description</description>
<maintainer email="[email protected]">gulltor</maintainer>
<license>TODO: License declaration</license>

<buildtool_depend>ament_cmake</buildtool_depend>

<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>

<export>
<build_type>ament_cmake</build_type>
</export>
</package>
28 changes: 28 additions & 0 deletions 3D_printer/src/printer3d_gocator_msgs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
cmake_minimum_required(VERSION 3.5)
project(printer3d_gocator_msgs)


if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()


find_package(ament_cmake REQUIRED)
find_package(builtin_interfaces REQUIRED)
find_package(rosidl_default_generators REQUIRED)
find_package(std_msgs REQUIRED)
find_package(sensor_msgs REQUIRED)


rosidl_generate_interfaces(${PROJECT_NAME}
"srv/GocatorPTCloud.srv"
DEPENDENCIES builtin_interfaces std_msgs sensor_msgs
)

ament_export_dependencies(rosidl_default_runtime)

ament_package()
Empty file.
19 changes: 19 additions & 0 deletions 3D_printer/src/printer3d_gocator_msgs/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>printer3d_gocator_msgs</name>
<version>0.0.0</version>
<description>Messages form communication with GOCATOR systems</description>
<maintainer email="[email protected]">m.bednarczyk</maintainer>
<license>TODO: License declaration</license>
<buildtool_depend>ament_cmake</buildtool_depend>
<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>
<depend>std_msgs</depend>
<depend>sensor_msgs</depend>
<depend>builtin_interfaces</depend>
<depend>rosidl_default_generators</depend>
<member_of_group>rosidl_interface_packages</member_of_group>
<export>
<build_type>ament_cmake</build_type>
</export>
</package>
3 changes: 3 additions & 0 deletions 3D_printer/src/printer3d_gocator_msgs/srv/GocatorPTCloud.srv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
std_msgs/Empty request
---
sensor_msgs/PointCloud2 pcloud
46 changes: 46 additions & 0 deletions 3D_printer/src/printer3d_image_capture/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
cmake_minimum_required(VERSION 3.5)
project(printer3d_image_capture)

# Default to C99
if(NOT CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 99)
endif()

# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)

# Install the python module for this package
# ament_python_install_package(nodes/)

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
# the following line skips the linter which checks for copyrights
# uncomment the line when a copyright and license is not present in all source files
#set(ament_cmake_copyright_FOUND TRUE)
# the following line skips cpplint (only works in a git repo)
# uncomment the line when this package is not in a git repo
#set(ament_cmake_cpplint_FOUND TRUE)
ament_lint_auto_find_test_dependencies()
endif()

# Install python scripts

install(
PROGRAMS
nodes/image_capture_calibration.py
nodes/image_capture_node.py
DESTINATION lib/${PROJECT_NAME}
)

ament_package()
Empty file.
Loading