Page 1 of 1

Boredom Killer - Arduino Robot Arm Project

Posted: Thu Apr 06, 2017 8:28 pm
by Jayme
So,
I got bored and wanted to find something interesting to do with my spare arduino.. after some research, I found that you can buy a usb host shield for the arduino, and plug in a microsoft xbox controller usb receiver into it, then code it up to control anything... ideas galore arrived.. including my mate begging me to make his ride on mower radio controlled :roll:

so I started looking into how to make an easy robot arm. after a while I stumbled across an R/C servo driven robot arm kit! cheap enough that I figured bugger making one... ill just build the kit! Link

so while it was in the post, Holden202 gave me some spare servos to play with :punk: and I began coding up the controls. I took the xbox controller library, and the r/c servo library and basically loaded them both into my project and started mapping controls to servo position. its tricker than you think, because an r/c servo wants to be given an absolute position, so if you map it directly it acts like a steering servo, let go of stick and it drives back to the center position. NOT what we want for a robot arm, so I coded up a few loops to slowly tick the servo position value back and forward, to make the controls more like an excavator. it even has speed, the further you push the stick, the shorter the loop and the quicker the servo ticks forward.

anyways, here is the result after I built the robot arm and hooked it all up! I needed some 5v power for the high torque servos, so I ran some speaker wire out of a hard drive connector 5v line in my pc lol...
The kids love it, a big toy.

[youtube]https://www.youtube.com/watch?v=sjsuNJmUKfo[/youtube]
20170406_200146.jpg

Re: Boredom Killer - Arduino Robot Arm Project

Posted: Thu Apr 06, 2017 8:57 pm
by Dylan
That's cool as well done

Re: Boredom Killer - Arduino Robot Arm Project

Posted: Thu Apr 06, 2017 9:09 pm
by antus
Real nice work getting the controller to work so smoothly!

Re: Boredom Killer - Arduino Robot Arm Project

Posted: Thu Apr 06, 2017 9:21 pm
by Jayme
I remembered seeing a neat idea somewhere for the speed code, where instead of locking up the code with a wait command, you just take a timestamp, then save the current system clock in a variable eg: 'timer' and the speed variable is a millisecond value. so you just have an IF system clock > timer1 + speed value then re enter the code to increment servo position. the speed variable is then mapped to the analog stick axis value. it worked really well, but having to reverse the axis values from the xbox controller (speed value is smaller = faster, but controller is a larger value the further the stick moves) so it took me a little while of brain pain in excel to get the speed formulas right. We used to tell the maths teacher at school, we would never ever use this shit. well the teacher was proven correct tonight.

Code: Select all

if  ((Xbox.getAnalogHat(LeftHatX, i) < -7500)&& servo1pos < 180) {
            servo1speed = (32768+Xbox.getAnalogHat(LeftHatX, i))/400+5 ;
        
        if (millis()>=(servo1timer+servo1speed)){
            servo1pos=servo1pos+1;
            myservo1.write(servo1pos);
            servo1timer = millis();
            Serial.print("Servo1 Position:"); 
            Serial.println(servo1pos);
        }

          }
on a side note... the arduino does struggle a bit, trying to keep up with the PWM control of 6 servos at once. when its still, you can see it twitching a bit lol.

Re: Boredom Killer - Arduino Robot Arm Project

Posted: Thu Apr 06, 2017 9:38 pm
by antus
Hardware or software pwm generation?

Re: Boredom Killer - Arduino Robot Arm Project

Posted: Thu Apr 06, 2017 9:41 pm
by Jayme
its all software PWM... it can use any digital pin, not just the PWM ones (there wouldnt be enough for 6 servos anyway), so its not unexpected for the PWM signal to be a bit less than perfect.

you can buy a servo control sheild that will give accurate control... maybe ill look into that later on.

Re: Boredom Killer - Arduino Robot Arm Project

Posted: Fri Apr 07, 2017 10:14 am
by Holden202T
Definitely a good project! :thumbup:

reminds me of that movie Malcolm :D

Re: Boredom Killer - Arduino Robot Arm Project

Posted: Fri Apr 07, 2017 7:21 pm
by VL400
Very cool indeed. Teach it to write your forum posts? :think:
Jayme wrote:when its still, you can see it twitching a bit lol.
Its not just arduinos that do that :lol: Too many shed fumes.

Re: Boredom Killer - Arduino Robot Arm Project

Posted: Mon Apr 10, 2017 11:59 am
by Holden202T
lol :)

Re: Boredom Killer - Arduino Robot Arm Project

Posted: Tue Apr 11, 2017 7:24 am
by The1
I wish I had a bordom problem instead of lack of time problem. Lol feel free to code enhanced lol, well done on the project, were doing this with highschool kids now where they have to design a arm, 3d print it then assemble and code it to solve a problem, tea dunker it is lol