Skip to content

Instantly share code, notes, and snippets.

@aman-tiwari
Last active December 17, 2015 08:57
Show Gist options
  • Save aman-tiwari/95308a11416e2fccb971 to your computer and use it in GitHub Desktop.
Save aman-tiwari/95308a11416e2fccb971 to your computer and use it in GitHub Desktop.
UArm control from Openframeworks
//--------------------------------------------------------------
void ofApp::setup() {
uarm.setup("/dev/tty.usbserial-A600CRMU", 9600);
}
//--------------------------------------------------------------
// x, y, z in cylindrical coordinates, handRot in degrees
void ofApp::setArmTo(int x, int y, int z, int handRot, bool gripper) {
// UArm expects 1 for an open gripper and 2 for a closed gripper
gripper = (int)gripper + 1;
unsigned char bytes[11] = {
0xFF,
0xAA,
static_cast<unsigned char>((x >> 8) & 0xFF),
static_cast<unsigned char>(x & 0xFF),
static_cast<unsigned char>((y >> 8) & 0xFF),
static_cast<unsigned char>(y & 0xFF),
static_cast<unsigned char>((z >> 8) & 0xFF),
static_cast<unsigned char>(z & 0xFF),
static_cast<unsigned char>((handRot >> 8) & 0xFF),
static_cast<unsigned char>(handRot & 0xFF),
static_cast<unsigned char>(gripper)
};
uarm.writeBytes(&bytes[0], 11);
}
//--------------------------------------------------------------
void ofApp::exit() {
uarm.flush(true,true);
}
#pragma once
#include "ofMain.h"
class ofApp : public ofBaseApp {
public:
void setup();
void exit();
ofSerial uarm;
void setArmTo(int x, int y, int z, int handRot, bool gripper);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment