Python Forum
Help understanding code section
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help understanding code section
#1


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
Reply
#2
Please post code between code tags see BBCODE
In addition, when pasting code, use shift-ctrl-v to preserve indentation
Reply
#3
        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
Reply
#4
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.
Reply
#5
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?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to add multi-line comment section? Winfried 1 137 Mar-24-2024, 04:34 PM
Last Post: deanhystad
  Code understanding: Need help in understanding dictionary code jt123 0 450 Jul-09-2023, 01:13 PM
Last Post: jt123
  New to python/coding Need help on Understanding why this code isn't working. Thanks! mat3372 8 1,662 May-09-2023, 08:47 AM
Last Post: buran
  Append data to Yaml section tbaror 0 6,886 Feb-09-2022, 06:56 PM
Last Post: tbaror
  Understanding a piece of code Michael1 4 1,372 Jan-20-2022, 07:14 PM
Last Post: Michael1
  Beginner: I need help understanding few lines of a code. hop_090 1 1,642 Sep-07-2020, 04:02 PM
Last Post: Larz60+
  Extracting Rows From Data Frame and Understanding The Code JoeDainton123 0 1,406 Aug-03-2020, 04:08 PM
Last Post: JoeDainton123
  Create an isolated section in bash? yxk 1 1,911 Feb-27-2020, 11:16 AM
Last Post: Larz60+
  Help Understanding Code Variables 1 1,880 May-02-2019, 05:53 PM
Last Post: micseydel
  Best section to do a while loop in my code mrapple2020 0 1,613 Apr-15-2019, 01:14 AM
Last Post: mrapple2020

Forum Jump:

User Panel Messages

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