Forum > Pas2JS

inverse kinematics in pas2js

(1/2) > >>

I recently created a simulation of robotic arm movement 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.

1) user upload using <input type="file">
2) embed the file in your JS code

It seems that it is there also one more solution described here:, but then one needs to use TMS Web Core Components.


--- Quote from: krolikbest on February 09, 2023, 08:49:05 am ---It seems that it is there also one more solution described here:, but then one needs to use TMS Web Core Components.

--- End quote ---

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

XAMPP looks quite heavyweight. If you have Python you can try this script. Should be easily adaptable to Windows, say, name the script, 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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---#!/usr/bin/env python3 # It's python3 -m http.server PORT for a CORS world from http.server import HTTPServer, SimpleHTTPRequestHandlerimport sys  class CORSRequestHandler(SimpleHTTPRequestHandler):        def end_headers(self):        self.send_header('Access-Control-Allow-Origin', 'origin')        self.send_header('Access-Control-Allow-Methods', '*')        self.send_header('Access-Control-Allow-Headers', '*')        self.send_header('Cache-Control', 'no-store, no-cache, must-revalidate')        return super(CORSRequestHandler, self).end_headers()     def do_OPTIONS(self):        self.send_response(200)        self.end_headers() host = sys.argv[1] if len(sys.argv) > 2 else ''port = int(sys.argv[len(sys.argv)-1]) if len(sys.argv) > 1 else 20080 print("Listening on {}:{}".format(host, port))httpd = HTTPServer((host, port), CORSRequestHandler)httpd.serve_forever() 


[0] Message Index

[#] Next page

Go to full version