go_away

Author Topic: Axon plus Ez1 plus webbot = I need better programming skills  (Read 1923 times)

0 Members and 1 Guest are viewing this topic.

Offline AsellithTopic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 648
  • Helpful? 9
  • "I'm a leaf on the wind. Watch how I soar"
Axon plus Ez1 plus webbot = I need better programming skills
« on: October 31, 2009, 10:09:07 AM »
Ok I am trying to implement an ez1 onto my robot. I have the axon hooked up and runnign my servos great. Just a word here WOW thanks I got the first half up and running in now time. Didn't get the bootloader working but I have an ISP so no big deal.

Anyway to my problem.

I keeps getting errors with the EZ1 code and I think I am missing something small.
Code: [Select]
#include "sys/axon.h" // Select Axon as Board Type

// Now include any other files that are needed here
#include "servoPWM.h"
#include "Sensors\Distance\Maxbotix\EZ1.h"
//Define Servos
//Numbers labled on physical construction. Only important thing is that the number go in order
//clockwise around the robot frame.
SERVO servo1 = MAKE_SERVO(FALSE, H3,1500, 500);
SERVO servo2 = MAKE_SERVO(FALSE, H5,1500, 500);
SERVO servo3 = MAKE_SERVO(FALSE, H4,1500, 500);


MaxSonarEZ1 sensor = MAKE_MaxSonarEZ1(F0);

//Make Servo List
SERVO_LIST servos[] = {&servo1, &servo2, &servo3};

// Create a driver for the list of servos
SERVO_DRIVER bank1 = MAKE_SERVO_DRIVER(servos);
int direction = 0;
//Initialize Hardware
void appInitHardware(void){

// Initialise the servo controller
servoPWMInit(&bank1);
// Give each servo a start value of 'stop'
act_setSpeed(&servo1,0);
act_setSpeed(&servo2,0);
act_setSpeed(&servo3,0);

distanceInit(sensor);

}


// This routine is called once to allow you to set up any other variables in your program
// You can use 'clock' function here.
// The loopStart parameter has the current clock value in žS
TICK_COUNT appInitSoftware(TICK_COUNT loopStart){


return 0; // dont pause after
}
// This routine is called repeatedly - its your main loop
TICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart){


distanceRead(sensor);

if (sensor.distance.cm; > 25)
{
act_setSpeed(&servo1,DRIVE_SPEED_MAX);
act_setSpeed(&servo2,DRIVE_SPEED_MAX);
act_setSpeed(&servo3,DRIVE_SPEED_MIN);

}
else
{
act_setSpeed(&servo1,DRIVE_SPEED_MIN);
act_setSpeed(&servo2,DRIVE_SPEED_MIN);
act_setSpeed(&servo3,DRIVE_SPEED_MAX);


}

return 1000000; // wait for 10 seconds before calling me again. 1000000us = 1 second
}

I get this error
Quote
../OSCAR_AXON.c:16: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sensor'

Am i missing a declaration or something in the includes? Ideas?

Edit: Also is the F0 port the right port for the 0 ADC channel on the axon? I made that assumption without busting out the 640 datasheet

« Last Edit: October 31, 2009, 10:10:52 AM by Asellith »
Jonathan Bowen
CorSec Engineering
www.corseceng.com

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,132
  • Helpful? 108
Re: Axon plus Ez1 plus webbot = I need better programming skills
« Reply #1 on: October 31, 2009, 11:08:21 AM »
Line 16 should be:
Code: [Select]
Maxbotix_EZ1 sensor = MAKE_Maxbotix_EZ1(F0);
Edit: its my fault - I need better documentation skills !!!
« Last Edit: October 31, 2009, 11:18:18 AM by Webbot »
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline AsellithTopic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 648
  • Helpful? 9
  • "I'm a leaf on the wind. Watch how I soar"
Re: Axon plus Ez1 plus webbot = I need better programming skills
« Reply #2 on: October 31, 2009, 05:08:25 PM »
ok does sensor.distance.in work to get the answer in inches? you only state sensor.distance.cm in the documentation.

BTW compiled fine now. gonna test it on the robot in a bit.
Jonathan Bowen
CorSec Engineering
www.corseceng.com

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,132
  • Helpful? 108
Re: Axon plus Ez1 plus webbot = I need better programming skills
« Reply #3 on: October 31, 2009, 05:29:10 PM »
ok does sensor.distance.in work to get the answer in inches? you only state sensor.distance.cm in the documentation.


No - you can only ready cm.
Keep meaning to get round to a global conversion suite ie
cm <=> inches
cm <=> feet
etc

So if you want to convert cm to inches for now then divide the result by 2.54 or multiply by 0.3937
Of course this requires floating point maths which makes your program bigger if you are not using floating point elsewhere in your program.

