PDA

View Full Version : I need help of this C++ program



lo0lo0999
03-10-2012, 05:48 AM
#include <stdio.h>
#include <conio.h>
#include "dynamixel.h"
#include<time.h>

#pragma comment(lib, "dynamixel.lib")


// Control table address
#define P_GOAL_POSITION_L 30
#define P_GOAL_POSITION_H 31
#define P_PRESENT_POSITION_L 36
#define P_PRESENT_POSITION_H 37
#define P_MOVING 46

// Defulat setting
#define DEFAULT_PORTNUM 25 // COM3
#define DEFAULT_BAUDNUM 1 // 1Mbps


int main()
{

int Moving, PresentPos;
int CommStatus, Hold;
int PORT_ID, GoalPos1, GoalPos2, GoalPos3, GoalPos4;
char Action;



// Open device
if( dxl_initialize(DEFAULT_PORTNUM, DEFAULT_BAUDNUM) == 0 )
{
printf( "Failed to open USB2Dynamixel!\n" );
printf( "Press any key to terminate...\n" );
getch();
return 0;
}
else
printf( "System Ready to Control ROBOT!\n" );

//initial position
dxl_write_word( 5, P_GOAL_POSITION_L, 512); getch();
dxl_write_word( 4, P_GOAL_POSITION_L, 512); getch();
dxl_write_word( 1, P_GOAL_POSITION_L, 512); getch();
dxl_write_word( 244, P_GOAL_POSITION_L, 512);

Hold = 0;

printf( "My MASTER, I am ready to obey your Commands \n" );
printf("A - Pick Object A \n");
printf("B - Pick Object B \n");
printf("R - Place at Right Side \n");
printf("L - Place at Leftide \n");
printf("ESC - Exit \n");
printf("\n\n Your Choice Please, MY Master : ");

do
{ Action = getch();
switch (Action)

{ case 0x1b : break;

case 97 : if (Hold == 0)
{ Hold = 1;
dxl_write_word( 4, P_GOAL_POSITION_L, 630);
getch();
dxl_write_word( 5, P_GOAL_POSITION_L, 176);
getch();
dxl_write_word( 1, P_GOAL_POSITION_L, 625);
getch();
dxl_write_word( 4, P_GOAL_POSITION_L, 512);
printf("Yes, My Master, Where should I Place it?"); }
else
{ printf("Sorry My Master! I Couldn't - I am Holding an Object! \n\n");
} break;

case 98 : if (Hold == 0)
{ Hold = 1;
dxl_write_word( 4, P_GOAL_POSITION_L, 630);
getch();
dxl_write_word( 5, P_GOAL_POSITION_L, 176);
getch();
dxl_write_word( 1, P_GOAL_POSITION_L, 625);
getch();
dxl_write_word( 4, P_GOAL_POSITION_L, 512);

printf("Yes, My Master, Where should I Place it?");}
else
{ printf("Sorry My Master! I Couldn't - I am Holding an Object! \n\n");
} break;

case 114 : if (Hold == 1)
{ Hold = 0;
dxl_write_word( 244, P_GOAL_POSITION_L, 218);
getch();
dxl_write_word( 4, P_GOAL_POSITION_L, 635);
getch();
dxl_write_word( 1, P_GOAL_POSITION_L, 436);
getch();
dxl_write_word( 4, P_GOAL_POSITION_L, 512);
getch();
dxl_write_word(244, P_GOAL_POSITION_L, 512);
printf("I think that I have done the JOB correctly!"); }
else
{ printf("Sorry My Master! I Couldn't - I don't have anything to place! \n\n");
} break;

case 108 : if (Hold == 1)
{ Hold = 0;
dxl_write_word(244, P_GOAL_POSITION_L, 839);
getch();
dxl_write_word( 4, P_GOAL_POSITION_L, 635);
getch();
dxl_write_word( 1, P_GOAL_POSITION_L, 436);
getch();
dxl_write_word( 4, P_GOAL_POSITION_L, 512);
getch();
dxl_write_word( 244, P_GOAL_POSITION_L, 512);
printf("I think that I have done the JOB correctly!");}
else
{ printf("Sorry My Master! I Couldn't - I don't have anything to place! \n\n");
} break;

default: printf(" Sorry, I don't have this Knowledge! - Teach me My Master! \n\n"); break;

}
}while(Action != 0x1b);

// Close device
dxl_terminate();
printf( "Press any key to terminate...\n" );
getch();
return 0;
}







