Don't ad-block us - support your favorite websites. We have safe, unobstrusive, robotics related ads that you actually want to see - see here for more.
0 Members and 1 Guest are viewing this topic.
act_setSpeed(servos[i], 10)
SERVO_LIST servos[] = {&s_0_1r, &s_0_2r, &s_0_3r, &s_0_1l, &s_0_2l, &s_0_3l};
/*************************************************************************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)SERVO s_0_1l = MAKE_SERVO(FALSE, B7, 1500, 900);SERVO s_0_2l = MAKE_SERVO(FALSE, B6, 1500, 900);SERVO s_0_3l = MAKE_SERVO(FALSE, B5, 1500, 900);SERVO s_0_1r = MAKE_SERVO(FALSE, B4, 1500, 900);SERVO s_0_2r = MAKE_SERVO(FALSE, H6, 1500, 900);SERVO s_0_3r = MAKE_SERVO(FALSE, H5, 1500, 900);// Create the list - remember to place an & at the// start of each servo nameSERVO_LIST servos[] = {&s_0_1r, &s_0_2r, &s_0_3r, &s_0_1l, &s_0_2l, &s_0_3l};// Create a driver for the list of servosSERVO_DRIVER bank1 = MAKE_SERVO_DRIVER(servos);//////////////////////////////////////////////////////////////
/*************************************************************************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) // Initiate Sensors (examples commented out) //accelerometerInit(accm3d2); //compassInit(hmc6343); //gyroInit(idg300); }TICK_COUNT appInitSoftware(TICK_COUNT loopStart){ rprintf("\nAxon Initiated.\n\n");return 0;}int tempbyte;// This is the main loopTICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart) { tempbyte=UART2_GET;//get a single character //power servos if (tempbyte=='1') { servosDisconnect(&bank1);//turn servos off rprintf("servos off\n"); } if (tempbyte=='2') { servosConnect(&bank1);//turn servos on rprintf("servos on\n"); } if (tempbyte=='4') { //send byte from hyperterminal for (uint16_t i=0 ; i<2 ; i++){ act_setSpeed(servos[i], act_getSpeed(servos[i])+10); //more right side servos delay_ms(2000); rprintf("moving servos forward1\n"); } } //print out sensor data return 2000; // wait for 20ms to stop crazy oscillations (long story) }
Hello, I don't want to type all the servo names that I have connected to axon2, is it possible to address them as elements of an array? I tried using the following code, but nothing happens, the servo jitters once and that's it.[ ... ]Code: [Select] if (tempbyte=='4') { //send byte from hyperterminal for (uint16_t i=0 ; i<2 ; i++){ act_setSpeed(servos[i], act_getSpeed(servos[i])+10); //more right side servos delay_ms(2000); rprintf("moving servos forward1\n"); }Simply, if you don't want to read the code, why can't I use Code: [Select]act_setSpeed(servos[i], 10) whereCode: [Select]SERVO_LIST servos[] = {&s_0_1r, &s_0_2r, &s_0_3r, &s_0_1l, &s_0_2l, &s_0_3l};
if (tempbyte=='4') { //send byte from hyperterminal for (uint16_t i=0 ; i<2 ; i++){ act_setSpeed(servos[i], act_getSpeed(servos[i])+10); //more right side servos delay_ms(2000); rprintf("moving servos forward1\n"); }
SERVO* servo = null;...servo = (SERVO *)pgm_read_word(&pservos[sSN]);
act_setSpeed(servo, 0);
What's the prototype for act_setSpeed() ? I don't see anything obviously wrong, but it would be nice to know what the function is expecting.
Code:SERVO* servo = null;...servo = (SERVO *)pgm_read_word(&pservos[sSN]);And then I used the servo variableCode:act_setSpeed(servo, 0);
For example: if your old code was something like -SERVO_LIST myServo[] = { &servo1, &servo2 );then it should be changed to -SERVO_LIST PROGMEM myServo[] = { &servo1, &servo2 );
act_setSpeed((SERVO *)pgm_read_word(&servos[i]), 10)
Code:act_setSpeed((SERVO *)pgm_read_word(&servos), 10)Which should hopefully setup the code to get the value out of the program space (not your normal data space like your code is currently doing)
Code:SERVO* servo = null;...servo = (SERVO *)pgm_read_word(&pservos[sSN]);And then I used the servo variableCode:act_setSpeed(servo, 0);Could you please explain what each line does?
Also, I have another question about Webbotlib, I found this in documentation:QuoteFor example: if your old code was something like -SERVO_LIST myServo[] = { &servo1, &servo2 );then it should be changed to -SERVO_LIST PROGMEM myServo[] = { &servo1, &servo2 );What is this PROGMEM stuff? the documentation doesn't explain it very well: http://webbot.org.uk/WebbotLibDocs/27190.html