Jump to content
THIS IS THE TEST SITE OF EUROBRICKS! ×
THIS IS THE TEST SITE OF EUROBRICKS!

Recommended Posts

  • Replies 94
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

Posted

Also for one of the motors? Not both. I will check it out, thanks.

I can’t wait for my metal axles and other stuff (big battery, screens) to arrive so I can rebuild my robot. Working on version 6.2 and I have a good feeling about this one :thumbup:

Posted
6 hours ago, dwalton76 said:

You can pass set_polarity() a list of motor objects to tweak

Can you maybe send me an example, because I am trying to figure out how to call the method. I can't seem to get the syntax right :hmpf_bad:

Posted
On 12/18/2018 at 1:42 PM, Jim said:

Can you maybe send me an example, because I am trying to figure out how to call the method. I can't seem to get the syntax right :hmpf_bad:

 

from ev3dev2.motor import MoveTank, OUTPUT_A, OUTPUT_B, LargeMotor, SpeedRPM

robot = MoveTank(OUTPUT_A, OUTPUT_B)
robot.set_polarity(LargeMotor.POLARITY_INVERSED, [robot.left_motor,])

This should do the trick. The second argument to set_polarity() is a list of motors that you want to change the polarity for.

Posted

I have been trying to get the polarity to work, but I am still drawing a blank. Since I am working with a stacked BrickPi, my syntax is a bit different. I can't use the "spi0.1MC" string in the polarity function. 

wheel_a = MoveTank("spi0.1:MC", "spi0.1:MH")
wheel_b = MoveTank("spi0.1:ME", "spi0.1:MB")
wheel_c = MoveTank("spi0.1:MF", "spi0.1:MG")
wheel_d = MoveTank("spi0.1:MA", "spi0.1:MD")

wheel_a.set_polarity(LargeMotor.POLARITY_INVERSED, ["spi0.1:MC",])

 

After tinkering a bit, this seems to work:

motor_a = LargeMotor('spi0.1:MA')
motor_b = LargeMotor('spi0.1:MB')
motor_c = LargeMotor('spi0.1:MC')
motor_d = LargeMotor('spi0.1:MD')
motor_e = LargeMotor('spi0.1:ME')
motor_f = LargeMotor('spi0.1:MF')
motor_g = LargeMotor('spi0.1:MG')
motor_h = LargeMotor('spi0.1:MH')

wheel_a = MoveTank("spi0.1:MC", "spi0.1:MH")
wheel_b = MoveTank("spi0.1:ME", "spi0.1:MB")
wheel_c = MoveTank("spi0.1:MF", "spi0.1:MG")
wheel_d = MoveTank("spi0.1:MA", "spi0.1:MD")

wheel_a.set_polarity(LargeMotor.POLARITY_INVERSED, [motor_c,])
wheel_b.set_polarity(LargeMotor.POLARITY_INVERSED, [motor_e,])
wheel_c.set_polarity(LargeMotor.POLARITY_INVERSED, [motor_f,])
wheel_d.set_polarity(LargeMotor.POLARITY_INVERSED, [motor_a,])
Posted

When I am running a test program, I sometimes have issues with the wait function. Instead of waiting for one second, it seems to be waiting forever, making the robot go berserk. I decided to implement a touch sensor the abandon the program when things go south. But my robot doesn't recognize my sensor. I have tried every port, multiple touch sensors, but it says that the sensor is not connected. This is my code:

from ev3dev2.motor import LargeMotor, Motor, SpeedPercent, MoveTank 
from ev3dev2.sensor import INPUT_1, INPUT_2
from ev3dev2.sensor.lego import TouchSensor

touch_1 = TouchSensor("spi0.1:S2")

When I used INPUT_2, instead of "spi0.1:S2", I got an error message stating that "spi0.1.S2" was not connected, so I reckoned I could use the stacked BrickPi notation.

Maybe I need to wait a bit before posting it here, but it might help others with the same issues. I have found the solution. You need to define which port it is, before creating the touch sensor, so this works:

port_2 = ev3.LegoPort("spi0.1:S2")
port_2.mode ="ev3-analog"
port_2.set_device = "lego-ev3-touch"

touch_1 = TouchSensor("spi0.1:S2")

 

Posted

The next issue I am facing is that sometimes my program has a rather erratic flow and hangs somewhere. This results in the motors turning forever. But before I bother you with this one, I will put some time in debugging the issue. Version 6.2 of my robot is done and I can start fiddling around with Python again.

Posted
On 12/29/2018 at 8:41 AM, Jim said:

I have been trying to get the polarity to work, but I am still drawing a blank. Since I am working with a stacked BrickPi, my syntax is a bit different. I can't use the "spi0.1MC" string in the polarity function. 


wheel_a = MoveTank("spi0.1:MC", "spi0.1:MH")
wheel_b = MoveTank("spi0.1:ME", "spi0.1:MB")
wheel_c = MoveTank("spi0.1:MF", "spi0.1:MG")
wheel_d = MoveTank("spi0.1:MA", "spi0.1:MD")

