go away spammer

Author Topic: Newbie help needed with WebBot example program  (Read 2810 times)

0 Members and 1 Guest are viewing this topic.

Offline KelpyTopic starter

  • Full Member
  • ***
  • Posts: 83
  • Helpful? 0
Newbie help needed with WebBot example program
« on: October 04, 2010, 12:34:09 PM »
Probably a really stupid question, but I would be very grateful if someone could help me.
I have this example program produced using the WebBotLib Project Designer.
Code: [Select]
// -------- Start Actuators -------
// To control your.motors/servos then see actuators.h in the manual // To retrieve the required speed of right_wheel_servo use:
// DRIVE_SPEED speed=act_getSpeed(right_wheel_servo);
// To set the required speed of right_wheel_servo use:
// act_setSpeed(right_wheel_servo,speed);
// This example will move the motors back and forth using the loopStart time:
TICK_COUNT ms = loopStart / 1000; // Get current time in ms
int16_t now = ms % (TICK_COUNT)10000; // 10 sec for a full swing
if(now >= (int16_t)5000){ // Goes from 0ms...5000ms
now = (int16_t)10000 - now; // then 5000ms...0ms
}
// Map it into DRIVE_SPEED range
DRIVE_SPEED speed = interpolate(now, 0, 5000, DRIVE_SPEED_MIN, DRIVE_SPEED_MAX);
// Set speed for all motors/servos
act_setSpeed(&right_wheel_servo,speed);
act_setSpeed(&left_wheel_servo,speed);
act_setSpeed(&scan_servo,speed);
// -------- End   Actuators -------

It swings the scan_servo from one side to the other in 10 seconds.

How can I make it do it in 5 seconds?
I know nothing about programming - I don't even know what int16_t is :-[

Offline madsci1016

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,450
  • Helpful? 43
    • Personal Website
Re: Newbie help needed with WebBot example program
« Reply #1 on: October 04, 2010, 12:53:10 PM »
change

Code: [Select]
int16_t now = ms % (TICK_COUNT)10000; // 10 sec for a full swing
if(now >= (int16_t)5000){ // Goes from 0ms...5000ms
now = (int16_t)10000 - now; // then 5000ms...0ms
}

to

Code: [Select]
int16_t now = ms % (TICK_COUNT)5000; // 10 sec for a full swing
if(now >= (int16_t)2500){ // Goes from 0ms...5000ms
now = (int16_t)5000 - now; // then 5000ms...0ms
}

at least that's what i think will do it.

Offline KelpyTopic starter

  • Full Member
  • ***
  • Posts: 83
  • Helpful? 0
Re: Newbie help needed with WebBot example program
« Reply #2 on: October 04, 2010, 01:05:00 PM »
Hi madsci1016 , thanks for the suggestion, but I already tried that.
All it does is make the servo go from the middle to the far left and back again, without ever going right.
Still travels at the same speed.
I have at long last managed to get my bot doing it's avoidance thing, using the Sharp, but is not that successful. It needs the servo to scan quicker from side to side.

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: Newbie help needed with WebBot example program
« Reply #3 on: October 04, 2010, 01:23:49 PM »
For a 5 second swing then try:-
Code: [Select]
// -------- Start Actuators -------
// To control your.motors/servos then see actuators.h in the manual // To retrieve the required speed of right_wheel_servo use:
// DRIVE_SPEED speed=act_getSpeed(right_wheel_servo);
// To set the required speed of right_wheel_servo use:
// act_setSpeed(right_wheel_servo,speed);
// This example will move the motors back and forth using the loopStart time:
TICK_COUNT ms = loopStart / 1000; // Get current time in ms
int16_t now = ms % (TICK_COUNT)5000; // 5 sec for a full swing
if(now >= (int16_t)2500){ // Goes from 0ms...2500ms
now = (int16_t)5000 - now; // then 2500ms...0ms
}
// Map it into DRIVE_SPEED range
DRIVE_SPEED speed = interpolate(now, 0, 2500, DRIVE_SPEED_MIN, DRIVE_SPEED_MAX);
// Set speed for all motors/servos
act_setSpeed(&right_wheel_servo,speed);
act_setSpeed(&left_wheel_servo,speed);
act_setSpeed(&scan_servo,speed);
// -------- End   Actuators -------
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 madsci1016

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,450
  • Helpful? 43
    • Personal Website
Re: Newbie help needed with WebBot example program
« Reply #4 on: October 04, 2010, 01:24:03 PM »
oops, forgot to change this too

Code: [Select]
DRIVE_SPEED speed = interpolate(now, 0, 5000, DRIVE_SPEED_MIN, DRIVE_SPEED_MAX);
to

