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.
// -------- 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 -------
int16_t now = ms % (TICK_COUNT)10000; // 10 sec for a full swingif(now >= (int16_t)5000){ // Goes from 0ms...5000ms now = (int16_t)10000 - now; // then 5000ms...0ms }
int16_t now = ms % (TICK_COUNT)5000; // 10 sec for a full swingif(now >= (int16_t)2500){ // Goes from 0ms...5000ms now = (int16_t)5000 - now; // then 5000ms...0ms }
// -------- 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 -------
DRIVE_SPEED speed = interpolate(now, 0, 5000, DRIVE_SPEED_MIN, DRIVE_SPEED_MAX);
DRIVE_SPEED speed = interpolate(now, 0, 2500, DRIVE_SPEED_MIN, DRIVE_SPEED_MAX);
oops, forgot to change this tooCode: [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
while(1){act_setSpeed(right_wheel_servo,DRIVE_SPEED_MIN);delay_ms(5000);act_setSpeed(right_wheel_servo,DRIVE_SPEED_MAX);delay_ms(5000);}
am I right in thinking 'delay_ms(5000)' means wait for 5 seconds? I've been using 'delay_cycles()'. What's the difference?
#include "hardware.h"// Initialise the hardwarevoid appInitHardware(void) { initHardware();}// Initialise the softwareTICK_COUNT appInitSoftware(TICK_COUNT loopStart){ return 0;}// This is the main loopTICK_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;}
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?
rprintf("Speed=%u\n",speed);
rprintf("Speed=%d\n",speed);
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