Recent

Author Topic: inverse kinematics in pas2js  (Read 2013 times)

krolikbest

  • Full Member
  • ***
  • Posts: 246
inverse kinematics in pas2js
« on: February 08, 2023, 10:21:56 pm »
I recently created a simulation of robotic arm movement https://www.youtube.com/watch?v=Qs-W6Lzi1XQ using pas2js technology. I was not using the latest version of pas2js but a slightly older one, from 2020 year. There is no library support implemented there yet, which is probably already in the newer version. In general, most of the code concerning math and arm movement comes from my earlier work, but it was new experience  for me the use of possibilities concerning graphics that pas2js gives. However during programming the surprise was how to read a local file (text file) which contains a set of vectors that form the movement path for the arm. To read such files I did the following (Windows 7):
- I installed the XAMPP server
- in the XAMPP\htdocs directory, I created a .htacces file
- the content of this file is the entry: Header set Access-Control-Allow-Origin "*".
- in the directory XAMPP\htdocs I created my directory where I keep my files, so then it looks like C:\XAMPP\htdocs\mydir
- Restart the XAMPP server
These steps helped me to avoid the CORS error that the browser reports when trying to open a file from a local disk. If you know better methods to open and read local text files I will be glad to know.
« Last Edit: February 08, 2023, 10:24:00 pm by krolikbest »

domasz

  • Sr. Member
  • ****
  • Posts: 413
Re: inverse kinematics in pas2js
« Reply #1 on: February 08, 2023, 11:14:39 pm »
Alternatives:
1) user upload using <input type="file">
2) embed the file in your JS code

krolikbest

  • Full Member
  • ***
  • Posts: 246
Re: inverse kinematics in pas2js
« Reply #2 on: February 09, 2023, 08:49:05 am »
It seems that it is there also one more solution described here:https://support.tmssoftware.com/t/file-upload-example/11719, but then one needs to use TMS Web Core Components.

domasz

  • Sr. Member
  • ****
  • Posts: 413
Re: inverse kinematics in pas2js
« Reply #3 on: February 09, 2023, 09:25:25 am »
It seems that it is there also one more solution described here:https://support.tmssoftware.com/t/file-upload-example/11719, but then one needs to use TMS Web Core Components.

This is Ajax and you will still need to host the file with a web server (like you do now).

PierceNg

  • Sr. Member
  • ****
  • Posts: 369
    • SamadhiWeb
Re: inverse kinematics in pas2js
« Reply #4 on: February 09, 2023, 09:34:48 am »
XAMPP looks quite heavyweight. If you have Python you can try this script. Should be easily adaptable to Windows, say, name the script pyhttpd.py, and create a .bat file to run the script. This script is useful as you can run it from any directory to serve said directory's contents.   

Code: Python  [Select][+][-]
  1. #!/usr/bin/env python3
  2.  
  3. # It's python3 -m http.server PORT for a CORS world
  4.  
  5. from http.server import HTTPServer, SimpleHTTPRequestHandler
  6. import sys
  7.  
  8.  
  9. class CORSRequestHandler(SimpleHTTPRequestHandler):
  10.    
  11.     def end_headers(self):
  12.         self.send_header('Access-Control-Allow-Origin', 'origin')
  13.         self.send_header('Access-Control-Allow-Methods', '*')
  14.         self.send_header('Access-Control-Allow-Headers', '*')
  15.         self.send_header('Cache-Control', 'no-store, no-cache, must-revalidate')
  16.         return super(CORSRequestHandler, self).end_headers()
  17.  
  18.     def do_OPTIONS(self):
  19.         self.send_response(200)
  20.         self.end_headers()
  21.  
  22. host = sys.argv[1] if len(sys.argv) > 2 else '0.0.0.0'
  23. port = int(sys.argv[len(sys.argv)-1]) if len(sys.argv) > 1 else 20080
  24.  
  25. print("Listening on {}:{}".format(host, port))
  26. httpd = HTTPServer((host, port), CORSRequestHandler)
  27. httpd.serve_forever()
  28.  


krolikbest

  • Full Member
  • ***
  • Posts: 246
Re: inverse kinematics in pas2js
« Reply #5 on: February 09, 2023, 12:43:16 pm »
Indeed, xampp is too heavy  for such purposes, so now I'm looking something lightweight.

 

TinyPortal © 2005-2018