If you want to avoid floating point use my Fibonacci calculator here: http://www.societyofrobots.com/fibonnaci_series_calculator.shtml
You will see the 10 bit approximation for 0.3937 is: 1/3 + 1/17 + 1/693

So add this to your code:
#include "fraction.h"
const uint16_t PROGMEM frac_cm_to_in[] = { 0, 3, 17, 693, 0};

To convert the value in cm to inches you can use:-
DISTANCE_TYPE cm = sensor.distance.cm;
DISTANCE_TYPE inches = fraction32(cm, frac_cm_to_in );

You now have a value in inches

Edit:
The reason why sensor.distance.in can't work is that this is accessing a variable. So as well as cm, I would also need to compute the value for inches, feet, meters etc etc every time as well as requiring the RAM to store these conversions. Too much overhead. Hence using 'cm' which is the least common denominator and sensors aren't accurate enough to return 'mm'.
Perhaps, in a later release, once I've done that scaler functions to convert between different scales then I could have routines like
distanceSensorInCM(sensor);
distanceSensorInInches(sensor);
etc
But thats all for the future at the moment.
« Last Edit: October 31, 2009, 05:39:46 PM by Webbot »
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline AsellithTopic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 648
  • Helpful? 9
  • "I'm a leaf on the wind. Watch how I soar"
Re: Axon plus Ez1 plus webbot = I need better programming skills
« Reply #4 on: October 31, 2009, 06:14:29 PM »
Ok I was mostly curious. Code changes work really nice on now. So I can say Phase 1 is complete! I now have an omni wheel robot that avoids objects in a single direction. It doesn't go in a straight line yet but I'm working on that.

On that note: Drive_speed_MAX and Min are ints right? so I can have something like Drive_speed_Max - correction_value right? Also what is the range for that function? I am going to need to start calculating movement in multiple directions and unlike a 2 wheel bot I'll need to change the numbers to a large range of numbers not just on and off.
Jonathan Bowen
CorSec Engineering
www.corseceng.com

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,132
  • Helpful? 108
Re: Axon plus Ez1 plus webbot = I need better programming skills
« Reply #5 on: October 31, 2009, 06:32:24 PM »
Ok I was mostly curious. Code changes work really nice on now. So I can say Phase 1 is complete! I now have an omni wheel robot that avoids objects in a single direction. It doesn't go in a straight line yet but I'm working on that.
Cool!

On that note: Drive_speed_MAX and Min are ints right? so I can have something like Drive_speed_Max - correction_value right? Also what is the range for that function? I am going to need to start calculating movement in multiple directions and unlike a 2 wheel bot I'll need to change the numbers to a large range of numbers not just on and off.
DRIVE_SPEED_MIN is -127 and DRIVE_SPEED_MAX=+127 and so brake = 0
However: the reason for defining constants is that you should NOT rely on those values - ie they may change in the future. No plans....but you've been warned!
So they are currently an 'int8_t' or 'DRIVE_SPEED' data type.
All the servo/motor controller functions will take a value between the two and generate the correct PWM.
You may find the 'interpolate' function listed in 'core.h' to be useful to generate values - read the manual.

Glad all is going ok
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,658
  • Helpful? 169
    • Society of Robots
Re: Axon plus Ez1 plus webbot = I need better programming skills
« Reply #6 on: November 01, 2009, 10:36:50 AM »
Quote
DRIVE_SPEED_MIN is -127 and DRIVE_SPEED_MAX=+127
Shouldn't it be 128? (assuming you didn't do change it intentionally in your code)

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,132
  • Helpful? 108
Re: Axon plus Ez1 plus webbot = I need better programming skills
« Reply #7 on: November 01, 2009, 02:08:33 PM »
Its intentionally 127.
The reason being that
DRIVE_SPEED_MIN (-127) = Full speed reverse, (or servo turned to one end stop)
DRIVE_SPEED_MAX(+127) = Full speed forward (or servo turned to other end stop)
Hence the 'midpoint' = 0 ie Stop (or servo at 'mid point')
So there are 127 forward speeds, and 127 reverse speeds.
The speeds are automatically CLAMPed to the valid range so if you were to use -128 then it would be CLAMPed to -127.
 
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline AsellithTopic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 648
  • Helpful? 9
  • "I'm a leaf on the wind. Watch how I soar"
Re: Axon plus Ez1 plus webbot = I need better programming skills
« Reply #8 on: November 03, 2009, 07:35:14 AM »
Ok I got to say my last project was a pain because I was using a non stream line MCU and writing all my code by myself. I am way ahead of schedule now and don't have any parts for phase 2 yet. So thanks to both Admin and Webbot for the great resources. Now i hope to start adding another layer to that with OSCAR modules.
Jonathan Bowen
CorSec Engineering
www.corseceng.com

 


Get Your Ad Here

data_list