Skip to content
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

Example program 16 and image path extractor refactor #12

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions trpl_examples/16_digital_IO/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Example 16: Digital input and output (Digital I/O)
This example will be demonstrating how to get signals from input and output pins, by controlling a gripper using a proximity switch. You can find these output pins on one of the sides of the robot cabinet. Check the current status of the pins by going to the status tab in the software UI and look at the Digital I/O section to the right.

### Learn more about the Tormach Robot Programming Language (TRPL):
https://tormach.atlassian.net/wiki/spaces/ROBO/pages/1930690719/Tormach+Robot+Programming+Language
41 changes: 41 additions & 0 deletions trpl_examples/16_digital_IO/digital_io.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@


# Example 16: Digital input and output (Digital I/O)
# This example will be demonstrating how to get signals from input and output pins,
# by controlling a gripper using a proximity switch.
# You can find these output pins on one of the sides of the robot cabinet,
# or go to the status tab in the software UI and look at the Digital I/O section to the right.

# These pins make it easy to interact with external devices like buttons or grippers.



from robot_command.rpl import *


set_units("mm", "deg") # set units

# Setting up global variables for the pins
GRIPPER_PIN = 7
PROX_SWITCH_PIN = 5

# Before we start opening and closing the gripper we need to set it in a known state.
set_digital_out(GRIPPER_PIN, False) # Close gripper

#***************************************************************
# NOTE: For this program you will need a button and grippers
#**************************************************************

notify("In this program, you will be opening and closing a gripper using a proximity switch.\n\nClick \"OK\" to continue if you have the gripper connected to output pin 7 and proximity switch conected to input pin 5 located on the robot cabinet.\n\nTo trigger the proximity switch put the proximity switch papendiculer to any metal surface.", warning=True)


# The main function runs in a loop
def main():
input_pin_state = get_digital_in(PROX_SWITCH_PIN) # Get the current state of the proximity switch.

# The proximity switch state will be "False" when its in contact with a metal object.
if input_pin_state is False: # If we detect a metal object
set_digital_out(GRIPPER_PIN, True) # Open gripper
sleep(2) # Wait 2 seconds

set_digital_out(GRIPPER_PIN, False) # Close gripper
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

This file was deleted.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 21 additions & 1 deletion trpl_examples/projects/image_path_extractor_pathpilot/common.py
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@
import cv2
import json


def cv_contour_list_to_pathsList(contourList):
newList = []
list = contourList
@@ -56,4 +57,23 @@ def cv_strict_resize(img, _desired_width=150, _desired_height=150):
new_height = _desired_height
new_width = int(new_height * aspect_ratio)
print("new W:H", new_width, new_height)
return cv2.resize(img, (new_width, new_height), interpolation=cv2.INTER_AREA)
return cv2.resize(img, (new_width, new_height), interpolation=cv2.INTER_AREA)

def b_spline(waypoints):
if not waypoints:
return []

waypoints = np.array(waypoints)
x = []
y = []

x = waypoints[:, 0]
y = waypoints[:, 1]


tck, _ = interpolate.splprep([x, y])
u = np.linspace(0, 1, num=200)
_x, _y = interpolate.splev(u, tck)
smooth = np.dstack((_x, _y))
# print(smooth)
return smooth[0]
Loading