Your browser was unable to load all of the resources. They may have been blocked by your firewall, proxy or browser configuration.
Press Ctrl+F5 or Ctrl+Shift+R to have your browser try again.

how to use klampt to control a simple robot arm (in python) #34

#1

Hello,
I'm new to Klampt, I found it when I was looking for a method to control my custom (DIY) robotic arm.
I'm only an hobbyist and self-taunt in programming and I want to create a code to control my robotic arm with something like an Xbox controller and, at first, see the arm move in simulation with the Vis app and secondly, to be able to create a custom controller and make move my real robotic arm in python(something like an 6 dof servo arm for example).
I searched in the online documentation and in the demo files but I wasn't able to understand how to create a main file properly to do what I want.
Is there something like courses, tutorials or some basic code ready to be used that can be used as examples to use a simple robotic arm?

In my case I already create my URDF and ROB file for my robot, i already have a code to control my motors from PID output (for ROS).
Now i stuck to create a main code properly.

Can you help me ?

Thank you for your time.

  • replies 1
  • views 612
  • likes 0

It has taken a long time for us to get here, but we finally have a good solution for this in Klampt 0.9. The Klampt Control API now provides a uniform interface to controlling robots. If you write a small amount of driver code, you can run the Klampt-examples demos kbdrive.py and pose.py. The following is a minimal piece of code to implement a nearly fully functional driver. In myrobot.py:

from klampt.control import RobotInterfaceBase,RobotInterfaceCompleter
class MyRobotDriver(RobotInterfaceBase):
    def __init__(self):
        RobotInterfaceBase.__init__(self)
        self.properties['klamptModelFile'] = 'path/to/my/URDF'
    def initialize(self):
        #TODO: connect to robot
        return True
    def controlRate(self):
        return 10  #10Hz
    def setPosition(self,q):
        #TODO: send a position command
        raise NotImplementedError()
    def sensedPosition(self):
        #TODO: return current position
        raise NotImplementedError()

def make(robotModel):
    return RobotInterfaceCompleter(MyRobotDriver())

Once the TODOs are implemented, you can then run klampt_control myrobot.py or python kbdrive.py /path/to/my/URDF myrobot.py and you should be able to control your robot and visualize its state too.