Im trying to send two different g-code instructions to the SKR V1.3 simultaneously using the pi 4B's UART pins to control two wheel stepper motors and one stepper motor for my lidar system:
First i send this command in order to allow un-restricted movement of the motors:
stty -echo && echo "G91" >> /dev/ttyAMA0
But then, When I want to send these commands simultaneously
For wheels,
echo "G1 X80 Y80" >> /dev/ttyAMA0
and for Lidar back n' fourth motion,
echo "G1 Z20" >> /dev/ttyAMA0
wait(3 seconds in python)
echo "G1 Z-20' >> /dev/ttyAMA0
they don't end up being processed at the same time. They work fine when executed alone, but when I execute them at the same time, or one after another, its only when the previous G-code command stops does the next one start. Is there a way to get around this and execute g-code commands simultaneously?
You can add the initial Z command to your existing command:
echo "G1 X80 Y80 Z20" >> /dev/ttyAMA0
I would recommend getting in to pyserial
https://github.com/pyserial/pyserial
Related
I need to run 2 command lines in chess engine using the UCI protocol.
1- position fen "r1k4r/p2nb1p1/2b4p/1p1n1p2/2PP4/3Q1NB1/1P3PPP/R5K1 b"
2- go depth 10
The first line set the FEN position in the engine (stockfish).
The second command the engine start to analyse the position and then give me an output.
In vb6 my code is this:
With CreateObject("WScript.Shell")
.Run "cmd /c start /b E:\UCI-Vb6\stockfish_9_x64.exe position fen "r1k4r/p2nb1p1/2b4p/1p1n1p2/2PP4/3Q1NB1/1P3PPP/R5K1 b" > E:\UCI-Vb6\out.txt", 1, True
End With
and runs perfectly, but if I try to send a second command it will go back to re-start the engine with no "memories" about the position I set up before.
I also try nesting the two commands with the "&" parameter but with the same result
And also try using "cmd /k" but again with no success.
Mplayer provides shortcuts to change the track and play/pause the music but they only work if the mplayer window has the focus.
Is it possible, for example, to change the track currently played in mplayer with a command line? In that case, I could assign this command to a shortcut and use it even if mplayer does not have the focus.
All I found on google was how to use mplayer to play files or which shortcuts to change track when the window has the focus.
I am actually in the middle of trying to do this exact thing! I am going to share what I have discovered so far in case it helps anyone.
I have not been able to find a way to play/pause tracks. However, I have been able to change tracks, at least in terms of going to the next track.
I have found 2 ways so far: Using /proc/$pid/fd/0 and Named Pipes (FIFOs). Explaining FIFOs is a little harder (I just recently learned of them) so I will do that last.
Modifying STDIN via /proc/$pid/fd/0
We can communicate with a process in a different terminal session by redirecting input to the process' file definitions directory at /proc/$pid/fd/ where $pid is the process' PID.
Firstly, find the process ID using pidof. Make sure mplayer is actually running!
$ pidof mplayer
This will output the PID of mplayer. Using this $PID, we can input what we want to STDIN for mplayer by redirecting it to /proc/$PID/fd/0. (Note, 0 refers to STDIN, 1 to STDOUT, etc.). An example:
$ echo "p" > /proc/$PID/fd/0
This has the effect of changing the tracks for mplayer.
However, even though I used p in my example, I have found that you can echo anything (including nothing) and it will still accomplish the same goal of changing the track no matter what you input.
Named Pipes
Also called FIFOs, named pipes, just like regular pipes (|), redirect output to other processes. The main difference is that these are part of the filesystem and can be used to communicate between different terminal sessions.
To start off, create a new named pipe anywhere in your filesystem. I chose /tmp/.
$ mkfifo /tmp/mp3control.pipe
Then start mplayer redirecting its STDIN to the named pipe.
$ mplayer -playlist brutal_tunez.txt < /tmp/mp3control.pipe
It will look like the process hangs and that's because it is expecting the other side to input something.
Now open up a new terminal and input stuff into the pipe.
$ echo "p" > /tmp/mp3control.pipe
You will hear music start to play from mplayer. Again, just like before, any further inputs to the pipe will just change tracks.
I believe this has something to do with the way mplayer handles STDIN and is not the same thing as entering p to play or pause music.
I will continue looking into this but I would love to hear from someone if I made a mistake somewhere. All in all, this might end up being something where the amount of time spent is not worth it, to be honest. (But we still must!)
I have a file make_partition.sql like:
CREATE INDEX my_nice_index ON mytable (ts);
CREATE TABLE mytable_2017_10 AS SELECT * FROM mytable WHERE date_trunc('month', ts) = '2017-10-01';
CREATE TABLE mytable_2017_11 AS SELECT * FROM mytable WHERE date_trunc('month', ts) = '2017-11-01';
I run it in the background using screen and then the command:
psql postgresql://usr:pw#host.com:5432/db_name -f make_partition.sql
And detach from the screen. It completes, but then it appears that only the first query was run. I've tested this a few times with the same result.
How can I get it to run them all? Do I have to put them in a procedure like this? How to run multiple SQL queries?
When you 'detach' from the screen, what is likely happening is an HUP signal is sent to the process and the script stops executing, the query that is currently executing will finish because it is part of a different process.
You can properly send it to the background and make it safe to detach in a couple of ways, one of the ways is using the command nohup (see man nohup for more) which ignores the HUP signal.
An alternative is to start the script as you have above, then pause it by pressing CTRL+Z, you can then send it to the background using bg and finally you can ensure it is ignoring the HUP signal using disown -h (see man disown for more).
This question is relatively old, and Adam Dadvar's answer provides the basics, but I'll provide one other piece of the puzzle that could trip someone up. If the SQL within your file will create output after each statement, you need to redirect at least the stdout into files, rather than letting it go to the terminal. Doing the latter will mean it's displaying the results and waiting for you to spacebar through the results before running the next command. If your code may produce error that you want to ignore, you should also redirect that output. Concretely, using the disown option, it would look something like:
psql postgresql://usr:pw#host.com:5432/db_name -f make_partition.sql 1> messages.log 2> errors.log
Then use CTRL+Z to suspend the current process, disown -h %1 to disown the process, and bg to "background" the process.
I wrote a script to remote execute test.cmd file by PsExec.exe.
PsExec.exe \\IP -u administrator -p password "C:\\Users\Administrator\Desktop\test.cmd"
Although I can run the script successfully, I cannot press any key to continue the process when it runs into command pause.
Press any key to continue . . . aaaaaa
The only way to keep going is press Enter.
Besides, if there are many lines of Pause or set /p which waits users to input, once user press Enter, it will affect couple lines of Pause or set /p. It really confuses me.
Best is that you use different logic in accordance with your limitations.
Try exchanging the Pause with a different suitable solution.
Other suggestion would be that you share your code, inputs and expectations (output is already given - the script doesn’t continue). Then someone can review the code and suggest for further steps.
Alternatively, it is also possible that you can fix it by using Console.ReadKey()
From within a MATLAB GUI application, I'm starting an external program (a console application on Windows) that takes care of reading data from a measurement system. The data is stored in several files that are processed by the MATLAB application as soon as the external program has finished. The problem is this:
The external program, when run on the command line, can be gracefully stopped by issuing a SIGINT (i.e. by pressing Ctrl + C). A signal handler traps the SIGINT and shuts down the program. Is there a way to do this from within the MATLAB GUI application, by pushing an "abort" button?
After many hours of searching I stumbled upon http://www.caam.rice.edu/~wy1/links/mex_ctrl_c_trick/ which shows how to detect SIGINT in a MEX file. Letting a MEX call the external program might work (although I'm not sure about the details yet). However, it still requires Ctrl + C to stop the program. How can I send the SIGINT via push button in my GUI?
If you start your external program in Cygwin, then Cygwin will give it a PID. Using this PID you can use Cygwin's kill command to send signals to the process. So start the program from Cygwin. In MATLAB you can use !ps (where ! means call external shell command) to get a list of Cygwin PID's and then !kill -s signal pid to send a signal to the program. To make it happen from a MATLAB GUI let the callback from some button call !kill.