Python Forum

Full Version: Help understanding code section
You're currently viewing a stripped down version of our content. View the full version with proper formatting.


Hi everyone.

Need a little help interpreting the following bit of code. Keep in mind this is all brand new to me but am keen to lean.

I am working on a previously created project as I like to learn by doing and seeing the effects of what I do directly.

The following is a bit of code is a small section that is designed to output the signal from a xbox style controller to move steppers on a robotic arm. (think I have the right section anyway)

The issue I am having is that the motor output (0) on the driver likes to interpret the signal from the controller and tell the motor to keep moving in one direction perpetually.
It is like the neutral point of the stick on the controller is somehow offset.

all I need to know is if I am reading this correctly.....

Are the " -1500" and "5000" sections the areas that define the thresholds for the stick movement on the controller? or the central point offset?

Or is it the (1, 35) and (0, 35)

if event.code == 'ABS_X':
value = event.state
if value < -1500:
if not joints[0].isBusy(): joints[0].run(1, 35)
elif value > 5000:
if not joints[0].isBusy(): joints[0].run(0, 35)
else:
if not joints[0].isBusy(): joints[0].softStop()

Or am I reading this wrong?

links to the github section of this project here - https://github.com/Roboteurs/rbx1-softwa...r/robot.py
Please post code between code tags see BBCODE
In addition, when pasting code, use shift-ctrl-v to preserve indentation
        if event.code == 'ABS_X':
            value = event.state
            if value < -1500:
                if not joints[0].isBusy(): joints[0].run(1, 35)
            elif value > 5000:
                if not joints[0].isBusy(): joints[0].run(0, 35)
            else:
                if not joints[0].isBusy(): joints[0].softStop()

I read the part you refereed me to before posting the first bit but couldn't get it to work.
Is that correct now?

Cant work out how to change the original post
Not 100% sure but I think it is direction in which you moved the Xbox controller. The direction in which the motor move is the first argument over move - 1 or 0
Maybe I misinterpreted your question.
If you refer to -1500 and 5000 - I think these are values/positions of the xbox control stick. You can see them as offset from central position (given it is of value 0). I guess in one direction it is more sensitive, than in the other - i.e. bigger move of the stick to start backward movement.
Yeah that is how I read it as well.
I went ahead and adjusted the values to be central eg -3500 and 3500 like the other motor outputs and it seems to work a lot better.

I had my finger on the power switch just in case it tried to kill itself ha ha. :-)

Do you know how to activate the softstop section of the code?