Hi again This code for controling Arobotic arm and I want your help to implement An Interface using button..In this pro i use a cmd command..And I`m using visual studio 2008 to compile this pro..I need your help during this week..




Also i want to include or apply the sensor to our robotic arm..so i want to apply it to the program ..I have the knowloage that i shoud include the address of my robotics >> so please can someone replay to me soon>>

Thanks

tician
03-11-2012, 12:22 AM
I am going to assume you want a physical push-button and not a click-able button in a window on the PC screen (I am still not very good with GUI's, so I could help you there). An Arduino would probably be easiest option with a button connected to one of the digital pins along with a pull-up resistor. This would also allow plenty of non-dynamixel sensors to be connected to the arm and still be accessed by the PC. There are two options for acquiring the button press and sensor data from the Arduino.

Option 1: The easiest would require you to use the onboard USBtoUART IC (either an FT232 or ATmega8U depending on board revision) to connect the Arduino to a USB port (would show up exactly like the USB2Dynamixel does as a COM port). All you would need to do is buy an Arduino and make a small program for it to read the state of the push-button's digital pin (and any analog sensor data) and send that over the UART to the PC. There are undoubtedly many code examples for reading digital and analog pin values on the Arduino and sending them over the UART, and everything you need to connect to the serial port on the PC-side is already included in both the Dynamixel and Zigbee SDK's (zgb_hal.c and zgb_hal.h would be a good start). I remember a project somewhere online where a person bought one of the big red EASY buttons from Staples and connected it to a PC via an Arduino, but I do not remember where that project was documented.

Option 2: Significantly more difficult would be to turn the Arduino into a dynamixel device that collects various pins states (ADC and digital pins of your choice) and sends them back to the PC through the USB2Dynamixel as if it were an AX-S1 or similar. The best place to look for example code would be lxnfergy's ax-m1 project on the vanadium-ros-pkg google code site (http://code.google.com/p/vanadium-ros-pkg/source/browse/hardware/ax_m1/firmware/). I am not sure how well it currently works and it would definitely need modification to work on your Arduino board, but it would at least be a start.

lnxfergy
03-11-2012, 01:38 AM
Option 2: Significantly more difficult would be to turn the Arduino into a dynamixel device that collects various pins states (ADC and digital pins of your choice) and sends them back to the PC through the USB2Dynamixel as if it were an AX-S1 or similar. The best place to look for example code would be lxnfergy's ax-m1 project on the vanadium-ros-pkg google code site (http://code.google.com/p/vanadium-ros-pkg/source/browse/hardware/ax_m1/firmware/). I am not sure how well it currently works and it would definitely need modification to work on your Arduino board, but it would at least be a start.

The AX-M1 code works pretty well in general, although it lacks a few features (such as the ability to do EEPROM storage, so you *have* to set the ID at programming time...)

-Fergs

lo0lo0999
03-11-2012, 04:11 AM
Thanks..But first I want to include the AX-S1 sensor in this program to control the robotic arm with it And I`m using Microsoft visual studio to compile this program ...

tician
03-11-2012, 07:29 PM
The AX-S1 behaves exactly like any other dynamixel device. You use the dxl_read_byte() and dxl_read_word() functions to read the sensor data stored in the various registers (Forward, Left and Right IR distance values, Sound Level, etc.), and you use the dxl_write_byte() and dxl_write_word() functions to set the different output registers (Buzzer and IR_COM). Everything related to using the AX-S1 and all other Robotis products is located on the Robotis support site along with the dynamixel and zigbee SDK's.

lo0lo0999
03-12-2012, 05:06 AM
Hi again... I understand what you said it functions so canyou helping me to modify this program to make me understand more …

Regards

tician
03-12-2012, 09:41 AM
The AX-S1 has an ID just like any other dynamixel device (usually set at the factory as ID==100). Use the information here (http://support.robotis.com/en/product/auxdevice/sensor/dxl_ax_s1.htm), along with the read and write functions, to gather sensor data.

Read sensor data:
int bIR_center = dxl_read_byte(AXS1_ID, 27); // Read CENTER IR distance value from AX-S1 (26 is LEFT, and 28 is RIGHT)

Write Buzzer data:
dxl_write_byte(AXS1_ID, 41, 255); // Set Buzzer to Melody Mode
dxl_write_byte(AXS1_ID, 40, 2); // Play pre-programmed Melody #2

lo0lo0999
03-13-2012, 02:24 AM
Thanks for the help ... I will try to look at that And when i modify it i will post it again here to make sure ...


Thanks again...:veryhappy::happy: