robotino_arm_control
Differences
This shows you the differences between two versions of the page.
robotino_arm_control [2016/10/25 15:32] – created dwallace | robotino_arm_control [2016/10/28 17:51] (current) – dwallace | ||
---|---|---|---|
Line 8: | Line 8: | ||
The completed project ready to upload via ftp: | The completed project ready to upload via ftp: | ||
- | Poser program: | + | Poser program: |
- | Grab_n_run program | + | Grab_n_run program |
===== Video ===== | ===== Video ===== | ||
Line 111: | Line 111: | ||
rec:: | rec:: | ||
exit( 1 ); | exit( 1 ); | ||
- | |||
} | } | ||
| | ||
else | else | ||
{ | { | ||
- | std::cout << " | + | std::cout << " |
- | | + | |
} | } | ||
} | } | ||
Line 176: | Line 174: | ||
Now we need to ask the user for the desired pose. We can do this just after we print out " | Now we need to ask the user for the desired pose. We can do this just after we print out " | ||
- | | + | <code c++> |
- | while(true){ | + | |
- | std::cout << " | + | |
- | std:: | + | |
- | if(x==' | + | std::cout << " |
- | cbha.stringPots( targetValues ); | + | std:: |
- | } | + | |
- | std::cout << "here is your pose." << std:: | + | |
- | for( unsigned int i = 0; i < 6; ++i ) | + | cbha.stringPots( targetValues ); |
- | { | + | } |
- | std::cout << " | + | |
- | } | + | |
- | std::cout << " | + | |
- | std:: | + | |
- | if(x==' | + | { |
- | break; | + | std::cout << " |
- | } | + | } |
- | } | + | |
+ | | ||
+ | std:: | ||
+ | |||
+ | | ||
+ | break; | ||
+ | } | ||
+ | } | ||
| | ||
- | | + | |
+ | </ | ||
Now we are ready to implement out control. | Now we are ready to implement out control. | ||
Line 204: | Line 209: | ||
This control works for both sets of bellows. | This control works for both sets of bellows. | ||
- | + | <code c++> | |
- | void drive() | + | void drive() |
- | { | + | { |
- | float pressures[8] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; // the pressures in our bellows | + | float pressures[8] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; // the pressures in our bellows |
- | float values[6] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}; | + | float values[6] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}; |
| | ||
- | | + | |
- | float lastTime=com.msecsElapsed(); | + | float lastTime=com.msecsElapsed(); |
- | float lowerAvg; | + | float lowerAvg; |
- | float upperAvg; | + | float upperAvg; |
| | ||
- | while( com.isConnected() && false == bumper.value() && _run ) | + | |
- | { | + | { |
- | // update the string pot values | + | // update the string pot values |
- | cbha.stringPots( values ); | + | cbha.stringPots( values ); |
| | ||
- | | + | |
| | ||
- | | + | |
- | pressures[0]=pressures[0]+(-values[0]+targetValues[0])*stepSize+(values[1]-targetValues[1])*stepSize+(values[2]-targetValues[2])*stepSize; | + | pressures[0]=pressures[0]+(-values[0]+targetValues[0])*stepSize+(values[1]-targetValues[1])*stepSize+(values[2]-targetValues[2])*stepSize; |
- | pressures[1]=pressures[1]+(values[0]-targetValues[0])*stepSize+(-values[1]+targetValues[1])*stepSize+(values[2]-targetValues[2])*stepSize; | + | pressures[1]=pressures[1]+(values[0]-targetValues[0])*stepSize+(-values[1]+targetValues[1])*stepSize+(values[2]-targetValues[2])*stepSize; |
- | pressures[2]=pressures[2]+(values[0]-targetValues[0])*stepSize+(values[1]-targetValues[1])*stepSize+(-values[2]+targetValues[2])*stepSize; | + | pressures[2]=pressures[2]+(values[0]-targetValues[0])*stepSize+(values[1]-targetValues[1])*stepSize+(-values[2]+targetValues[2])*stepSize; |
| | ||
- | | + | |
- | lowerAvg=(pressures[0]+pressures[1]+pressures[2])/ | + | lowerAvg=(pressures[0]+pressures[1]+pressures[2])/ |
| | ||
- | | + | |
- | pressures[0]-=lowerAvg; | + | pressures[0]-=lowerAvg; |
- | pressures[1]-=lowerAvg; | + | pressures[1]-=lowerAvg; |
- | pressures[2]-=lowerAvg; | + | pressures[2]-=lowerAvg; |
| | ||
- | | + | |
- | pressures[3]=pressures[3]+(-values[3]+targetValues[3])*stepSize+(values[4]-targetValues[4])*stepSize+(values[5]-targetValues[5])*stepSize; | + | pressures[3]=pressures[3]+(-values[3]+targetValues[3])*stepSize+(values[4]-targetValues[4])*stepSize+(values[5]-targetValues[5])*stepSize; |
- | pressures[4]=pressures[4]+(values[3]-targetValues[3])*stepSize+(-values[4]+targetValues[4])*stepSize+(values[5]-targetValues[5])*stepSize; | + | pressures[4]=pressures[4]+(values[3]-targetValues[3])*stepSize+(-values[4]+targetValues[4])*stepSize+(values[5]-targetValues[5])*stepSize; |
- | pressures[5]=pressures[5]+(values[3]-targetValues[3])*stepSize+(values[4]-targetValues[4])*stepSize+(-values[5]+targetValues[5])*stepSize; | + | pressures[5]=pressures[5]+(values[3]-targetValues[3])*stepSize+(values[4]-targetValues[4])*stepSize+(-values[5]+targetValues[5])*stepSize; |
- | | + | |
| | ||
- | | + | |
- | pressures[4]-=upperAvg; | + | pressures[4]-=upperAvg; |
- | pressures[5]-=upperAvg; | + | pressures[5]-=upperAvg; |
| | ||
- | | + | |
- | cbha.setPressures( pressures ); | + | cbha.setPressures( pressures ); |
| | ||
| | ||
| | ||
- | | + | |
| | ||
- | | + | |
| | ||
- | | + | |
| | ||
- | | + | |
| | ||
- | | + | |
- | { | + | { |
- | std::cout << " | + | std::cout << " |
- | } | + | } |
| | ||
- | | + | |
| | ||
- | | + | |
- | { | + | { |
- | std::cout << " | + | std::cout << " |
- | } | + | } |
| | ||
| | ||
- | | + | |
- | lastTime=com.msecsElapsed(); | + | lastTime=com.msecsElapsed(); |
- | com.processEvents(); | + | com.processEvents(); |
- | rec:: | + | rec:: |
- | } | + | } |
- | + | } | |
- | + | </ | |
- | } | + | |
+ | Now the program is ready to compile and run. You can download the completed program and it's makefile here {{dylanw: | ||
- | + | ===== Moving | |
- | Now the program is ready to compile and run. You can download the completed program | + | |
+ | Now that we can move the arm we want to move to a known location and grab an object there. | ||
- | + | First we need to declare a few more things above our init() | |
- | == Moving to an object and grabbing it == | + | |
- | + | ||
- | Now that we can move the arm we want to move to a known location and grab an object there. | + | |
- | + | ||
- | First we need to declare a few more things above our init() | + | |
OmniDrive omniDrive; | OmniDrive omniDrive; | ||
Line 298: | Line 298: | ||
we will use the odometry class to measure the robots position. | we will use the odometry class to measure the robots position. | ||
- | We no longer need the posing code in our init class. | + | We no longer need the posing code in our init class. |
- | | + | <code c++ init.cpp> |
- | { | + | void init( const std:: |
- | // Initialize the actors | + | { |
+ | // Initialize the actors | ||
| | ||
- | // Connect | + | |
- | std::cout << " | + | std::cout << " |
- | com.setAddress( hostname.c_str() ); | + | com.setAddress( hostname.c_str() ); |
| | ||
- | com.connectToServer( true ); | + | |
| | ||
- | if( false == com.isConnected() ) | + | |
- | { | + | { |
- | std::cout << std::endl << "Could not connect to " << com.address() << std::endl; | + | std::cout << std::endl << "Could not connect to " << com.address() << std::endl; |
| | ||
- | rec:: | + | rec:: |
- | exit( 1 ); | + | exit( 1 ); |
- | } | + | } |
- | else | + | |
- | { | + | |
- | std::cout << " | + | { |
+ | std::cout << " | ||
| | ||
- | | + | |
- | cbha.setGripperValve1( false ); | + | cbha.setGripperValve1( false ); |
- | cbha.setGripperValve2( false ); | + | cbha.setGripperValve2( false ); |
| | ||
- | | + | |
| | ||
- | } | + | |
- | } | + | } |
+ | </ | ||
+ | Now lets look at the updated drive() function | ||
- | Now lets look at the updated | + | <code c++ drive.cpp> |
- | + | void drive() | |
- | | + | { |
- | { | + | float targetValues[6] = { 0.591398, 0.522972, 0.532747, 0.796676, 0.821114, 0.904203}; |
- | float targetValues[6] = { 0.591398, 0.522972, 0.532747, 0.796676, 0.821114, 0.904203}; | + | float caryPose[6] = { 0.591398, 0.522972, 0.532747, 0.796676, 0.821114, 0.904203}; |
- | float caryPose[6] = { 0.591398, 0.522972, 0.532747, 0.796676, 0.821114, 0.904203}; | + | float pressures[8] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; |
- | float pressures[8] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; | + | float values[6] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; |
- | float values[6] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; | + | float pickupPose[6]={0.777126, |
- | float pickupPose[6]={0.777126, | + | float errors[6] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; // we want to know how far away we are from the desired values we will store that error here |
- | float errors[6] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; // we want to know how far away we are from the desired values we will store that error here | + | float tolerance=.02; |
- | float tolerance=.02; | + | |
| | ||
| | ||
- | | + | |
- | unsigned int * seq; | + | unsigned int * seq; |
- | double x; // x position | + | double x; // x position |
- | double y; // y positon | + | double y; // y positon |
- | double phi; // rotation | + | double phi; // rotation |
| | ||
- | | + | |
- | bool closed=false; | + | bool closed=false; |
| | ||
- | | + | |
- | float lastTime=com.msecsElapsed(); | + | float lastTime=com.msecsElapsed(); |
- | float lowerAvg; | + | float lowerAvg; |
- | float upperAvg; | + | float upperAvg; |
| | ||
- | | + | |
- | targetValues[i]=pickupPose[i]; | + | targetValues[i]=pickupPose[i]; |
- | } | + | } |
- | while( com.isConnected() && false == bumper.value() && _run ) | + | |
- | { | + | |
- | // update the string pot values | + | { |
- | cbha.stringPots( values ); | + | // update the string pot values |
+ | cbha.stringPots( values ); | ||
| | ||
- | | + | |
| | ||
- | | + | |
- | pressures[1]=pressures[1]+(values[0]-targetValues[0])*stepSize+(-values[1]+targetValues[1])*stepSize+(values[2]-targetValues[2])*stepSize; | + | pressures[1]=pressures[1]+(values[0]-targetValues[0])*stepSize+(-values[1]+targetValues[1])*stepSize+(values[2]-targetValues[2])*stepSize; |
- | pressures[2]=pressures[2]+(values[0]-targetValues[0])*stepSize+(values[1]-targetValues[1])*stepSize+(-values[2]+targetValues[2])*stepSize; | + | pressures[2]=pressures[2]+(values[0]-targetValues[0])*stepSize+(values[1]-targetValues[1])*stepSize+(-values[2]+targetValues[2])*stepSize; |
| | ||
- | | + | |
| | ||
- | | + | |
- | pressures[1]-=lowerAvg; | + | pressures[1]-=lowerAvg; |
- | pressures[2]-=lowerAvg; | + | pressures[2]-=lowerAvg; |
| | ||
- | | + | |
- | pressures[4]=pressures[4]+(values[3]-targetValues[3])*stepSize+(-values[4]+targetValues[4])*stepSize+(values[5]-targetValues[5])*stepSize; | + | pressures[4]=pressures[4]+(values[3]-targetValues[3])*stepSize+(-values[4]+targetValues[4])*stepSize+(values[5]-targetValues[5])*stepSize; |
- | pressures[5]=pressures[5]+(values[3]-targetValues[3])*stepSize+(values[4]-targetValues[4])*stepSize+(-values[5]+targetValues[5])*stepSize; | + | pressures[5]=pressures[5]+(values[3]-targetValues[3])*stepSize+(values[4]-targetValues[4])*stepSize+(-values[5]+targetValues[5])*stepSize; |
- | | + | |
| | ||
- | | + | |
- | pressures[4]-=upperAvg; | + | pressures[4]-=upperAvg; |
- | pressures[5]-=upperAvg; | + | pressures[5]-=upperAvg; |
| | ||
- | | + | |
| | ||
- | | + | |
| | ||
- | | + | |
- | for( unsigned int i = 0; i < 6; ++i ){ | + | for( unsigned int i = 0; i < 6; ++i ){ |
- | errors[i]=targetValues[i]-values[i]; | + | errors[i]=targetValues[i]-values[i]; |
- | std:: | + | std:: |
- | if(tolerance > std:: | + | if(tolerance > std:: |
- | + | std::cout << "in tolerance: " << i << | |
- | | + | } |
- | } | + | |
- | else{ | + | |
- | break; | + | break; |
- | } | + | } |
| | ||
- | | + | |
- | | + | |
- | } | + | } |
- | else inTolerance=false; | + | |
+ | | ||
| | ||
- | | + | |
| | ||
| | ||
- | | + | |
| | ||
- | | + | |
| | ||
| | ||
- | | + | |
| | ||
- | omniDrive.setVelocity( vel[0], vel[1], vel[2] ); // update our velocity vector using the robotino api omni drive | + | omniDrive.setVelocity( vel[0], vel[1], vel[2] ); // update our velocity vector using the robotino api omni drive |
| | ||
| | ||
- | | + | |
| | ||
| | ||
- | | + | |
- | if (inTolerance==true && x<=0 && !closed){ | + | if (inTolerance==true && x<=0 && !closed){ |
- | vel[0]=.2; | + | vel[0]=.2; |
- | } | + | } |
- | // seccond | + | // second |
- | if (inTolerance==true && x<=0.51 && x>=.49 && !closed){ | + | |
- | vel[0]=0; | + | if (inTolerance==true && x<=0.51 && x>=.49 && !closed){ |
- | rec:: | + | vel[0]=0; |
- | cbha.setGripperValve1( true ); // close gripper valves | + | rec:: |
- | cbha.setGripperValve2( true ); | + | cbha.setGripperValve1( true ); // close gripper valves |
- | rec:: | + | cbha.setGripperValve2( true ); |
- | closed=true; | + | rec:: |
- | for( unsigned int i = 0; i < 6; ++i ){ // switch our pose to the cary pose | + | closed=true; |
+ | |||
+ | | ||
targetValues[i]=caryPose[i]; | targetValues[i]=caryPose[i]; | ||
} | } | ||
} | } | ||
+ | | ||
// now that the gripper is closed we want to start rotating. | // now that the gripper is closed we want to start rotating. | ||
if (inTolerance==true && x<=0.51 && x>=.49 && closed){ | if (inTolerance==true && x<=0.51 && x>=.49 && closed){ | ||
vel[2]=.5; | vel[2]=.5; | ||
} | } | ||
+ | | ||
// once you have rotated 2.25 radians stop and wait 5 seconds. | // once you have rotated 2.25 radians stop and wait 5 seconds. | ||
if (phi> | if (phi> | ||
Line 479: | Line 488: | ||
// syncronize and delay | // syncronize and delay | ||
lastTime=com.msecsElapsed(); | lastTime=com.msecsElapsed(); | ||
- | com.processEvents(); | + | |
- | rec:: | + | |
- | } | + | } |
- | + | } | |
- | + | </ | |
- | | + | |
- | + | ||
- | The completed file can be downloaded here [[:File: | + | The completed file can be downloaded here {{dylanw: |
robotino_arm_control.1477434763.txt.gz · Last modified: 2016/10/25 15:32 by dwallace