I would like to receive a value sent by the console in UCS (to change the value of a variable), like the “Serial.read()” of the C language.
How could I do this ?
Thanks for your help !
I don’t understand how to use this to get a value that the user enters in the console .
I would like, that, with a print() with the python command in UCS, the program asks the user to enter a number in the console, then, the user enter a number, and the program put it into a variable.
But i can’t find a way to do this because the input() doesn’t work …
An idea ?
Ah ok, sounds more just like a python question how to get keyboard input. You can refer to python - How to read keyboard input? - Stack Overflow for example, it gets the input in a string format then converts it into a integer.
There should be a lot of other references on the internet as well.
I tried “nb = raw_input('Choisis un nombre : ')” and the program stoped with this message in the console :
-----------------------------------ERROR-----------------------------------
Traceback (most recent call last):
File “x:\project\metal\python\GUI\GUI\Logic\Interpreter.py”, line 293, in evaluateScript
File “”, line 1, in
NameError: name ‘raw_input’ is not defined
---------------------------------------------------------------------------
I also tried nb = input('Choisis un nombre : ') and it did the same thing with this message :
-----------------------------------ERROR-----------------------------------
Traceback (most recent call last):
File “x:\project\metal\python\GUI\GUI\Logic\Interpreter.py”, line 293, in evaluateScript
File “”, line 1, in
RuntimeError: input(): lost sys.stdin
---------------------------------------------------------------------------
You can try input() in command line to see if it works:
$ python
Python 2.7.10 (default, Aug 26 2015, 09:29:31)
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> a = input()
123 # type '123' here
>>> a
123
I’m confused
I’m a big beginner and I don’t know what is “command lines” with uarm, moreover I only know how to program in C so python is very new for me
In fact, if I understand, there is no way to enter a value in a variable when the program is playing in UCS ?
(Sorry for my bad english, i’m french )
A more common way is to use the GUI, which is probably what you have been using, in which case getting input from keyboard directly may not be that straight forward and likely requires changing the code base.
For beginners, you can use the GUI interface to define where the robot needs to go based on the tutorial above.
Aaa ok !
I don’t think that I have the level to use command lines
so I will, instead of setting the value of the variable with the console, assign keys to increment or decrement it !
Thanks a lot for your help !
It’s thanks to guys like you that uarm become accessible to beginners, even to program complexe tasks ! Thanks !