Bliss
Eurobricks Citizen-
Posts
171 -
Joined
-
Last visited
Content Type
Profiles
Forums
Gallery
Everything posted by Bliss
-
Dacta Control Lab Software
Bliss replied to Dazmundo's topic in LEGO Technic, Mindstorms, Model Team and Scale Modeling
I did not run into this situation yet but I'm not testing as much as you do I guess... I'm using Python 3.11. ... >>> from LegoClassB import LegoInterfaceB >>> Lego1=LegoInterfaceB() >>> Lego1.ComPort="COM14" >>> Lego1.StartLego() >>> Lego1.Inp[1].On False >>> Lego1.Out[1].On False >>> Lego1.Out[1].On=True >>> Lego1.Out[1].On=False >>> Lego1.Out[2].On=True >>> Lego1.Out[2].On=False >>> Lego1.IsRunning True -
Dacta Control Lab Software
Bliss replied to Dazmundo's topic in LEGO Technic, Mindstorms, Model Team and Scale Modeling
The lego Interface B code (Communication, Reading continuously and Decoding of Inputs and writing commands) is all done in what they call a C# Class which you can explore de code by opening the LegoInterfaceB.cs with notepad or Notepad++. LegoInterfaceB.cs is located in the complete zip package directly in the root folder (Ex. LegoClassB folder) When we compile a class it becomes a DLL (Library) and even in the LegoSciptB and LegoDemoB, there is a LegoInterfaceB.DLL but I tried to import it in Python and didn't work... I had to compile with a different .Net... -
Dacta Control Lab Software
Bliss replied to Dazmundo's topic in LEGO Technic, Mindstorms, Model Team and Scale Modeling
Anyway, I think you're right, IronPython integration to C# is probably very minimum... But since you aready have Python 3.X on your PC, you could do the other way around... Use Lego directly into python... You could use the Dacta Python program that you found here: https://www.shamlian.net/projects/dacta/index.html I did not personnaly had time to look at it. But I'm guessing it might work very well. OR You could use my Lego DLL directly in Python but there are few step to achieve this. I did some test and I will describe the steps I followed. I'm still very newbie at Python. I compiled the Lego Interface B program as a Class Library (DLL). Only the part that manages the Interface B, No IronPython. At first it did not work. To make it work, I had to compile it using .Net Framework 4.7... 1. You have to intall Python Net from the CLI (Command Line Interface, I just opened a Dos Command Window) You type in the command line: pip install pythonnet and press enter. Make sure it has installed properly. 2. Download my LegoClassB: Link to my LegoClassB 3. In python IDLE Shell or Python CLI, enter the command: import clr If pythonnet installed correctly there should be NO Error. 4. Now enter the following: (Please note the small "r" at the beginning of the path to tell to use raw string or you may get a problem because of the use of "\") LegoClassB is the name of the DLL without the extension DLL... clr.AddReference(r"C:\...\LegoClassB\bin\Release\LegoClassB") If things goes well, Python will respond with: <System.Reflection.RuntimeAssembly object at 0x000001BEF230C9C0> 5. Enter the following: from LegoClassB import LegoInterfaceB if there are no Errors, then you are in business. 6. Enter the following one at a time to declare the Lego1 Interface and configure the com port, start and try (Do the same for Lego2, Lego3, Lego4, Lego999 lol, but first lets make it work with Lego1) Lego1 = LegoInterfaceB() Lego1.ComPort="COM1" Lego1.StartLego() print(Lego1.IsRunning) Lego1.Out[1].On=True Let me know how it goes. I think that you should have more luck with having MQTT to run with Lego box at the same time... But still, there might be some surprises... -
Dacta Control Lab Software
Bliss replied to Dazmundo's topic in LEGO Technic, Mindstorms, Model Team and Scale Modeling
Here is an attempt to make a script for the first part of your train program (9V train part) . In that script, You have to change the com port, CN_Auto_Speed (I set it to 7), and the LightSp = 550 (Light Setpoint). The light setpoint is very different than you program which is Light < 70. Also, this appears to be reverse than the Value I programmed for the inputs. I suspect that ControlLab software/TC Logo is using a special calculation for the Light sensor. Me, I just take the raw 10 bits value... So might be a good Idea to use the LegoDemoB program to test the your Light8 and Light7 value when a train block the sensor and the value when it clrears the sensor. Then adjust the LightSp variable accordingly. So, in "while not C() and Light8.Val < LightSp :" , when Sensor is clear (sees the light), value is around 480 (For me), and the code is looping, and when Sensor is blocked, it gives a value over 620. So the loop will end when Sensor has a value > LightSp (550) import time Lego1.ComPort="COM14" Lego1.StartLego() time.sleep(1) C=lambda:cancellationToken.IsCancellationRequested LampB = Lego1.Out[out.B] SoundC = Lego1.Out[out.C] MotorD = Lego1.Out[out.D] LampF = Lego1.Out[out.F] MotorH = Lego1.Out[out.H] Touch4 = Lego1.Inp[4] Light7 = Lego1.Inp[7] Light8 = Lego1.Inp[8] LampB.Dir=True LampB.On=True MotorD.Dir=True MotorD.OnFor(20) time.sleep(2) SoundC.Dir=True SoundC.OnFor(20) time.sleep(2) CN_Auto_Speed=7 LightSp = 550 # Light Setpoint while not C(): MotorH.Dir = True MotorH.Pow = CN_Auto_Speed MotorH.On = True while not C() and not Touch4.On: pass MotorH.On = False LampF.On = True time.sleep(1) SoundC.Dir=False SoundC.On=True MotorH.Dir = False MotorH.On = True # backup until trigger light sensor while not C() and Light8.Val < LightSp : pass MotorH.On = False LampF.On = False SoundC.On=False MotorD.Dir=False MotorD.OnFor(20) time.sleep(2) break LampB.On=False Maybe it is because you tried first the code import sys sys.path.append(".\lib") And it worked . Then you change the path but the last one (.\lib) was still in memory (Once the parh is appended, i suspect it remains in the session even if you modify the script or clear the script textbox windows and run the script again with a new path append. But shuting down the LegoSriptB program completly must reset the memory... and when you run it again, or a new version, it will not find the random.py if you only append the ...site-packages folder because random.py does not exist in this folder. -
Dacta Control Lab Software
Bliss replied to Dazmundo's topic in LEGO Technic, Mindstorms, Model Team and Scale Modeling
This should work no? import sys sys.path.append("C:\\Users\Gunner\AppData\Local\Programs\Python\Python313\Lib\site-packages") sys.path.append("C:\\Users\Gunner\AppData\Local\Programs\Python\Python313\Lib") import random import paho.mqtt OR MAYBE JUST: import sys sys.path.append("C:\\Users\Gunner\AppData\Local\Programs\Python\Python313\Lib") import random import paho.mqtt -
Dacta Control Lab Software
Bliss replied to Dazmundo's topic in LEGO Technic, Mindstorms, Model Team and Scale Modeling
I made a small correction in LegoScriptB because there was a small glitch in the OnFor method... LegoScriptB Link For reference, here is LegoDemoB Link -
Dacta Control Lab Software
Bliss replied to Dazmundo's topic in LEGO Technic, Mindstorms, Model Team and Scale Modeling
It still work for me. Is random.py in "C:\\Users\Gunner\AppData\Local\Programs\Python\Python313\Lib\site-packages"? Should C:\\ be C:\ ? For me random.py is in ...AppData\Local\Programs\Python\Python313\Lib\. -
Dacta Control Lab Software
Bliss replied to Dazmundo's topic in LEGO Technic, Mindstorms, Model Team and Scale Modeling
I made a big change in the LegoScriptB program and the previous Examples will not work anymore. Please, use the examples provided in the README file. New version LegoScriptB Before: Lego1.SetOn[3] = True if Lego1.InOn == True: Now: Lego1.Out[3].On = True if Lego1.Inp[1].On: This allow us to do the following: MotorA = Lego1.Out[out.A] Touch1 = Lego1.Inp[1] Example: import time Lego1.ComPort="COM14" Lego1.StartLego() time.sleep(1) MotorA = Lego1.Out[out.A] Touch1 = Lego1.Inp[1] MotorA.Pow = 7 MotorA.Dir = False while not cancellationToken.IsCancellationRequested: MotorA.On = Touch1.On time.sleep(0.020) I also added a method in the outputs calle OnFor(Delay) Delay = 0-255 tenth of second. Lego1.Out[1].OnFor(20) will activate Output A of Lego1 for 2 seconds then deactivate it. It will not block the program flow, if you want to block, use after time.sleep(2) to wait 2 sec. -
Dacta Control Lab Software
Bliss replied to Dazmundo's topic in LEGO Technic, Mindstorms, Model Team and Scale Modeling
Actually, I'm using IronPython and I'm not sure what version of official Python it is using. -
Dacta Control Lab Software
Bliss replied to Dazmundo's topic in LEGO Technic, Mindstorms, Model Team and Scale Modeling
Seems that the Lego script B program does not embed this module. (I'msearching if it is even possible to embed some python modules in the exe...) But from what I found out, In the publish folder of Lego Script B, where the exe is also located, there is a lib sub folder with a bunch of .py modules... So, you could do this: import sys sys.path.append(".\lib") import random print(random.random()) -
Dacta Control Lab Software
Bliss replied to Dazmundo's topic in LEGO Technic, Mindstorms, Model Team and Scale Modeling
Hello, thanks for your interest! About the RCX, I already owned few of those but unfortunately I sold them all. I should have kept one at least :-) But as far as I remember, the serial/Infrared link between the PC and the RCX was only to send a program to the CPU inside the RCX (and to update/upload the firmware). The user program was running on the RCX in opposite of the lego interface B where the user program runs on a PC/MAC/Raspberry Pi etc. Lego Interface B is like a remote Input and Output passive device linked to a Main Programmable Logic Controller (PLC, yes I have a backgound in Industrial PLC Programming :-) ) RCX, is an integrated PLC that has it's own Local I/O's (Not remote). Unless you can put a firmware in the RCX that will make it acts has a dummy remote I/O gateway that waits for Output commands from its Infrared port and continuously sends sensors values to the IR port? I recall there was custom firmwares back in the days like NQC, (Not Quite C) and more... I did not check since if there was more custom firmwares available for the RCX. -
Dacta Control Lab Software
Bliss replied to Dazmundo's topic in LEGO Technic, Mindstorms, Model Team and Scale Modeling
@Gunners TekZone, Thanks for all the details. The logo program already talks a lot by itself without knowing much about this language. It's pretty simple. That gives me ideas to implement few more commands of the lego interface B that I did not yet tested... About the logo "onfor", I understand that this activates an output and deactivates after a delay, like onfor 20 will activate output for 2.0 seconds and deactivate output after the 2sec elapsed. But I wonder if the logo "onfor 20" will prevent any following instructions to execute unti the 2.0 delay has elapsed. So in the following for example, the MotorH will activate after 4 sec ?: (MotorD, which I believe is the track sw, activates for 2 sec, then after this 2 sec, MotorD stops, SoundC activates for 2 sec, then after this delay, sounds will stop and MotorH will activates. tto "MotorD setright onfor 20 tto "SoundC setright onfor 20 tto "MotorH setright setpower CN_Auto_Speed on According to you video and the timing, that's what it looks like. Right? Thanks again. -
Dacta Control Lab Software
Bliss replied to Dazmundo's topic in LEGO Technic, Mindstorms, Model Team and Scale Modeling
Nice. Can you paste somehow your TC Logo program? What are the inputs and outputs? I guess a picture of the program would be enough if cannot paste or have a text file... I never used the original control lab software... Maybe I should have tried it to get familiar with the functions. Could have given me some ideas... -
Dacta Control Lab Software
Bliss replied to Dazmundo's topic in LEGO Technic, Mindstorms, Model Team and Scale Modeling
I updated the LegoScriptB in the Dropbox link (See my post above). I just added the possibility to use out.A to out.H as the output port number for the output type properties (SetOn, SetFree, SetDir, SetPow). Ex.: Lego1.SetOn[3] , Lego1.SetOn[out.C] , Lego1.SetOn[out.c] are now allowed to activate/deactivate Output Port C. I also replaced SetON by SetOn (Lowercase N) and changed the example codes in my previous post... -
Dacta Control Lab Software
Bliss replied to Dazmundo's topic in LEGO Technic, Mindstorms, Model Team and Scale Modeling
Thanks! It appears I forgot to fix the same error we had in the LegoDemoB program... Here is the Fixed LegoScriptB program I also corrected the Example codes in my posts above. Some of them were not working because of some hidden characters ... -
Dacta Control Lab Software
Bliss replied to Dazmundo's topic in LEGO Technic, Mindstorms, Model Team and Scale Modeling
import time Lego1.ComPort="COM1" Lego1.StartLego() Lego2.ComPort="COM2" Lego2.StartLego() time.sleep(1) Lego2.SetPow[1] = 7 Lego2.SetDir[1] = False while not cancellationToken.IsCancellationRequested: if Lego1.InOn[1]: Lego2.SetOn[1] = True else: Lego2.SetOn[1] = False time.sleep(0.020) -
Dacta Control Lab Software
Bliss replied to Dazmundo's topic in LEGO Technic, Mindstorms, Model Team and Scale Modeling
I updated my previous post and the dropbox link because I forgot to include properties InTempC and InTempF... By the way, the password for the EXE standalone zip file is lego. If you use the Start Stop button to connect your Lego Interface B Box, you do not need to connect it in the script by using StartLego() method. (But you can do it also, It will see it is already started). Then, If you have a temp sensor on input 3, you can just write the following script and Run it: print("Temperature (C): ", Lego1.InTempC[3]) print("Temperature (F): ", Lego1.InTempF[3]) -
Dacta Control Lab Software
Bliss replied to Dazmundo's topic in LEGO Technic, Mindstorms, Model Team and Scale Modeling
Hello all. Happy new year! Here is a Draft of my C# project that embed IronPython as an attempt to make a programming environment for the Lego Interface B. Dropbox link : LegoScriptB for Programming Lego Interface B. It is based on my previous LegoDemoB project except that I removed all Lego Box Command Buttons and Status information. However, I left the Serial Start Stop buttons so you can still use them but it is not necessary as you can start and stop lego box from the script textbox. Features: - You can connect and use up to three (3) lego interface B. You can use Lego1, Lego2, Lego3 Variables. - Upon exiting the software, the last script in the textbox is saved. - In this version, there is no way to save to and load from files. - For now, I use Notepad++ to save some scripts in one file that I copy paste the parts I need in the Script textbox... - You probably can use many Python modules (import), for now I just used import time in my examples. - I will provide a text file eventually with all the Methods and Properties of the Lego variable. - You do not need to install Python. The exe is supposed to include all dependant libraries. - If your script has errors, the output box does not give very detailed msg. For example, it you forget a ":" colon for while or if, it will only log "invalid syntax". I'm trying to find a way to have more detailed error messages. I would suggest you try smaller parts of your code as it grows... Usual mistakes are lowercase, uppercase, indents, missing colon... How to use: - Be careful, Python is case sensitive (Lego1, True, False, print, while, etc) - In python, Indentation if VERY important. - You may comment your script with "#" symbol followed by you comment. - You enter your script in the "Enter you Python Script Here:" textbox. - To execute the script, click "RUN Script" button. - The Run Script button will be disabled during the execution of you script program. - The "STOP Loop Scipt" button is provided to allow to gracefully end an infinite While Loop. (See Example) - The use of while loop is tricky as you can be stucked in an infinite loop. You will have to shut down the whole Software. Please always use "while not cancellationToken.IsCancellationRequested:" rather than "while True:" Lego Variable Methods: - StopLego() : Stop Serial Communication with Lego box. Same as the STOP Button. Ex.: Lego1.StopLego() - StartLego() : Start Serial Communication with the Lgo box. Same as the START Button. (You must have set a valid COM port prior to use this method) Ex. Lego1.StartLego() Lego Variable Properties: - ComPort : Read/Write (R/W) COM port. Ex.: Lego1.ComPort = "COM14" - SetOn[OutPortNo] : (R/W), Where OutPortNo = 1 to 8 representing Output A to H. Ex.: Lego1.SetON[1] = True # Activates Output A. Lego1.SetOn[1] = False # Deactivates (BRAKES) Output A. - SetFree[OutPortNo]: (R/W), Where OutPortNo = 1 to 8 representing Output A to H. Ex.: Lego1.SetFree[1] = True # to inform to Coast to Stop then on a second line: . Lego1.SetOn[1] = False # Deactivates (Coast to Stop) Output A. - SetDir[OutPortNo]: (R/W), Where OutPortNo = 1 to 8 representing Output A to H. Ex.: Lego1.SetDir[1] = False # Set the direction of output A to CCW I think. If set to True, it's the opposite direction. You should set this property before SetON... - SetPow[OutPortNo]: (R/W), Where OutPortNo = 1 to 8 representing Output A to H. Accepts values 0 to 7. Ex.: Lego1.SetPow[1] = 7 # Sets the max power to Output A. - IsRunning: (Read Only), Tells if the Lego Box Serial Communication has been established, the Stop Led Light on the lego box should be OFF. Ex.: if Lego1.IsRunning: print("Lego Box is Running") - InOn[InputPort): (RO), Input port range is 0 to 8. 0 is the status of the Lego Box Stop Button. 1 to 8 are the Input port number. Reports True or False and follow the Led light status. Can be used for many sensors. Ex: if Lego1.InOn[1]: print("Lego1 input 1 is ON") - InVal[InputPort): (RO), Input port range is 1 to 8. 10 bit Value of input port. Ex. if Lego1.InVal[1] > 100: print("Input 1 value > 100) - InRotCW[InputPort): (RO), Input port range is 5 to 8. Status of the last direction reported by the rotation sensor. True (CW?) or False(CCW?). Ex.: if Lego1.InRot[5]: print("Lego 1 Input 5 Rotation ClockWise") - InRot[InputPort): (RW), Input port range is 5 to 8. Rotation sensor Count. You can Read or Set this property. Ex. Lego1.InRot[5] = 0 # Resets input 5 rotation sensor count to 0. if Lego1.InRot[5] > 48: print("Lego1 Rot Sensor 5 made at least 3 turns") - InTempC[InputPort] and InTempF[InputPort]: (RO), Input port range 1 to 4. Read the Temperature Sensor valur in celsius and fahrenheit. print(Lego1.InTempF[3]) # prints temp sensor value at input port 3. Script Examples: The following script connects Lego1 to COM14 port and prints the IsRunning status in the Output Log Textbox. Then it sets the power to max (7) and activates 4 outputs A, B, C, D. It Waits 3 seconds, then it Deactivates the 4 same outputs. Script ends. import time Lego1.ComPort="COM14" Lego1.StartLego() time.sleep(1) print("Lego 1 Running: ", Lego1.IsRunning) Lego1.SetPow[1] = 7 Lego1.SetPow[2] = 7 Lego1.SetPow[3] = 7 Lego1.SetPow[4] = 7 Lego1.SetOn[1] = True Lego1.SetOn[2] = True Lego1.SetOn[3] = True Lego1.SetOn[4] = True time.sleep(3) Lego1.SetOn[1] = False Lego1.SetOn[2] = False Lego1.SetOn[3] = False Lego1.SetOn[4] = False The following scipts has a While loop using the cancellationToken to be able to exit the loop with the STOP Loop Script button. You have to connect a Touch sensor to Input #1. You may connect a motor to Output 1. When executing the script, Press once on the Touch Sensor. The motor (Output 1) will Run for 3.5 sec, then stop for 1.5 sec, Reverse the direction, then start again for 3.5 sec and do this in a loop until you press again the Touch sensor. import time print("Script Running") Lego1.ComPort="COM14" Lego1.StartLego() time.sleep(1) print("Lego 1 Running: ", Lego1.IsRunning) Lego1.SetPow[1] = 7 Lego1.SetDir[1] = False seq_en=False wait_en=False m1=False # m1 is a memory used to simulate a ONE SHOT over the Input 1 to avoid hunting effect... print("Sequence Disabled") while not cancellationToken.IsCancellationRequested: if Lego1.InOn[1]: if not m1: m1=True if not seq_en: ti=time.time() + 3.5 seq_en = True print("Sequence Enabled") else: seq_en= False print("Sequence Disabled") else: m1=False if seq_en: if not wait_en: if time.time()<ti: Lego1.SetOn[1] = True else: Lego1.SetOn[1] = False tw=time.time()+1.5 wait_en = True else: if time.time()>tw: Lego1.SetDir[1] = not Lego1.SetDir[1] ti=time.time() + 3.5 wait_en=False else: Lego1.SetOn[1] = False time.sleep(0.020) # 20ms scan time. Not mandatory but I thought it might help ressources. Anyway, legobox scantime is around 20-30 ms Lego1.SetOn[1] = False Simple Loop script to make output 1 follow input 1 import time Lego1.ComPort="COM14" Lego1.StartLego() time.sleep(1) Lego1.SetPow[1] = 7 Lego1.SetDir[1] = False while not cancellationToken.IsCancellationRequested: if Lego1.InOn[1]: Lego1.SetOn[1] = True else: Lego1.SetOn[1] = False time.sleep(0.020) Can be even simpler: import time Lego1.ComPort="COM14" Lego1.StartLego() time.sleep(1) Lego1.SetPow[1] = 7 Lego1.SetDir[1] = False while not cancellationToken.IsCancellationRequested: Lego1.SetOn[1] = Lego1.InOn[1] time.sleep(0.020) -
Dacta Control Lab Software
Bliss replied to Dazmundo's topic in LEGO Technic, Mindstorms, Model Team and Scale Modeling
I updated the LegoDemoB in Dropbox. Added automatic Com port list refesh on clicking the dropdown of the combobox. Added colored Start/Stop Lego Box Buttons. LegoDemoB Program Dropbox Link -
Dacta Control Lab Software
Bliss replied to Dazmundo's topic in LEGO Technic, Mindstorms, Model Team and Scale Modeling
@Gunners TekZone, I updated the dropbox. For the slider position vs start/stop of the lego box, after a stop, it will reset to max, but when starting again the box, the slider will come back to the last position but not if you activate an output, it will use this setting not the max like before. If it is preferable, i could also after a stop reset all slider to the max and keep the max when clicking the start again. I'm talking here about start/stop of the box in a same session. If the program is shutdown and re-executed, sliders will initialize at max. I also found another bug: If there is NO com port on the PC, the program do the ghost thing because there was of an error not displayed but shown in the windows log events. The program was initialzing with first com port, item 0 but there was no item. Now it is allowed to start the program without com port in the PC but the combo box does not refresh if you plug a serial usb adapter while the program is running. Have to restart the program... I guess would need a refresh com list button eventually... Bliss -
Dacta Control Lab Software
Bliss replied to Dazmundo's topic in LEGO Technic, Mindstorms, Model Team and Scale Modeling
Good find. Will try to fix later on. Actually for this project, Controlling one box only would be enough as you found out that you can run more than one instance of the program allowing connecting to many lego interface B independly. So I do not intend to add a Lego 3, at least not now. (Maybe I should even remove the second Lego from this demo project... ) However, for my other project, yes, I can eventually allow more than 2... Thank you. -
Dacta Control Lab Software
Bliss replied to Dazmundo's topic in LEGO Technic, Mindstorms, Model Team and Scale Modeling
Hello, you may check back the Dropbox link in my previous post. I "published" using Fodi addon to make sure the exe in the publish folder was really a standalone. Because sometime, If I copy this exe alone in another folder and try to execute, it will ghost. But if I copy the whole publish folder with all its content, then the exe opens the form fine... Thank you! -
Dacta Control Lab Software
Bliss replied to Dazmundo's topic in LEGO Technic, Mindstorms, Model Team and Scale Modeling
Thank you. I just implemented those 3 items (Without calibration for the moment). Updated Dropbox LegoDemoB files Let me know. Bliss -
Dacta Control Lab Software
Bliss replied to Dazmundo's topic in LEGO Technic, Mindstorms, Model Team and Scale Modeling
So I did get this ghost behavior when I copied the exe to another directory on my computer. So I deleted ALL files and folders in my visual studio build bin folders and recompiled everything... I updated the Dropbox link above that I still include here: LegoDemoB recompiled files Thanks for your help. -
Dacta Control Lab Software
Bliss replied to Dazmundo's topic in LEGO Technic, Mindstorms, Model Team and Scale Modeling
I checked the visual studio project settings and it appears to be compiling for windows 7, win-x86... Maybe it does not do for 32 bits version I don't know. Did you right click on the exe file, properties, compatibility tab and force for windows 7?