wheel_a.set_polarity(LargeMotor.POLARITY_INVERSED, ["spi0.1:MC",])

 

FYI all of the spi strings are defined:

ddwalton@ddwalton-mbp[_platform]# grep spi *.py
brickpi3.py:OUTPUT_A = 'spi0.1:MA'
brickpi3.py:OUTPUT_B = 'spi0.1:MB'
brickpi3.py:OUTPUT_C = 'spi0.1:MC'
brickpi3.py:OUTPUT_D = 'spi0.1:MD'
brickpi3.py:OUTPUT_E = 'spi0.1:ME'
brickpi3.py:OUTPUT_F = 'spi0.1:MF'

You can import them via

from ev3dev2.motor import OUTPUT_A, OUTPUT_B, OUTPUT_C

Same goes for the INPUT strings

On 12/29/2018 at 8:41 AM, Jim said:

I have been trying to get the polarity to work, but I am still drawing a blank. Since I am working with a stacked BrickPi, my syntax is a bit different. I can't use the "spi0.1MC" string in the polarity function. 


wheel_a = MoveTank("spi0.1:MC", "spi0.1:MH")
wheel_b = MoveTank("spi0.1:ME", "spi0.1:MB")
wheel_c = MoveTank("spi0.1:MF", "spi0.1:MG")
wheel_d = MoveTank("spi0.1:MA", "spi0.1:MD")

wheel_a.set_polarity(LargeMotor.POLARITY_INVERSED, ["spi0.1:MC",])

 

After tinkering a bit, this seems to work:


motor_a = LargeMotor('spi0.1:MA')
motor_b = LargeMotor('spi0.1:MB')
motor_c = LargeMotor('spi0.1:MC')
motor_d = LargeMotor('spi0.1:MD')
motor_e = LargeMotor('spi0.1:ME')
motor_f = LargeMotor('spi0.1:MF')
motor_g = LargeMotor('spi0.1:MG')
motor_h = LargeMotor('spi0.1:MH')

wheel_a = MoveTank("spi0.1:MC", "spi0.1:MH")
wheel_b = MoveTank("spi0.1:ME", "spi0.1:MB")
wheel_c = MoveTank("spi0.1:MF", "spi0.1:MG")
wheel_d = MoveTank("spi0.1:MA", "spi0.1:MD")

wheel_a.set_polarity(LargeMotor.POLARITY_INVERSED, [motor_c,])
wheel_b.set_polarity(LargeMotor.POLARITY_INVERSED, [motor_e,])
wheel_c.set_polarity(LargeMotor.POLARITY_INVERSED, [motor_f,])
wheel_d.set_polarity(LargeMotor.POLARITY_INVERSED, [motor_a,])

