From: Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>
To: help-gnu-emacs@gnu.org
Subject: Re: the Elisp robot [photo]
Date: Wed, 21 Oct 2020 16:24:24 +0200 [thread overview]
Message-ID: <878sbzbqsn.fsf@ebih.ebihd> (raw)
In-Reply-To: X5ApU6piX2bWqu3Y@protected.rcdrun.com
Jean Louis wrote:
> And how does the internal OS communicates with
> robot commands? Are those shell commands or how?
It comes with files that represent different parts of
the robot.
The Elisp reads and writes to these files.
Here is one file that is a good example:
;;; -*- lexical-binding: t -*-
;;;
;;; this file:
;;; http://user.it.uu.se/~embe8573/terror-3/ev3-motor.el
;;; https://dataswamp.org/~incal/terror-3/ev3-motor.el
(require 'cl-lib)
(require 'ev3-motor-init)
(require 'file-write-to)
;; speed files / getters / setters
;; NB: digit in a/the speed file, not measured/actual droid speed
(defun get-motor-speed-file (motor)
(cl-case motor
('left left-motor-speed-file)
('right right-motor-speed-file)
('medium medium-motor-speed-file) ))
(defun get-motor-speed (motor)
(file-to-integer (get-motor-speed-file motor) ))
(defun set-motor-speed (motor speed)
(write-to-file-integer (get-motor-speed-file motor) speed) )
;; commands
(defun get-motor-cmd-file (motor)
(cl-case motor
('left left-motor-cmd-file)
('right right-motor-cmd-file)
('medium medium-motor-cmd-file) ))
(defun motor-cmd (motor cmd)
(write-to-file (get-motor-cmd-file motor) cmd) )
(defun run-forever (motor)
(motor-cmd motor "run-forever") )
(defun stop (motor)
(motor-cmd motor "stop") )
;; individual motor control
;;
;; NB 1: most often, these are not used directly, instead use
;; the interactive functions in ev3-motor-rotate.el,
;; ev3-motor-straight.el, etc
;;
;; NB 2: always set motor speed thru `set-motor'
;; in order to set both speed AND issue robot command
;; as well as to check that speed doesn't exceed the max speed
(defvar *max-speed* nil)
(defun set-motor (motor speed)
(let*((max-speed (or *max-speed* (setq *max-speed* 1050))) ;; TODO: get from file here
(min-speed (- max-speed) ))
(when (and (<= min-speed speed)
(<= speed max-speed) )
(set-motor-speed motor speed)
(if (zerop speed) (stop motor)
(run-forever motor) ))))
(defun set-motor-left (speed)
(set-motor 'left speed) )
(defun set-motor-right (speed)
(set-motor 'right speed) )
(defun set-motor-both (speed &optional right)
(set-motor 'left speed)
(set-motor 'right (or right speed)) )
(defun stop-motor-left ()
(set-motor 'left 0) )
(defun stop-motor-right ()
(set-motor 'right 0) )
(defun stop-motor-both ()
(stop-motor-left)
(stop-motor-right) )
(provide 'ev3-motor)
--
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal
next prev parent reply other threads:[~2020-10-21 14:24 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20201016144103.r3npeqap7uo63ney.ref@Ergus>
2020-10-16 14:41 ` Prompt issue with tramp shell Ergus
2020-10-16 14:48 ` Colin Baxter
2020-10-18 12:09 ` Daniel Martín
2020-10-18 14:37 ` Colin Baxter
2020-10-20 23:12 ` Ergus
2020-10-20 23:21 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-10-20 23:30 ` the Elisp robot [photo] (was: Re: Prompt issue with tramp shell) Emanuel Berg via Users list for the GNU Emacs text editor
2020-10-20 23:53 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-10-21 5:54 ` the Elisp robot [photo] Jean Louis
2020-10-21 6:08 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-10-21 6:25 ` Jean Louis
2020-10-21 6:41 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-10-21 12:28 ` Jean Louis
2020-10-21 14:24 ` Emanuel Berg via Users list for the GNU Emacs text editor [this message]
2020-10-21 17:48 ` Jean Louis
2020-10-21 22:48 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-10-21 23:06 ` Jean Louis
2020-10-21 23:33 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-10-22 9:55 ` Jean Louis
2020-10-22 16:34 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-10-22 16:55 ` Jean Louis
2020-10-22 17:42 ` Emanuel Berg via Users list for the GNU Emacs text editor
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=878sbzbqsn.fsf@ebih.ebihd \
--to=help-gnu-emacs@gnu.org \
--cc=moasenwood@zoho.eu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).