Difference between revisions of "PD control api"
(4 intermediate revisions by one user not shown) | |||
Line 7: | Line 7: | ||
<br> | <br> | ||
− | - Make 2 files under grasp directory. | + | - Make 2 files under '''grasp''' directory. |
<syntaxhighlight lang="cpp"> | <syntaxhighlight lang="cpp"> | ||
RSP.cpp | RSP.cpp | ||
Line 13: | Line 13: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | - | + | - Edit '''CMakeLists.txt''' for building new cpp file |
<syntaxhighlight lang="cpp"> | <syntaxhighlight lang="cpp"> | ||
+ | add_executable (grasp main.cpp canAPI.cpp RSP.cpp) | ||
+ | target_link_libraries (grasp BHand pcanbasic pthread) | ||
+ | install (TARGETS grasp DESTINATION ${PROJECT_BINARY_DIR}/bin) | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | - Edit each files. | ||
+ | <syntaxhighlight lang="cpp"> | ||
+ | // RSP.h | ||
#ifndef _ROCKSCISSORSPAPER_H | #ifndef _ROCKSCISSORSPAPER_H | ||
#define _ROCKSCISSORSPAPER_H | #define _ROCKSCISSORSPAPER_H | ||
Line 24: | Line 32: | ||
#endif | #endif | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | |||
− | |||
<syntaxhighlight lang="cpp"> | <syntaxhighlight lang="cpp"> | ||
+ | // RSP.cpp | ||
#include "rDeviceAllegroHandCANDef.h" | #include "rDeviceAllegroHandCANDef.h" | ||
#include <BHand/BHand.h> | #include <BHand/BHand.h> | ||
Line 97: | Line 104: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | - | + | - Edit '''main.cpp''' |
<syntaxhighlight lang="cpp"> | <syntaxhighlight lang="cpp"> | ||
− | + | // Include Rock Scissors Paper header file. | |
+ | #include "RSP.h" | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | - | + | - Add commands to use Rock Scissors Paper functions. |
<syntaxhighlight lang="cpp"> | <syntaxhighlight lang="cpp"> | ||
− | + | // MainLoop() | |
+ | case '1': | ||
+ | MotionRock(); | ||
+ | break; | ||
+ | case '2': | ||
+ | MotionScissors(); | ||
+ | break; | ||
+ | case '3': | ||
+ | MotionPaper(); | ||
+ | break; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | Try to build and run Allegro Hand. 1,2,3 keyboard button will show you Rock Scissors Paper. | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + |
Latest revision as of 17:30, 3 July 2019
[edit] Making Rock Paper Scissors by Allegro Hand
This instruction shows you how to use PD control api by making Rock Paper Scissors with Allegro Hand.
Please download BHand_PDcontrol_tutorial.zip file and follow below steps. File:BHand PDcontrol tutorial.zip
Also, you need to install BHand library. "libBHand": Grasping_Library_for_Linux
Also, you need to install BHand library. "libBHand": Grasping_Library_for_Linux
- Make 2 files under grasp directory.
RSP.cpp RSP.h
- Edit CMakeLists.txt for building new cpp file
add_executable (grasp main.cpp canAPI.cpp RSP.cpp) target_link_libraries (grasp BHand pcanbasic pthread) install (TARGETS grasp DESTINATION ${PROJECT_BINARY_DIR}/bin)
- Edit each files.
// RSP.h #ifndef _ROCKSCISSORSPAPER_H #define _ROCKSCISSORSPAPER_H void MotionRock(); void MotionScissors(); void MotionPaper(); #endif
// RSP.cpp #include "rDeviceAllegroHandCANDef.h" #include <BHand/BHand.h> // ROCK-SCISSORS-PAPER(RIGHT HAND) static double rock[] = { -0.1194, 1.2068, 1.0, 1.4042, -0.0093, 1.2481, 1.4073, 0.8163, 0.1116, 1.2712, 1.3881, 1.0122, 0.6017, 0.2976, 0.9034, 0.7929}; static double paper[] = { -0.1220, 0.4, 0.6, -0.0769, 0.0312, 0.4, 0.6, -0.0, 0.1767, 0.4, 0.6, -0.0528, 0.5284, 0.3693, 0.8977, 0.4863}; static double scissors[] = { 0.0885, 0.4, 0.6, -0.0704, 0.0312, 0.4, 0.6, -0.0, 0.1019, 1.2375, 1.1346, 1.0244, 1.0, 0.6331, 1.3509, 1.0}; extern BHand* pBHand; extern double q_des[MAX_DOF]; static void SetGainsRSP() { // This function should be called after the function SetMotionType() is called. // Once SetMotionType() function is called, all gains are reset using the default values. if (!pBHand) return; double kp[] = { 500, 800, 900, 500, 500, 800, 900, 500, 500, 800, 900, 500, 1000, 700, 600, 600 }; double kd[] = { 25, 50, 55, 40, 25, 50, 55, 40, 25, 50, 55, 40, 50, 50, 50, 40 }; pBHand->SetGainsEx(kp, kd); } void MotionRock() { for (int i=0; i<16; i++) q_des[i] = rock[i]; if (pBHand) pBHand->SetMotionType(eMotionType_JOINT_PD); SetGainsRSP(); } void MotionScissors() { for (int i=0; i<16; i++) q_des[i] = scissors[i]; if (pBHand) pBHand->SetMotionType(eMotionType_JOINT_PD); SetGainsRSP(); } void MotionPaper() { for (int i=0; i<16; i++) q_des[i] = paper[i]; if (pBHand) pBHand->SetMotionType(eMotionType_JOINT_PD); SetGainsRSP(); }
- Edit main.cpp
// Include Rock Scissors Paper header file. #include "RSP.h"
- Add commands to use Rock Scissors Paper functions.
// MainLoop() case '1': MotionRock(); break; case '2': MotionScissors(); break; case '3': MotionPaper(); break;
Try to build and run Allegro Hand. 1,2,3 keyboard button will show you Rock Scissors Paper.
Whos here now: Members 0 Guests 0 Bots & Crawlers 1 |