Society of Robots - Robot Forum
Software => Software => Topic started by: happy_hippo on July 09, 2011, 11:42:49 AM
-
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.
Simply, if you don't want to read the code below, why can't I use act_setSpeed(servos[i], 10) where
SERVO_LIST servos[] = {&s_0_1r, &s_0_2r, &s_0_3r, &s_0_1l, &s_0_2l, &s_0_3l}; is set in hardware.h
If I just write &s_0_1r everything works.
hardware.h
/*************************************************************************
Authored by John Palmisano of SocietyofRobots.com
in collaboration with Clive Webster of WebbotLib
2009
intended use for Axon and Axon II
instructions:
This file is where you define all of your intended hardware connected to
your 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 name
SERVO_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 servos
SERVO_DRIVER bank1 = MAKE_SERVO_DRIVER(servos);
//////////////////////////////////////////////////////////////
And main program (scroll down to tempbyte == '4'):
/*************************************************************************
AXON AND AXON II CODE FOR WEBBOTLIB
Authored by John Palmisano of SocietyofRobots.com
in collaboration with Clive Webster of WebbotLib.
For more information, see:
http://www.societyofrobots.com/axon
http://www.societyofrobots.com/axon2
http://sourceforge.net/projects/webbotavrclib
2009
intended use for Axon and Axon II
instructions:
Read comments for explanation of all code.
appInitHardware() is for initiating the Axon.
appControl() is where your code goes. It is similar to control.c
for 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 control
void 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 loop
TICK_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)
}
Simply, if you don't want to read the code, why can't I use act_setSpeed(servos[i], 10) where
SERVO_LIST servos[] = {&s_0_1r, &s_0_2r, &s_0_3r, &s_0_1l, &s_0_2l, &s_0_3l};
Any suggestions?
Thanks
-
Any ideas? It should be something easy ???
There is no compiler error, so the type is fine if I use servo[1] etc..
But it's just not working..
Thanks
-
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.
[ ... ]
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 act_setSpeed(servos[i], 10) where
SERVO_LIST servos[] = {&s_0_1r, &s_0_2r, &s_0_3r, &s_0_1l, &s_0_2l, &s_0_3l};
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.
Are you getting any errors or warnings from the compiler?
Joe
-
It has been awhile since I played with something like this. But if I remember correctly the servo list is in program space and you can not use directly. Looking at my brat program, I did something like:
SERVO* servo = null;
...
servo = (SERVO *)pgm_read_word(&pservos[sSN]);
And then I used the servo variable
act_setSpeed(servo, 0);
Kurt
-
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.
I don't really know what it requires , because it's a webbotlib library. In the "External Dependencies" folder of AVR studio there's a few things listed, including actuators.h, which I think has this function. I uploaded the code here: http://codepad.org/pQEJ9LNV (http://codepad.org/pQEJ9LNV)
There's also servos.h file, the code is here: http://codepad.org/rHAQSZ7A. (http://codepad.org/rHAQSZ7A.)
I'm not advanced enough with C to understand that code yet :(
Code:
SERVO* servo = null;
...
servo = (SERVO *)pgm_read_word(&pservos[sSN]);
And then I used the servo variable
Code:
act_setSpeed(servo, 0);
Could you please explain what each line does?
Also, I have another question about Webbotlib, I found this in documentation:
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 );
What is this PROGMEM stuff? the documentation doesn't explain it very well: http://webbot.org.uk/WebbotLibDocs/27190.html (http://webbot.org.uk/WebbotLibDocs/27190.html)
thank you
-
What I am saying is that the servo list may not be in normal program memory space.
You might experiment changing:
act_setSpeed(servos[i], 10)
to something like:
act_setSpeed((SERVO *)pgm_read_word(&servos[i]), 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:
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)
That worked perfectly, thank you very much :D
-
Code:
SERVO* servo = null;
...
servo = (SERVO *)pgm_read_word(&pservos[sSN]);
And then I used the servo variable
Code:
act_setSpeed(servo, 0);
Could you please explain what each line does?
I've been looking at what's here, but I don't have enough information to be able to say without guessing. I usually have bad experiences when I guess though.
It's not obvious how structs are defined or initialized. There are some very good reasons for writing code that hides those kinds of details, but understanding it does require access to header files and stuff I don't have.
Also, I have another question about Webbotlib, I found this in documentation:
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 );
What is this PROGMEM stuff? the documentation doesn't explain it very well: http://webbot.org.uk/WebbotLibDocs/27190.html (http://webbot.org.uk/WebbotLibDocs/27190.html)
PROGMEM is a special compiler directive that tells it to store variables in the controller's flash memory instead of in RAM. Since RAM is limited, larger variables and arrays can be stored in flash, and pulled into memory when needed.
I haven't read the documentation, but if it differs from what I just said, go with what the docs say.
I've been getting more impressed with the webbot library, and I'm thinking about downloading it to check it out some more. Might even wind up buying one of those new fangled Mote thingies.
Sorry I couldn't help more.
Joe
-
You can see an example of servo control with arrays in my Biped Engine:
http://www.societyofrobots.com/sor_biped_engine.shtml (http://www.societyofrobots.com/sor_biped_engine.shtml)
WebbotLib Gait Designer can also help you out.