Git Product home page Git Product logo

Comments (4)

PeterStaev avatar PeterStaev commented on June 5, 2024

Hey @ADScomics , when you say "terminate a program" do you mean the command that the plugin provides or you terminate it in the Python code?

from lego-spikeprime-mindstorms-vscode.

ADScomics avatar ADScomics commented on June 5, 2024

Hi @PeterStaev, It's when I terminate it with the plugin command via the button next to 'play'. Even just pressing the home button to exit the program does not seem to work for me either. Here's my code if it helps at all. The program itself seems to run properly (Although I'm not sure where it's accessing the code libraries on the top).

# LEGO type:standard slot:1 autostart

from mindstorms import MSHub, Motor, MotorPair, ColorSensor, DistanceSensor, App
from mindstorms.control import wait_for_seconds, wait_until, Timer
from mindstorms.operator import greater_than, greater_than_or_equal_to, less_than, less_than_or_equal_to, equal_to, not_equal_to
import math


# Create your objects here.
hub = MSHub()
eyes = DistanceSensor('A')
foldingMechanism = MotorPair('C', 'D')
steeringMechanism = Motor('B')
rearWheels = Motor('E')
speed = 0
def BackUp():
    global speed
    speed = 0
    speed = 30
    if (dist > 60):
        speed = 0

# Write your program here.
#hub.light_matrix.write('Initialized!')
hub.light_matrix.write('Hi!')
hub.light_matrix.write('Hey!')
hub.speaker.start_sound('Hi',100)
while True:
    dist = eyes.get_distance_cm()
    rearWheels.start(speed)
    if hub.right_button.is_pressed():
        speed = -100
    if hub.left_button.is_pressed():
        speed = 0
    #if dist != None and dist < 30:
     #   BackUp()

from lego-spikeprime-mindstorms-vscode.

PeterStaev avatar PeterStaev commented on June 5, 2024

From what I see from your code you have an endless loop on the main thread. This is what stalls the hub and that's why the central button does not end the program. If you try the same code in the Mindstorms/SPIKE app probably the result will be the same 😃

from lego-spikeprime-mindstorms-vscode.

ADScomics avatar ADScomics commented on June 5, 2024

Gah, that was it! Strangely enough, the Mindstorms app didn't have that same issue, although uploading and running the code was finicky a lot, so maybe that had something to do with it. Thanks for your help! I come from object oriented programming in C sharp, so Python is very new to me. 😅

from lego-spikeprime-mindstorms-vscode.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.