Closed Ruimtewese closed 10 months ago
@Ruimtewese your code doesn't seem correct (at least for HubOS v2). Are you perhaps using HubOS v3?
Here is what the mindstorms app give me as an example for light_matrix:
from mindstorms import MSHub
hub = MSHub()
hub.light_matrix.write('Hello!')
# Show the number "1" on the Light Matrix.
hub.light_matrix.write('1')
So you need to create an instance of the hub and then use the light_matrix
object from there.
And a similar example to your second code:
from mindstorms import Motor
motor_a = Motor('A')
# Run the motor 90 degrees clockwise at 30% speed.
motor_a.run_for_degrees(90, 30)
# Run the motor 90 degrees counterclockwise at maximum (100%) speed.
motor_a.run_for_degrees(-90, 100)
# Run the motor 360 degrees clockwise at default speed.
motor_a.run_for_degrees(360)
Thanks for your prompt reply.
Your new code solves the "could not be resolved" issue (problem 2). However, problem 1 persisted. I am not sure how to check the hub version but vsc seems to be connected to LEGO Hub: Connected (1.5.6.0/3.2.36). Does that maybe suggest HubOS v3?? Which would mean the VSC extension will not function correctly?
We have found the issue...
We did not realize that the upload and start is separated. Now that we have done an upload, followed by play, it seems to be working.
@PeterStaev, I still have some problem understanding what is happening in VSC. Using the code example below.
# LEGO type:standard slot:10 autostart
from mindstorms import MotorPair, ColorSensor, Motor
motor_a = Motor('A')
motor_b = Motor('B')
motor_pair = MotorPair('B', 'A')
color_sensor = ColorSensor('E')
motor_with_indicator = Motor('F')
distance_max = 40
motor_a.set_degrees_counted(0)
motor_b.set_degrees_counted(0)
circumferece = 17.5
a_relatvie_posision = 0
distance_between_wheels = 160
diameter_wheel = 55
turning_factor = distance_between_wheels / diameter_wheel
while circumferece/360*a_relatvie_posision < distance_max:
steering = color_sensor.get_reflected_light() - 50
motor_pair.start_at_power(50, steering)
motor_with_indicator.start(100)
a = motor_a.get_position()
b = motor_b.get_position()
c = motor_with_indicator.get_position()
a_relatvie_posision = motor_a.get_degrees_counted()
#print("%i, %i, %i, %i" %(a, aa, b,c))
motor_pair.stop()
motor_with_indicator.stop()
motor_pair.move_tank(90 * turning_factor, 'degrees', 50, -50)
The code seems to be uploading and running fine. However, the syntax highlighting and auto complete suggestions are not working correctly.
It seems that VSC does not find the 'mindstorms' source files and reports this error message:
How can I get to the underlying/related libraries? Does the extension bundle the required lego packages needed at upload time?
Or am I missing something?
@Ruimtewese this extension does not provide autocomplete (yet). You can check the comment here that provides a workaround: https://github.com/PeterStaev/lego-spikeprime-mindstorms-vscode/issues/29#issuecomment-1166307963
The packages that are underlined are present on the hub itself so they are not bundled but the code can execute fine on the hub.
@PeterStaev thanks for the speedy reply.
The work around seems to work, also for Mindstorms using the decoy 'mindstorms.py' file. See screenshot below.
I have successfully installed this extension and is trying to use it with Robot Inventor. VSC and the Hub connects, no problem.
Problem 1: However, when uploading simple code, the tune for uploading plays, but is shortly afterwards followed by the code terminated jingle.
The code I have tried:
from hub import light_matrix
light_matrix.write('Hello, World!')
Problem 2: Also, for the following code (and unrelated to problem1):
import motor
from hub import port
# Run a motor on port A for 360 degrees at 720 degrees per second.
motor.run_for_degrees(port.A, 360, 720)
VSC gives this message: "Import "motor" could not be resolved" which seems to be that it can not find these libraries. Should I have installed the these libaries should where else? The standard LEGO IDE is working fine.
Can you provide me with some help on this matter/