So the motor_a, etc objects that you are creating are not going to be used by MoveTank, MoveTank is going to create its own LargeMotor objects.  So what you have above will work but this is going down a path that could be very confusing to troubleshoot later :(  Something like the following would be much cleaner

 

wheel_a = MoveTank(OUTPUT_A, OUTPUT_B)
wheel_c = MoveTank(OUTPUT_C, OUTPUT_D)

wheel_a.set_polarity(LargeMotor.POLARITY_INVERSED, [wheel_a.left_motor,])
wheel_c.set_polarity(LargeMotor.POLARITY_INVERSED, [wheel_c.left_motor,])

 

On 12/29/2018 at 9:41 AM, Jim said:

When I am running a test program, I sometimes have issues with the wait function. Instead of waiting for one second, it seems to be waiting forever, making the robot go berserk. I decided to implement a touch sensor the abandon the program when things go south. But my robot doesn't recognize my sensor. I have tried every port, multiple touch sensors, but it says that the sensor is not connected. This is my code:


from ev3dev2.motor import LargeMotor, Motor, SpeedPercent, MoveTank 
from ev3dev2.sensor import INPUT_1, INPUT_2
from ev3dev2.sensor.lego import TouchSensor

touch_1 = TouchSensor("spi0.1:S2")

When I used INPUT_2, instead of "spi0.1:S2", I got an error message stating that "spi0.1.S2" was not connected, so I reckoned I could use the stacked BrickPi notation.

Maybe I need to wait a bit before posting it here, but it might help others with the same issues. I have found the solution. You need to define which port it is, before creating the touch sensor, so this works:


port_2 = ev3.LegoPort("spi0.1:S2")
port_2.mode ="ev3-analog"
port_2.set_device = "lego-ev3-touch"

touch_1 = TouchSensor("spi0.1:S2")

 

brickpi cannot auto detect the sensors so you have to use set_device() to specify what is connected on what ports.  I don't have a code example handy but if you search in the ev3dev-lang-python repo for set_device() you should be able to find an example (there may be an example in the docs also...not sure).

Can you post the code you are using where the motors go beserk?

Posted
7 minutes ago, dwalton76 said:

brickpi cannot auto detect the sensors so you have to use set_device() to specify what is connected on what ports.  I don't have a code example handy but if you search in the ev3dev-lang-python repo for set_device() you should be able to find an example (there may be an example in the docs also...not sure).

Can you post the code you are using where the motors go beserk?

I solved the sensor issue (see my comments).

I will do some more testing with motors and program flow and when I face errors, I will post them here. I haven't done enough testing to properly judge whether I have made mistakes myself.

11 minutes ago, dwalton76 said:

 


wheel_a = MoveTank(OUTPUT_A, OUTPUT_B)
wheel_c = MoveTank(OUTPUT_C, OUTPUT_D)

wheel_a.set_polarity(LargeMotor.POLARITY_INVERSED, [wheel_a.left_motor,])
wheel_c.set_polarity(LargeMotor.POLARITY_INVERSED, [wheel_c.left_motor,])

 

Thanks!  That looks great. I had some troubles with the "left_motor" not being recognizes. But it does seem to compile this way.

I will invest some time to write a proper program and I will post it here, so you can take a look.

  • 3 weeks later...
Posted
1 hour ago, pasquentmax said:

Hello, what are the advantages of programming in python? does this give other possibilities to the ev3 lego?

You mean the default graphical EV3 software (EV3-G)?

Python is a full blown programming languages with all the bells and whistles. If you are comfortable with writing computer software, using Python will give you better options to structure your project and implement functionality. When projects grow bigger, maintaining a EV3-G program can be cumbersome.

Posted
10 hours ago, pasquentmax said:

Hello, what are the advantages of programming in python? does this give other possibilities to the ev3 lego?

Like Jim said, python, java, C or any other high level languages may allow big structered projects but don't give "per se" other possibilities to EV3. In some cases you may even lack some EV3 possibilities (like daisy chaning, still being addressed by ev3dev project). But when used on a full operating system like ev3dev then lots of other possibilities arise.

For a start, you have the full network stack. So you can use standard network protocols with your EV3. And also other linux stacks, like BueZ (Bluetooth) and ALSA (Audio). So you can pair your EV3 with a bluetooth speaker or an USB audio card and get decent sound. Or use your EV3 as a MIDI device.

Then you have the device support from the kernel. That means some LEGO devices that Linux still supports (like the old LEGOCam and the original WeDo 1.0) can be used with your EV3. And some NXT devices that no longer work with the current EV3 firmware can still be used as well (like the RFID sensor or the IRLink). And lots of non-LEGO devices - like USB fingerprint readers.

Now mixing all this can be difficult. And that's where I think python shines, not because it's a better language but because there is an huge amount of libraries available so you don't need to re-invent the wheel. Like complex mathematics or image and audio processing.

Posted

I was able to do all the steps as listed on the EV3Dev.org website. I think I did all the steps correctly. I was able to do the hello.py program to run on my EV3. But, when I try something more advanced like LED or motors I get an error message that says it is unable to import 'ev3dev.motor' [E0401] I tried following the notes to change how the editor does line feeds from CR to LF but I still get the error message. any help would be greatly appreciated.

Mike,

Posted

Interestingly, although I get an error message stating that it cannot find the ev3dev.motor to import. When I run the program from the EV3 brick it works????

I redid all the steps to change the CR to LF behavior but still have the error message or messages depending on how many imports I use.

Posted

@MichaelWareman I have merged your question with my Python topic. I am not sure why it isn't working for you. I need to check my code, to compare it with my program. I can do this later.

  • 4 months later...
  • 5 years later...
Posted (edited)

This looks like it might be the correct topic to talk about this issue in...

I'm working on a project using a Mindstorms EV3 running EV3dev with Python coding. I had written my code and gotten everything working the way I wanted, and had successful tests, but then the rechargeable AA batteries I was using in it died. I'd been wanting to have it powered from the wall eventually, so while I was charging them, I rigged up a basic battery eliminator sort of thing, with the positive and negative contacts wired to the contacts of a USB-chargeable 9V battery, which I then plugged in via USB. After doing this, it booted up just fine, but a couple other issues became apparent. When I went to the File Browser on the brick and tried to select my program as before, nothing would happen, except that a new file under it would appear with the name main.py.err.log, and the same thing would happen for any program loaded on to the brick. Second, when I plugged it back into my computer over USB and tried re-connecting to VSCode, it would start the process, and then fail, giving me me an "Exit code 127" message. After that I wondered if I just didn't have enough amperage, so I plugged it in to a 9V transformer, with the same symptoms of powering on but not working. I then put AA batteries back in, and it still didn't work right! I also tried removing the EV3Dev SD card, rebooting, powering down, reinserting it, and rebooting again, but nothing changed.

Does anyone have any idea what's going on here? It's a core part of a larger project that I've been working hard at for a good while, and that I had pretty much just got working, so I'd be really disappointed if I couldn't get it working again!

Any help would be appreciated!

[EDIT] My next step will probably be restoring the stock firmware and seeing if I can get programs to run on it. If that works, perhaps I could just rewrite my code in whatever the standard is for EV3 and go with that? Or maybe I need to try reflashing the EV3dev SD card

Edited by 2GodBDGlory

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.

Announcements

  • THIS IS THE TEST SITE OF EUROBRICKS!

×
×
  • Create New...