Code: [Select]
DRIVE_SPEED speed = interpolate(now, 0, 2500, DRIVE_SPEED_MIN, DRIVE_SPEED_MAX);
EDIT: dang, beaten by seconds!

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: Newbie help needed with WebBot example program
« Reply #5 on: October 04, 2010, 01:29:20 PM »
oops, forgot to change this too

Code: [Select]
DRIVE_SPEED speed = interpolate(now, 0, 5000, DRIVE_SPEED_MIN, DRIVE_SPEED_MAX);
to

Code: [Select]
DRIVE_SPEED speed = interpolate(now, 0, 2500, DRIVE_SPEED_MIN, DRIVE_SPEED_MAX);
EDIT: dang, beaten by seconds!

Dang:- you also forgot to fix the comments  ;) :D
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 madsci1016

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,450
  • Helpful? 43
    • Personal Website
Re: Newbie help needed with WebBot example program
« Reply #6 on: October 04, 2010, 01:38:02 PM »
Dang:- you also forgot to fix the comments  ;) :D

and?

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: Newbie help needed with WebBot example program
« Reply #7 on: October 04, 2010, 02:08:14 PM »
try this less fancy method . . . it'll help you understand the concepts, although not the most 'optimal' ;D

Code: [Select]
while(1)
{
act_setSpeed(right_wheel_servo,DRIVE_SPEED_MIN);
delay_ms(5000);
act_setSpeed(right_wheel_servo,DRIVE_SPEED_MAX);
delay_ms(5000);
}

Offline KelpyTopic starter

  • Full Member
  • ***
  • Posts: 83
  • Helpful? 0
Re: Newbie help needed with WebBot example program
« Reply #8 on: October 05, 2010, 08:26:24 AM »
Great! ;D

Thanks for all your help, guys. I've used madsci1016's partial, and Webbot's suggestion, and gone one step further so it scans in 2.5seconds.

It works much better now, but I am going to try and make it backup a little before turning, so it won't get stuck in corners. :o

May need some more help, as it is all experimentation. I've never even seen C until about 3 weeks ago :-[

Admin, thanks for the suggestion, and surprisingly, I actually get it ;D One thing, am I right in thinking 'delay_ms(5000)' means wait for 5 seconds? I've been using 'delay_cycles()'. What's the difference?

One other thing, (probably for Webbot), when I print the values of 'speed' (which is the value sent to the scan servo), one side prints something like 0 to 128, and the other side the values are something like 65500 to 66000. Why is that?

Very grateful for your time, all of you. :)
« Last Edit: October 05, 2010, 08:32:44 AM by Kelpy »

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: Newbie help needed with WebBot example program
« Reply #9 on: October 05, 2010, 09:23:48 AM »
Quote
am I right in thinking 'delay_ms(5000)' means wait for 5 seconds? I've been using 'delay_cycles()'. What's the difference?
A cycle is the time it takes to loop within an empty while loop.

The function delay_ms() requires more processing, which means it takes several clock cycles for it to work properly. So if you need to delay shorter than that, thats when you use cycles. The WebbotLib manual explains it better.


edit: I misspoke
« Last Edit: October 05, 2010, 11:44:10 AM by Admin »

Offline KelpyTopic starter

  • Full Member
  • ***
  • Posts: 83
  • Helpful? 0
Re: Newbie help needed with WebBot example program
« Reply #10 on: October 05, 2010, 11:00:37 AM »
Thanks Admin. I'll use what WebBotLib suggests.

Nearly there, but I have another problem.
It doesn't matter what angle the robot approaches a wall, it alway tries to turn left. Probably my coding. Perhaps someone could take a look. The relevant bit is about 2/3 the way down.

Code: [Select]
#include "hardware.h"

