0

I was trying to use a function from my own class and it gave me this error:

Traceback (most recent call last):
  File "/home/robot/MyBlocks/main.py", line 134, in <module>
  File "/home/robot/MyBlocks/main.py", line 50, in drive_mm
TypeError: can't convert Generic_Myblocks to int

Exited with error code 1.

Here's my code for the drive function:

def drive_mm(angle, speed, mm, brake=True):
  robot.reset()
  while robot.distance() < mm:
    robot.drive(speed, angle)       <-- the error is this line
  robot.stop()
  if brake == True:
    lm.hold()
    rm.hold()
    return
  else:
    lm.brake()
    rm.brake()

And for the actual program:

# Creates a object using the custom class and runs the drive function off it
    myblocks = Generic_Myblocks(ev3, robot, leftMotor, rightMotor, leftColor, rightColor, infrared)
    myblocks.drive_mm(0, 1000, 100)
4
  • robot is undefined (in the posted code). Commented Jun 22, 2023 at 15:54
  • robot was defined as the DriveBase() object earlier in the code. I can show you more if you'd like. Commented Jun 22, 2023 at 15:57
  • drive_mm() appears to be a method of the class, in which case the first parameter it receives will be the instance of the class it was invoked via. That parameter is normally named self - you are instead receiving it as angle, and trying to do math with it. Commented Jun 22, 2023 at 15:59
  • That seems to be it @jasonharper. thank you all, im kinda new to this stuff Commented Jun 22, 2023 at 16:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.