Python Forum
Robot Stay Inside Circular Ring
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Robot Stay Inside Circular Ring
#1
I have a Lego Mindstorms brick running ev3dev (open source Linux) and I am writing a Python program for it. I want to enter it in a friendly Sumo style robot competition. Two robots are put inside a circular ring and whoever pushes their opponent outside the ring wins. So I need an "avoid the line" or "stay inside the black line circle" program.

Here is an example video wwwDOTyoutubeDOTcom/watch?v=3tguWcKTXQI&t=110s
I still have to clarify exactly what the ring will be, black area outlined by white, or something different. But I think I can assume I'll be avoiding a bold black line, and I can change that later if I need to.

I'm running ev3dev, brickman v.0.8.0, kernel 4.4.24-16-ev3dev-ev3 on a Lego Mindstorms EV3 programmable brick, revision 0006
I'm using PyCharm IDE and I push the code to the brick over WiFi.

Error:
<ev3dev.core.LargeMotor object at 0xb6903e30>> ignored robot@ev3dev:~/myproject$ python col-reflect-driveaway-v.2016.12.05.n01.py 0 Traceback (most recent call last):   File "col-reflect-driveaway-v.2016.12.05.n01.py", line 38, in <module>     m2.reset()   File "/usr/lib/python2.7/dist-packages/ev3dev/core.py", line 738, in reset     self.command = 'reset'   File "/usr/lib/python2.7/dist-packages/ev3dev/core.py", line 295, in command     self.set_attr_string('command', value)   File "/usr/lib/python2.7/dist-packages/ev3dev/core.py", line 216, in set_attr_string     self._set_attribute(attribute, "{0}".format(value))   File "/usr/lib/python2.7/dist-packages/ev3dev/core.py", line 204, in _set_attribute     self._attribute_cache.write(abspath(self._path + '/' + attribute), value) AttributeError: 'LargeMotor' object has no attribute '_path' Exception AttributeError: "'LargeMotor' object has no attribute '_path'" in <bound method LargeMotor.__del__ of <ev3dev.core.LargeMotor object at 0xb6960e30>> ignored robot@ev3dev:~/myproject$ 
Program
#!/usr/bin/env python3
# so that script can be run from Brickman

# I amd combining a "bump into wall, back up, turn 45 degrees, drive forward" program
# and a color sensor col-reflect program
# This is for a "sumo", robot inside of a circle outlined in black, drive forward, if sense black line then turn

# This code (or an earlier version of it) is posted at codepasteDOTnet/zrs5gq

from ev3dev.ev3 import *
from time import sleep


### col-reflect
# Connect EV3 color sensor and check connected.

cl = ColorSensor()
assert cl.connected, "Connect a color sensor to any sensor port"

# Put the color sensor into COL-REFLECT mode
# to measure reflected light intensity.
# In this mode the sensor will return a value between 0 and 100
cl.mode = 'COL-REFLECT'

while True:
   print(cl.value())
   sleep(0.5)

   # I get max 80 with white paper, 3mm separation
   # and 5 with black plastic, same separation

   direction = 1 # Switches between 1 and -1

   m = LargeMotor('outB')
   m.reset()
   m.run_forever(speed_sp=675 * direction)

   m2 = LargeMotor('outA')
   m2.reset()
   m2.run_forever(speed_sp=675)

   print(cl.value())
   sleep(0.5)

   new_color = cl.value()
   print new_color
   if new_color < 10:
     direction *= -1  # Reverse the direction. Forward becomes backward, backward becomes forward
     m.run_timed(time_sp=1000, speed_sp=300 * direction)
     sleep(1)
     print "I am sleeping"
     direction *= -1  # Reverse the direction. Forward becomes backward, backward becomes forward
     m.run_forever(speed_sp=675 * direction)
   touch = new_touch
#######
Reply
#2
When I run the program with >python3 rather than just >python
I get the error
robot@ev3dev:~/myproject$ python3 col-reflect-driveaway-v.2016.12.05.n01.py
File "col-reflect-driveaway-v.2016.12.05.n01.py", line 45
print new_color
^
SyntaxError: Missing parentheses in call to 'print'
Reply
#3
Have you tried adding parenthesis in the call to 'print'?
Reply
#4
(Dec-07-2016, 06:08 AM)micseydel Wrote: Have you tried adding parenthesis in the call to 'print'?
Thank you, the "print" call is now working
while True:
   print(cl.value())
   sleep(0.5)
Can you help me with the new problem I now have?
I'm now getting this error
Error:
robot@ev3dev:~/myproject$ python3 col-reflect-driveaway-v.2016.12.05.n01.py 0 Traceback (most recent call last):   File "col-reflect-driveaway-v.2016.12.05.n01.py", line 48, in <module>     m2.run_forever(speed_sp=675)   File "/usr/lib/python3/dist-packages/ev3dev/core.py", line 756, in run_forever     setattr(self, key, kwargs[key])   File "/usr/lib/python3/dist-packages/ev3dev/core.py", line 546, in speed_sp     self._speed_sp = self.set_attr_int(self._speed_sp, 'speed_sp', value)   File "/usr/lib/python3/dist-packages/ev3dev/core.py", line 215, in set_attr_int     return self._set_attribute(attribute, name, str(int(value)))   File "/usr/lib/python3/dist-packages/ev3dev/core.py", line 208, in _set_attribute     raise Exception('Device is not connected') Exception: Device is not connected robot@ev3dev:~/myproject$ packet_write_wait: Connection to 192.168.1.158 port 22: Broken pipe
The program starts running, for some reason it loses the WiFi connection, but the program keeps running, therefore CTRL-C doesn't stop it, and I have to reboot the Mindstorms brick.

You can see the most recent version of the code at: https://codepaste.net/zrs5gq

Edit admin:
Look at BBCode help button.
icode tag is only for short inline code.
Reply
#5
There might be someone around here that can help you, but you probably want a specialized forum for that device. It's hard to help when we lack domain knowledge and can't reproduce the problem.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  What is a circular import? asked by a newbie of newbies ineuw 1 944 Sep-16-2022, 07:27 PM
Last Post: Gribouillis
  The Wall-E Robot Argentum 1 1,406 Apr-03-2022, 03:01 PM
Last Post: sastonrobert
  Circular Import Led_Zeppelin 3 2,644 Jul-14-2021, 07:41 PM
Last Post: snippsat
  help on pandas circular import jip31 2 8,251 May-18-2021, 11:54 AM
Last Post: jip31
  Make these LEDs stay on duckredbeard 5 2,982 Apr-08-2021, 10:26 PM
Last Post: duckredbeard
  Circular import dependency hobbyist 9 3,827 Feb-23-2021, 11:57 AM
Last Post: Gribouillis
  DarkPaw Robot code Tyrelex78 3 2,132 Nov-27-2020, 12:06 AM
Last Post: Tyrelex78
Question How to make a button always stay on a point when resizing the window? _ShevaKadu 5 4,162 Nov-04-2020, 03:59 PM
Last Post: deanhystad
  How to iterate over some characters in a string and the others will stay as it is. ? sodmzs 9 4,393 Jun-17-2019, 06:45 PM
Last Post: perfringo
  Turning Robot towards goal, comparison of angles SpaceTime 0 2,742 Jan-21-2019, 10:26 PM
Last Post: SpaceTime

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020