// Initialise the hardware
void appInitHardware(void) {
initHardware();


}
// Initialise the software
TICK_COUNT appInitSoftware(TICK_COUNT loopStart){
return 0;
}
// This is the main loop
TICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart) {

// long delay;

// -------- Start Switch/Button-------
// Switch/Button - see switch.h


// To test if it is pressed then
if(SWITCH_pressed(&button)){
// pressed
}

// To test if it is released then
if(SWITCH_released(&button)){
// released
}

// -------- End   Switch/Button-------


// -------- Start Sharp GP2-------
// Read the Sharp GP2 and store the result in distance.distance.cm
distanceRead(distance);

// The value can be printed using %u eg rprintf("Distance=%u",distance.distance.cm);

rprintf("Distance=%u\n",distance.distance.cm);

// or dumped using:
// rprintf("distance: ");
// distanceDump(distance);
// rprintfCRLF();
// -------- End   Sharp GP2-------

// -------- Start Actuators -------
// To control your.motors/servos then see actuators.h in the manual // To

retrieve the required speed of right_wheel_servo use:
// DRIVE_SPEED speed=act_getSpeed(right_wheel_servo);
// To set the required speed of right_wheel_servo use:
// act_setSpeed(right_wheel_servo,speed);
// This example will move the motors back and forth using the loopStart time:
TICK_COUNT ms = loopStart / 1000; // Get current time in ms
int16_t now = ms % (TICK_COUNT)2500; // 2.5 sec for a full swing
if(now >= (int16_t)1250){ // Goes from 0ms...1250ms
now = (int16_t)2500 - now; // then 2500ms...0ms
}
// Map it into DRIVE_SPEED range
DRIVE_SPEED speed = interpolate(now, 0, 1250, DRIVE_SPEED_MIN, DRIVE_SPEED_MAX);
// Set speed for all motors/servos

rprintf("Speed=%u\n",speed);

act_setSpeed(&scan_servo,speed); //scan servo

scan side to side

//******************************************************************************//

if(distance.distance.cm<30 && speed>65000) //scanner at left of

centre
{

act_setSpeed(&right_wheel_servo,DRIVE_SPEED_MIN); //turn right
act_setSpeed(&left_wheel_servo,DRIVE_SPEED_MAX);

delay_cycles(US_TO_CYCLES(50)); //settle down,now

}

else if(distance.distance.cm<30 && speed<150) //scanner at right of centre

{

act_setSpeed(&right_wheel_servo,DRIVE_SPEED_MAX); //turn left
act_setSpeed(&left_wheel_servo,DRIVE_SPEED_MIN);

delay_cycles(US_TO_CYCLES(50)); //settle down,now

}


else //go forwards

{

act_setSpeed(&right_wheel_servo,DRIVE_SPEED_MAX);
act_setSpeed(&left_wheel_servo,DRIVE_SPEED_MAX);

delay_cycles(20);

}

// -------- End   Actuators -------

return 20000;
}

Thanks alot.

I should mention, that the criteria I am using to decide whether to turn left or right, is the 'speed' variable sent to the servos by the main loop, as mentioned above. I still don't understand them :-[

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: Newbie help needed with WebBot example program
« Reply #11 on: October 05, 2010, 11:16:09 AM »
One other thing, (probably for Webbot), when I print the values of 'speed' (which is the value sent to the scan servo), one side prints something like 0 to 128, and the other side the values are something like 65500 to 66000. Why is that?
Coz you are using:
Code: [Select]
rprintf("Speed=%u\n",speed);
Where %u means an 'unsigned number' but the speeds are actually 'signed numbers' - so use %d instead:-
Code: [Select]
rprintf("Speed=%d\n",speed);

That probably also explains your new turning problem. ie  where you are comparing for0 speed > 65000 etc
The speed can only ever be between -127 and +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 Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: Newbie help needed with WebBot example program
« Reply #12 on: October 05, 2010, 11:47:52 AM »
Nearly there, but I have another problem.
It doesn't matter what angle the robot approaches a wall, it alway tries to turn left. Probably my coding. Perhaps someone could take a look.

I should mention, that the criteria I am using to decide whether to turn left or right, is the 'speed' variable sent to the servos by the main loop, as mentioned above. I still don't understand them :-[
You don't need the speed variable in the loop . . . and your threshold for your sensor (which is currently 30), would make a difference if changed.

Offline KelpyTopic starter

  • Full Member
  • ***
  • Posts: 83
  • Helpful? 0
Re: Newbie help needed with WebBot example program
« Reply #13 on: October 05, 2010, 12:05:50 PM »
Aw....thanks fellas.
Am I chuffed, or what ;D ;D ;D ;D
It works brilliantly....well and truly hooked now.
Must do a video. ::)

Thank you all so much for your help (and the site in general - great job). ;D ;D ;D ;D ;D ;D ;D ;D ;D

Offline KelpyTopic starter

  • Full Member
  • ***
  • Posts: 83
  • Helpful? 0
Re: Newbie help needed with WebBot example program
« Reply #14 on: October 06, 2010, 09:02:54 AM »
As promised, a short video of my bot in action. Still needs 'tinkering and fine-tuning' but I'm pleased with the way it works.
Must get an omni-wheel, and larger back wheels :-[

http://www.youtube.com/watch?v=GwMVV8o2E5M
« Last Edit: October 06, 2010, 09:14:44 AM by Kelpy »

 


Get Your Ad Here

data_list