To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.roboticsOpen lugnet.robotics in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / 22232
Subject: 
[Q] Remote control code ?
Newsgroups: 
lugnet.robotics
Date: 
Sat, 21 Feb 2004 04:29:32 GMT
Viewed: 
3430 times
  
Hi Philo,Steve and Allen.

I've made a YAL right after reading the articles of you all.
It's great and very fun.

After tuning some papameters, it is working so well.

My Lego has been in a dark corner of my room so long time.
New BrickCC/BrickOS help me to follow up all procedures easily.


But, I don't know about "remote control code" !

pid = (Kd * err_diff + Kp * err + Ki * err_int) /3000l + ForwardOffset;

then when you change ForwardOffset (via remote control code) the robot

Please let me know and try to control this Legway in better way.

Kitak.


ps. I've wated for 10 days to get a admission for posting...;


Subject: 
Re: [Q] Remote control code ?
Newsgroups: 
lugnet.robotics
Date: 
Wed, 31 Mar 2004 02:55:05 GMT
Viewed: 
3775 times
  
I’m lazy . . . would someone please write a version of the program that works with the LEGO remote control? Using the remote control is cooler than driving it with a flashlight. And with a flashlight you can’t make it turn.


Subject: 
Re: [Q] Remote control code ?
Newsgroups: 
lugnet.robotics
Date: 
Wed, 31 Mar 2004 04:31:40 GMT
Viewed: 
3811 times
  
In lugnet.robotics, Jordan Bradford wrote:
   I’m lazy . . . would someone please write a version of the program that works with the LEGO remote control? Using the remote control is cooler than driving it with a flashlight. And with a flashlight you can’t make it turn.

Okay, I tried writing it anyway. It doesn’t work, and I think it’s because I’m not changing the motor speeds. All I’m doing is changing motor directions. Help me out, please, since I spent the time to install BrickOS in BricxCC and learn the remote.h and dsound.h APIs. Thanks!

#include <conio.h>
#include <unistd.h>
#include <dmotor.h>
#include <dsensor.h>
#include <dbutton.h>
#include <remote.h>
#include <rom/lcd.h>
#include <dsound.h>

int directionA, directionC;

int remote(unsigned int etype, unsigned int key)
{
  if(etype == LREVT_KEYON)
  {
    switch(key)
    {
    case LRKEY_BEEP:
      dsound_system(DSOUND_BEEP);
      break;
    case LRKEY_A1:
      directionA = fwd;
      break;
    case LRKEY_A2:
      directionA = rev;
      break;
    case LRKEY_C1:
      directionC = fwd;
      break;
    case LRKEY_C2:
      directionC = rev;
      break;
    case LRKEY_STOP:
      break;
    }
  }
  return 1;
}

int main(int argc, char **argv) {
  long offset;
  long err, err_diff, err_int = 0, err_old;
  long pid;

  int Kd = 210, Kp = 180, Ki = 10;

  ds_active(&SENSOR_1);
  ds_active(&SENSOR_3);
  msleep(20);
  offset = (long)SENSOR_1 - (long)SENSOR_3;
  cputs("yal1");
  sleep(2);
  err_old = 0;

  lr_init();
  lr_startup();
  lr_set_handler(remote);

  while(1)
  {
    err = (long)SENSOR_1 - (long)SENSOR_3 - offset;
    err_int = err_int + err + err_old;
    err_diff = (err - err_old);
    err_old = err;

    pid = (Kd * err_diff + Kp * err + Ki * err_int) /3000l;


    if (pid > 255) pid = 255;
    if (pid < -255) pid = -255;

    if (pid < 0)
    {
      directionA = rev;
      directionC = rev;
      pid = -pid;
    }
    else
    {
      directionA = fwd;
      directionC = fwd;
      pid = pid;
    }
    if (pid < 5)
    {
      directionA = brake;
      directionC = brake;
    }

    lcd_int(pid);
    lcd_refresh();

    motor_a_dir(directionA);
    motor_a_speed(pid);
    motor_c_dir(directionC);
    motor_c_speed(pid);

    if(PRESSED(dbutton(), BUTTON_PROGRAM))
    {
      motor_a_dir(brake);
      motor_c_dir(brake);
      ds_passive(&SENSOR_1);
      ds_passive(&SENSOR_3);
      cputs("stop");
      msleep(300);
      while (PRESSED(dbutton(), BUTTON_PROGRAM));
      motor_a_dir(off);
      motor_c_dir(off);
      cls();
      lr_shutdown();
      return(0);
    }
    msleep(20);
  }
}

Some other things:
-Is there any reason the Prgm button is being used to stop the program? Why not just press the Run button again, like in the normal firmware?
-How can I make the Stop button on the remote do what the program currently does when Prgm is pressed? Maybe I’ll cheat and use a goto.

Thanks again!


©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR