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

Assignment 03 #30

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"dtype": "compas.robots/Configuration", "value": {"joint_values": [2.561262838721709, 0.8451018845125493, -2.128157829177538, 5.995444924740527, 4.712388980581042, -5.292718795466213], "joint_types": [0, 0, 0, 0, 0, 0], "joint_names": ["shoulder_pan_joint", "shoulder_lift_joint", "elbow_joint", "wrist_1_joint", "wrist_2_joint", "wrist_3_joint"]}}, {"dtype": "compas.robots/Configuration", "value": {"joint_values": [2.2125640907869433, 0.8942197482784214, -2.3657481437474894, 6.183917375542697, 4.712388980617422, -5.641417543400978], "joint_types": [0, 0, 0, 0, 0, 0], "joint_names": ["shoulder_pan_joint", "shoulder_lift_joint", "elbow_joint", "wrist_1_joint", "wrist_2_joint", "wrist_3_joint"]}}, {"dtype": "compas.robots/Configuration", "value": {"joint_values": [-0.2970980335982931, -3.7990612214450974, 1.5888955622429972, -5.643815971684596, 4.712388980430257, -1.8678943604431635], "joint_types": [0, 0, 0, 0, 0, 0], "joint_names": ["shoulder_pan_joint", "shoulder_lift_joint", "elbow_joint", "wrist_1_joint", "wrist_2_joint", "wrist_3_joint"]}}, {"dtype": "compas.robots/Configuration", "value": {"joint_values": [-0.6726973850771518, -3.785948528761859, 1.5560738824964655, -5.624106984724417, 4.712388979195383, -2.243493711922022], "joint_types": [0, 0, 0, 0, 0, 0], "joint_names": ["shoulder_pan_joint", "shoulder_lift_joint", "elbow_joint", "wrist_1_joint", "wrist_2_joint", "wrist_3_joint"]}}, {"dtype": "compas.robots/Configuration", "value": {"joint_values": [-1.051392668584917, -3.705690100785498, 1.3609023953100354, -5.509193926044956, 4.712388977988545, -2.622188995429787], "joint_types": [0, 0, 0, 0, 0, 0], "joint_names": ["shoulder_pan_joint", "shoulder_lift_joint", "elbow_joint", "wrist_1_joint", "wrist_2_joint", "wrist_3_joint"]}}, {"dtype": "compas.robots/Configuration", "value": {"joint_values": [-1.392908672652407, -3.5673600645888737, 1.0398093941698567, -5.326430961973991, 4.712388977064929, -2.963704999497277], "joint_types": [0, 0, 0, 0, 0, 0], "joint_names": ["shoulder_pan_joint", "shoulder_lift_joint", "elbow_joint", "wrist_1_joint", "wrist_2_joint", "wrist_3_joint"]}}, {"dtype": "compas.robots/Configuration", "value": {"joint_values": [-1.6913937521262539, -3.3847429218167844, 0.6322947612551082, -5.101533472876494, 4.712388976517914, -3.2621900789711242], "joint_types": [0, 0, 0, 0, 0, 0], "joint_names": ["shoulder_pan_joint", "shoulder_lift_joint", "elbow_joint", "wrist_1_joint", "wrist_2_joint", "wrist_3_joint"]}}, {"dtype": "compas.robots/Configuration", "value": {"joint_values": [4.32226695375123, -3.872707438192579, 1.7804900707013485, 3.6630136945243064, -4.712388982240333, -0.3901220264358558], "joint_types": [0, 0, 0, 0, 0, 0], "joint_names": ["shoulder_pan_joint", "shoulder_lift_joint", "elbow_joint", "wrist_1_joint", "wrist_2_joint", "wrist_3_joint"]}}, {"dtype": "compas.robots/Configuration", "value": {"joint_values": [4.067990148419234, -3.835480364014888, 1.681899123084908, 3.724377568382729, -4.712388982230876, -0.6443988317678508], "joint_types": [0, 0, 0, 0, 0, 0], "joint_names": ["shoulder_pan_joint", "shoulder_lift_joint", "elbow_joint", "wrist_1_joint", "wrist_2_joint", "wrist_3_joint"]}}, {"dtype": "compas.robots/Configuration", "value": {"joint_values": [3.821731137105227, -3.791333465793145, 1.5695137145099463, 3.792616079139966, -4.712388982118972, -0.890657843081858], "joint_types": [0, 0, 0, 0, 0, 0], "joint_names": ["shoulder_pan_joint", "shoulder_lift_joint", "elbow_joint", "wrist_1_joint", "wrist_2_joint", "wrist_3_joint"]}}, {"dtype": "compas.robots/Configuration", "value": {"joint_values": [3.5897877098359334, -3.7233127276305984, 1.4030353478766215, 3.891073707966185, -4.712388981921602, -1.1226012703511514], "joint_types": [0, 0, 0, 0, 0, 0], "joint_names": ["shoulder_pan_joint", "shoulder_lift_joint", "elbow_joint", "wrist_1_joint", "wrist_2_joint", "wrist_3_joint"]}}]
61 changes: 61 additions & 0 deletions lecture_04/assignment_03/maxence_grangeot/assignment_03.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
"""Assignment 03: Using inverse kinematics
"""
import os
import compas
from compas_fab.backends import RosClient
from compas_fab.robots import Configuration

from compas.geometry import Frame
from compas.geometry import Point
from compas.geometry import Vector

compas.DATA = "/Users/Maxence/opt/anaconda3/envs/fs2022/lib/python3.8/site-packages/compas/data/samples/"


def calculate_ik_for_frames(robot, frames):

configs = []
configs.append(robot.zero_configuration())

for f in frames:
start_configuration = configs[-1]
configs.append(robot.inverse_kinematics(f, start_configuration))
configs.pop(0)
return configs


def store_configurations(configurations, filename):
compas.json_dump(configurations, filename)
# Is it supposed to be more sophiticated? I don't understand the reason to define such function.
# Also, I don't find the difference between compas.json_dump and compas.json_dumps
pass


# the solution_viewer.ghx can't find the assignment_03.py (which is in the same folder).
# I fixed this by loading the json into GHPython but I would like to understand why it doesn't work by default.
if __name__ == '__main__':

frames = [
Frame(Point(-0.329, 0.059, 0.082), Vector(1.000, 0.000, 0.000), Vector(0.000, -1.000, 0.000)),
Frame(Point(-0.260, 0.129, 0.082), Vector(1.000, 0.000, 0.000), Vector(0.000, -1.000, 0.000)),
Frame(Point(-0.186, 0.194, 0.082), Vector(1.000, 0.000, 0.000), Vector(0.000, -1.000, 0.000)),
Frame(Point(-0.106, 0.252, 0.082), Vector(1.000, 0.000, 0.000), Vector(0.000, -1.000, 0.000)),
Frame(Point(-0.020, 0.299, 0.082), Vector(1.000, 0.000, 0.000), Vector(0.000, -1.000, 0.000)),
Frame(Point(0.074, 0.329, 0.082), Vector(1.000, 0.000, 0.000), Vector(0.000, -1.000, 0.000)),
Frame(Point(0.172, 0.330, 0.082), Vector(1.000, 0.000, 0.000), Vector(0.000, -1.000, 0.000)),
Frame(Point(0.263, 0.295, 0.082), Vector(1.000, 0.000, 0.000), Vector(0.000, -1.000, 0.000)),
Frame(Point(0.339, 0.233, 0.082), Vector(1.000, 0.000, 0.000), Vector(0.000, -1.000, 0.000)),
Frame(Point(0.400, 0.155, 0.082), Vector(1.000, 0.000, 0.000), Vector(0.000, -1.000, 0.000)),
Frame(Point(0.448, 0.070, 0.082), Vector(1.000, 0.000, 0.000), Vector(0.000, -1.000, 0.000))]

with RosClient('localhost') as client:
robot = client.load_robot()

configurations = calculate_ik_for_frames(robot, frames)
print("Found {} configurations".format(len(configurations)))
for i in range(0, len(configurations)):
print(configurations[i])

filename = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'assignment-03.json')
store_configurations(configurations, filename)
print("Stored results in {}".format(filename))
Loading