Trossen Hexapod  Top Banner
Results 1 to 8 of 8

Thread: I need help of this C++ program

  1. I need help of this C++ program

    #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

  2. #2
    Join Date
    Sep 2010
    Location
    ಠ_ಠ
    Posts
    1,318
    Images
    25
    Rep Power
    52

    Re: I need help of this C++ program

    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. 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.
    Please pardon the pedantry... and the profanity... and the convoluted speech pattern...
    "You have failed me, Brain!"

  3. #3
    Join Date
    May 2008
    Posts
    2,224
    Images
    155
    Rep Power
    109

    Re: I need help of this C++ program

    Quote Originally Posted by tician View Post
    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. 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

  4. Trossen Hexapod  Thread Banner
  5. Re: I need help of this C++ program

    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 ...

  6. #5
    Join Date
    Sep 2010
    Location
    ಠ_ಠ
    Posts
    1,318
    Images
    25
    Rep Power
    52

    Re: I need help of this C++ program

    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.
    Please pardon the pedantry... and the profanity... and the convoluted speech pattern...
    "You have failed me, Brain!"

  7. Re: I need help of this C++ program

    Hi again... I understand what you said it functions so canyou helping me to modify this program to make me understand more …

    Regards

  8. #7
    Join Date
    Sep 2010
    Location
    ಠ_ಠ
    Posts
    1,318
    Images
    25
    Rep Power
    52

    Re: I need help of this C++ program

    The AX-S1 has an ID just like any other dynamixel device (usually set at the factory as ID==100). Use the information here, 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
    Please pardon the pedantry... and the profanity... and the convoluted speech pattern...
    "You have failed me, Brain!"

  9. Re: I need help of this C++ program

    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...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Question(s) Robot plus program
    By blastdog in forum Humanoids, Walkers & Crawlers
    Replies: 1
    Last Post: 09-07-2011, 05:18 PM
  2. Who uses what cad program?
    By rebel in forum Software and Programming
    Replies: 20
    Last Post: 02-14-2011, 12:13 AM
  3. Help to finish off program
    By nolimit44 in forum Software and Programming
    Replies: 17
    Last Post: 02-11-2011, 09:52 PM
  4. First Program with arduinno
    By nolimit44 in forum Software and Programming
    Replies: 0
    Last Post: 01-29-2011, 12:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •