Posts: 1
Joined: Fri Oct 14, 2016 2:29 am

Gerbot - python code issue

Fri Oct 14, 2016 3:26 am

Hi Gert,

I'm using two gertbot h-bridge boards and a Raspberry pi 2 model B to control 3 stepper motors with python 3. I've freed up the uart and can control my motors by using Gert's GUI. I can also control the motors with my own python code BUT this only works if I've first run Gert's GUI and hit the 'connect' button.

Looking at the functions that I've been using I can see that it is the 'read_uart' call that sometimes returns -1 for the first gertbot board and always returns -1 for the second gertbot board. If I remove the try, except blocks I see that the specific error is 'OSError: [Errno 11] Resource temporarily unavailable'. If I have first connected to the boards with Gert's GUI (without using this to set motor modes etc, just simply clicking connect and then closing the GUI) my python code works fine. It appears that the connect button is doing something that my python code isn't. I've started looking at the C++ source code for the GUI but haven't yet found anything that fixes this problem.

Gert (or someone) do you have a solution or any suggestions?

Below is an example of my python code (works fine after first connecting with GUI) but motor_error is always [x, y, -1] (where x and y are sometimes 0 sometimes -1) if I haven't first connected with the GUI:

Code: Select all

import gertbot as gb

MOTOR_MODE = 8                          #Step gray off
STEPS_MM = 25                           #Steps per mm of stepper motors
GERTBOT_IDS = [0, 0, 1]                 #Gertbot IDs for each MOTOR
MOTOR_IDS = [0, 2, 0]                   #Motor IDs for each GERTBOT ID
STEP_FREQUENCY = 600                    #Stepper motor frequency in Hz

def configure_gertbots(gertbot_ids, motor_ids, motor_mode, step_frequency):
        gb.open_uart(0) # Open serial port to talk to Gertbot
        motor_error = [0]*len(gertbot_ids)
        number_of_posts = len(gertbot_ids)
        for i in range(0, number_of_posts):
            # Setup as steppers
            # Set the step frequency
            # Set endstops
            # set short mode

        # test for errors
        for i in range(0, number_of_posts):
            motor_error[i] = gb.read_error_status(gertbot_ids[i])


        return sum(motor_error)
        return -1

Any advice would be much appreciated!

Return to “HATs and other add-ons”