Beginners: please read this post and this post before posting to the forum.
0 Members and 1 Guest are viewing this topic.
/*************************************************************************Authored by John Palmisano of SocietyofRobots.comin collaboration with Clive Webster of WebbotLib2009intended use for Axon and Axon IIinstructions:This file is where you define all of your intended hardware connected toyour Axon microcontroller. You can set up baud rates for your UART,specificy which sensors you are using, declare servos, etc.Keeping this separate from your other code makes code sharing easy.*************************************************************************///////////////////////////LIBRARIES/////////////////////////////declare sensor libraries (examples are commented out)//#include <Sensors/Acceleration/DynamicEngineering/ACCM3D2.h>//#include <Sensors/Compass/Honeywell/HMC6343.h>//#include <Sensors/Gyro/InvenSense/IDG300.h>///////////////////////////////////////////////////////////////////////////////////////////UART///////////////////////////////UART defines (name your UART)#define GPS_UART UART0#define USB_UART UART1#define WIRELESS_UART UART2#define OTHER_UART UART3//UART baud defines (change baud rate)#define GPS_BAUD (BAUD_RATE)9600#define USB_BAUD (BAUD_RATE)115200#define WIRELESS_BAUD (BAUD_RATE)9600#define OTHER_BAUD (BAUD_RATE)38400//UART define which uart to use#define GPS_ACTIVATE &uart0SendByte#define USB_ACTIVATE &uart1SendByte#define WIRELESS_ACTIVATE &uart2SendByte#define OTHER_ACTIVATE &uart3SendByte#define UART2_GET uart2GetByte()///////////////////////////////////////////////////////////////////////////////////////////SERVOS/////////////////////////////define servo hardware, use TRUE for right side, FALSE for inverted side//if you use hardware PWM, use only PWM pins//example: MAKE_SERVO(ROTATION DIRECTION, PIN, CENTER, RANGE)//arm1 servosSERVO s_1_1 = MAKE_SERVO(FALSE, L1, 1500, 900);SERVO s_1_2 = MAKE_SERVO(FALSE, B7, 1500, 900);SERVO s_1_3 = MAKE_SERVO(FALSE, H3, 1500, 900);//arm2 servosSERVO s_2_1 = MAKE_SERVO(FALSE, L2, 1500, 900);SERVO s_2_2 = MAKE_SERVO(FALSE, B6, 1500, 900);SERVO s_2_3 = MAKE_SERVO(FALSE, E7, 1500, 900);//arm3 servosSERVO s_3_1 = MAKE_SERVO(FALSE, L3, 1500, 900);SERVO s_3_2 = MAKE_SERVO(FALSE, B5, 1500, 900);SERVO s_3_3 = MAKE_SERVO(FALSE, E6, 1500, 900);//arm4 servosSERVO s_4_1 = MAKE_SERVO(FALSE, L4, 1500, 900);SERVO s_4_2 = MAKE_SERVO(FALSE, B4, 1500, 900);SERVO s_4_3 = MAKE_SERVO(FALSE, E5, 1500, 900);//arm5 servosSERVO s_5_1 = MAKE_SERVO(FALSE, L5, 1500, 900);SERVO s_5_2 = MAKE_SERVO(FALSE, H6, 1500, 900);SERVO s_5_3 = MAKE_SERVO(FALSE, E4, 1500, 900);//arm6 servosSERVO s_6_1 = MAKE_SERVO(FALSE, L6, 1500, 900);SERVO s_6_2 = MAKE_SERVO(FALSE, H5, 1500, 900);SERVO s_6_3 = MAKE_SERVO(FALSE, E3, 1500, 900);// Create the list - remember to place an & at the// start of each servo nameSERVO_LIST jt1[] = {&s_1_1, &s_2_1, &s_3_1, &s_4_1, &s_5_1, &s_6_1};SERVO_LIST jt2[] = {&s_1_2, &s_2_2, &s_3_2, &s_4_2, &s_5_2, &s_6_2};SERVO_LIST jt3[] = {&s_1_3, &s_2_3, &s_3_3, &s_4_3, &s_5_3, &s_6_3};// Create a driver for the list of servosSERVO_DRIVER bank1 = MAKE_SERVO_DRIVER(jt1);SERVO_DRIVER bank2 = MAKE_SERVO_DRIVER(jt2);SERVO_DRIVER bank3 = MAKE_SERVO_DRIVER(jt3);//////////////////////////////////////////////////////////////
/*************************************************************************AXON AND AXON II CODE FOR WEBBOTLIBAuthored by John Palmisano of SocietyofRobots.comin collaboration with Clive Webster of WebbotLib.For more information, see:http://www.societyofrobots.com/axonhttp://www.societyofrobots.com/axon2http://sourceforge.net/projects/webbotavrclib2009intended use for Axon and Axon IIinstructions:Read comments for explanation of all code.appInitHardware() is for initiating the Axon.appControl() is where your code goes. It is similar to control.cfor the original Axon code.See hardware.h for defining your external hardware.See sys/axon2.h in WebbotLib to change which pins are input and output.*************************************************************************///allows for printing with features, but uses more memory#define RPRINTF_FLOAT#define RPRINTF_COMPLEX//additional math capabilities//#include <math.h>//WebbotLib includes#include "sys/axon2.h" //defines your MCU (change to axon.h if you use the original Axon)#include "servos.h" //use for software servo PWM#include "a2d.h" //use for ADC#include "rprintf.h" //use for UART//#include "i2c_master.h" //use for I2C//#include "buffer.h" //use for GPS and other serial stuff//user includes#include "hardware.h"#include "stdio.h"#include "string.h"// In my initialising code - pass the list of servos to controlvoid appInitHardware(void) { //initialize UART ports (see hardware.h to change baud/names) uartInit(GPS_UART, GPS_BAUD); //UART0 uartInit(USB_UART, USB_BAUD); //USB uartInit(WIRELESS_UART, WIRELESS_BAUD); //UART2 uartInit(OTHER_UART, OTHER_BAUD); //UART3 // declare USB for output rprintfInit(WIRELESS_ACTIVATE); // Initialise the servo controller //servoPWMInit(&bank1); //use PWM to control servos (must use PWM pins!) servosInit(&bank1, TIMER1); //use software PWM to control servos (can use any pin) servosInit(&bank2, TIMER4); servosInit(&bank3, TIMER5); // Initiate Sensors (examples commented out) //accelerometerInit(accm3d2); //compassInit(hmc6343); //gyroInit(idg300); }TICK_COUNT appInitSoftware(TICK_COUNT loopStart){ rprintf("\nAxon Initiated.\n\n");return 0;}void move_servo(SERVO_LIST* joint_id, short int leg_id, short int servo_position){ act_setSpeed((SERVO *)pgm_read_word(&joint_id[leg_id-1]), servo_position); delay_ms(24);}int get_position(SERVO_LIST* joint_id, short int leg_id){ return (act_getSpeed((SERVO *)pgm_read_word(&joint_id[leg_id-1])));}void move_servo_inc(SERVO_LIST* joint_id, short int leg_id, short int increment){ act_setSpeed((SERVO *)pgm_read_word(&joint_id[leg_id-1]), act_getSpeed((SERVO *)pgm_read_word(&joint_id[leg_id]))+increment); delay_ms(24);}void reset_pos (){ short int i; for (i=0; i<6; i++) { move_servo(jt1, i, 0); move_servo(jt2, i, 0); move_servo(jt3, i, 0); }}void raise_jt(SERVO_LIST* joint_id, short int s_1, short int pos1, short int s_2, short int pos2, short int s_3, short int pos3) { move_servo(joint_id, s_1, pos1); move_servo(joint_id, s_2, pos2); move_servo(joint_id, s_3, pos3); }int tempbyte;// This is the main loopTICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart) { tempbyte=UART2_GET;//get a single character if (tempbyte=='1') { servosConnect(&bank1);//turn servos on servosConnect(&bank2); servosConnect(&bank3); rprintf("servos on\n"); } //power servos if (tempbyte=='2') { servosDisconnect(&bank1);//turn servos off servosDisconnect(&bank2); servosDisconnect(&bank3); rprintf("servos off\n"); } if (tempbyte=='l') { { raise_jt(jt2, 1, 60, 3, 60, 5, -60); raise_jt(jt3, 1, 60, 3, 60, 5, -60); delay_ms(3000); move_servo(jt1, 6, 75); move_servo(jt2, 6, -5); move_servo(jt3, 6, -25); move_servo(jt1, 2, 40); move_servo(jt2, 2, 5); move_servo(jt3, 2, 8); move_servo(jt1, 4, 10); move_servo(jt2, 4, 15); move_servo(jt3, 4, 30); } } short int i; if (tempbyte=='u') { //send byte from hyperterminal rprintf("moving arm_x_1 forward\n"); for (i=0; i<6; i++) { move_servo_inc(jt1, i, -10); } } if (tempbyte=='o') { reset_pos(); } if (tempbyte=='i') { //send byte from hyperterminal rprintf("moving arm_x_1 backwards\n"); for (i=0; i<6; i++) { move_servo_inc(jt1, i, 10); } } if (tempbyte=='j') { //send byte from hyperterminal rprintf("moving arm_x_2 forward\n"); for (i=0; i<3; i++) { move_servo_inc(jt2, i, 10); } for (i=3; i<6; i++) { move_servo_inc(jt2, i, -10); } } if (tempbyte=='k') { //send byte from hyperterminal rprintf("moving arm_x_2 backwards\n"); for (i=0; i<3; i++) { move_servo_inc(jt2, i, -10); } for (i=3; i<6; i++) { move_servo_inc(jt2, i, 10); } } if (tempbyte=='n') { //send byte from hyperterminal rprintf("moving arm_x_3 forward\n"); for (i=0; i<3; i++) { move_servo_inc(jt3, i, 10); } for (i=3; i<6; i++) { move_servo_inc(jt3, i, -10); } } if (tempbyte=='m') { //send byte from hyperterminal rprintf("moving arm_x_3 backwards\n"); for (i=0; i<3; i++) { move_servo_inc(jt3, i, -10); } for (i=3; i<6; i++) { move_servo_inc(jt3, i, 10); } } //print out sensor data return 34000; // wait for 20ms to stop crazy oscillations (long story) }
Program: 21558 bytes (32.9% Full)(.text + .data + .bootloader)Data: 889 bytes (10.9% Full)(.data + .bss + .noinit)
You need to use Project Designer:
Look at it this way: it frees up the time you would have spent getting boring low-level stuff working so now you have more time to do high level interesting stuff.
hmm, a bit off topic, but there is no sys/axon2.h library anymore in webbotlib 2.06. Maybe I need to copy 1.33 , and then copy 2.06 on top of it? or somthing? ThanksNope, that didn't work. Tonnes of compiler errors if I do that.Nah, I think I will stick with 1.33. Can't get 2.06 to work at all.