ev3dev / ev3dev-lang-python

Pure python bindings for ev3dev
MIT License
425 stars 144 forks source link

New Wheel #712

Closed kpu979 closed 4 years ago

kpu979 commented 4 years ago

Hi, Im a programmer by trade, but a total newbie to Python, especially for EV3.

I need to add a new wheel. It's the Motorcycle wheel (part: 88517c02) (100.6 D, 17 W). I created the class in the wheel.py file. VSCode recognizes it, but when trying to run the code on the EV3, I get the following: File "/home/robot/vscode-hello-python-master/hello.py", line 8, in from ev3dev2.wheel import MCTire ImportError: cannot import name 'MCTire'

What am I missing?

dwalton76 commented 4 years ago

I am not familiar with the workflow for using VSCode to edit and deploy changes to ev3dev-lang-python but I can walk you through how to get this up and running (just not using VSCode).

kpu979 commented 4 years ago

Thanks for the response. If I edit this file on the EV3 itself, what will prevent this file from being overwritten when I update (sudo apt-get install --only-upgrade python3-ev3dev2)?

It seems to me there has to be a better way to edit these files and get them to the EV3.

Is it possible to add this wheel config into code base?

kpu979 commented 4 years ago

I was thinking through this issue, and came to a conclusion that perhaps making a generic Wheel definition possible to allow the user of this to input their own wheel configurations. As a programmer myself, I dislike hard coding values so I typically make the users input their own values or have these values data-driven from tables.

Anyway, here's the code I came up with. It is not tested (I don't know how to actually change these classes on the EV#. The instruction above were great, but the git clone command failed :( ). And, like I said above, Im a total newbie to Python, so there may be lots of bugs nor the proper way of doing things with Python, but I present this code as a concept, and I hope you can include this into the wheel.py code... once properly coded and tested.

(addition to wheel.py) . . . class GenTire(Wheel): """ Generic Tire definition

Arguments:

tire_diameter tire_width

example: from ev3dev2.wheel import MoveDifferential from ev3dev2.wheel import GenTire

tire = Gentire(100.6,17)

mdiff = MoveDifferential(OUTPUT_B, OUTPUT_C, tire, 112) mdiff.on_arc_right(SpeedRPM(50), 90, 100)

"""

def __init__(self,tire_diameter,tire_width):
    Wheel.__init__(self, tire_diameter, tire_width)        
WasabiFan commented 4 years ago

You can add this class to your own code; it doesn't need to be part of this library's codebase. Adding your new class in your own file should work as long as you import Wheel.

kpu979 commented 4 years ago

Hi and thanks for the response!

Again, Im a total newbie to Python, and Im sure what you suggested makes total sense, but im lost as to how to import Wheel and how to integrate the class into my .py file and incorporating the wheel class. :(

kpu979 commented 4 years ago

ok... I figured it out:

from ev3dev2.wheel import Wheel

class MCTire(Wheel): def init(self): Wheel.init(self, 100.3, 17)

Thanks for your help and patience with this newbie.

kpu979 commented 4 years ago

@dwalton76 -- I tried to follow your instructions. When I do this: git clone https://github.com/ev3dev/ev3dev-lang-python.git --- I get this: Cloning into 'ev3dev-lang-python'... fatal: unable to access 'https://github.com/ev3dev/ev3dev-lang-python.git/': Could not resolve host: github.com

My EV3 is connected to my laptop via bluetooth.

dlech commented 4 years ago

Your EV3 needs to be connected to the Internet. If your laptop runs Windows, it is not possible to use Internet Connection Sharing with Bluetooth, so you need to use USB or Wi-Fi instead.

kpu979 commented 4 years ago

@dlech -- Thank you!!!! I've successfully connected my EV3 via usb to my mac and shared out the internet to it.

The issue now is when I download/run hello.py from VSCode, it fails... but when I run the code via SSH (or directly from EV3, it works. Its a cludgy workflow, but I'll work with this for now.