To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.legosOpen lugnet.robotics.rcx.legos in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / legOS / 4060
4059  |  4061
Subject: 
Kernel freeze when attempting to use rotation sensor
Newsgroups: 
lugnet.robotics.rcx.legos
Date: 
Sat, 12 Jun 2010 10:18:28 GMT
Viewed: 
32206 times
  
Hi,

I've tried using the latest BrickOS and the latest BIBO with patches (from here:
http://sourceforge.net/tracker/?func=detail&aid=2858992&group_id=58151&atid=486699
), both with the same result. I don't know if nobody's really used a rotation
sensor in 4 years (unlikely), or if my code just fails (likely), but every time
I run it, the kernel crashes when using the rotation sensor the SECOND TIME
AROUND (NOT THE FIRST TIME). The code in its entirety is posted below (it's for
a slightly modified version of the Plotter from the Ultimate Builders' Set):

#include <dmotor.h>
#include <dsensor.h>
#include <unistd.h>
#include <conio.h>
#include <lnp.h>

int charpos;
int line;

#define PAPER_WIDTH 10
#define PAPER_HEIGHT 13

void fosrotate(int drotations){ // Counts rotations using the Fibre Optic
System, which actually works rather well as a rotation sensor.
  unsigned int rotations = 0;
  while(rotations<drotations){
    while(SENSOR_2!=0xFFC0){
    }
    rotations += 1;
    while(SENSOR_2>0x9000){
    }
    rotations += 1;
  }
}

void up(int x){ // Paper down x/16 teeth (no typo - pen goes up paper)
  ds_rotation_on(&SENSOR_1);
  ds_rotation_set(&SENSOR_1,0);
  msleep(100);
  motor_b_speed(MAX_SPEED);
  motor_b_dir(rev);
  while(ROTATION_1>-x){
    msleep(100);
    lcd_number(ROTATION_1,sign,e0);
  }
  motor_b_dir(brake);
  ds_rotation_off(&SENSOR_1);
}

void down(int x){ // Paper up x/16 teeth (no typo - pen goes down paper)
  ds_rotation_on(&SENSOR_1);
  ds_rotation_set(&SENSOR_1,0);
  msleep(100);
  motor_b_speed(MAX_SPEED);
  motor_b_dir(fwd);
  while(ROTATION_1<x){
    msleep(100);
    lcd_number(ROTATION_1,sign,e0);
  }
  motor_b_dir(brake);
  ds_rotation_off(&SENSOR_1);
}

void left(int x){ // Pen left x/16
  motor_c_dir(rev);
  fosrotate(x);
  motor_c_dir(brake);
}

void right(int x){ // Pen right x/16 teeth
  motor_c_dir(fwd);
  fosrotate(x);
  motor_c_dir(brake);
}

void pup(){
  motor_a_dir(fwd);
  sleep(7);
  motor_a_dir(brake);
}

void pdown(){
  motor_a_dir(rev);
  sleep(12);
  motor_a_dir(brake);
}

void cr(){
  // Carriage to far left
  motor_c_speed(MAX_SPEED);
  motor_c_dir(rev);
  msleep(500);
  while(!TOUCH_3){
    msleep(100);
  }
  // Carriage to print position (2 teeth right)
//  motor_c_dir(fwd);
//  fosrotate(32);
//  motor_c_dir(brake);
  right(32);
  charpos = 0;
}

void lf(){
  // Feed paper for a whole rotation of the output axle (24 * 16)
//  ds_rotation_set(&SENSOR_1,0);
//  ds_rotation_on(&SENSOR_1);
//  motor_b_speed(MAX_SPEED);
//  motor_b_dir(fwd);
//  while(ROTATION_1<384){
//    msleep(100);
//  }
//  motor_b_dir(brake);
  down(100);
  line += 1;
  if(line > PAPER_HEIGHT){
    cputc_native_user(CHAR_P, CHAR_C, CHAR_L, CHAR_A);
    cputc_native_5(CHAR_4);
    while(getchar() != KEY_VIEW){
    }
    line = 0;
    lf();
  }
}

void draw_a_letter(char letter){
  if(letter == 10){ // LF
    lf();
    return;
  }
  if(letter == 13){ // CR
    cr();
    return;
  }
  if(letter == 'A'){
    pdown();
    down(80);
    up(80);
    right(40);
    down(40);
    left(50);
    right(50);
    down(40);
    pup();
    up(80);
    right(10);
    return;
  }
}

void addr_handler_1(const unsigned char *data, unsigned char length, unsigned
char src)
{
  int i;
  for(i=0;i<length;++i){ // Print
    draw_a_letter(data[i]);
  }
}

int main(){
  line = 0;
  ds_active(&SENSOR_1);
  ds_active(&SENSOR_2);
  ds_passive(&SENSOR_3);
  // Do initial Penup, CRLF
  pup();
  cr();
  lf();
  // Wait for message from PC
  lnp_addressing_set_handler (0, addr_handler_1);
  while(!shutdown_requested())
    msleep(1000);
  return 0;
}



I send the letter "A" from the computer and it receives fine. However, when
running the first down(80); instruction, the screen usually shows around 105
(note the lcd_number debug statements) and it completely freezes, with the motor
still running - only taking the battery out and redownloading the kernel will
get it back to normal. Note that this is the second time down(int x) has been
called - the initial CRLF (the LF in particular) calls down(100).

It seems to me that the code to set the rotation sensor's value to 0 doesn't
actually work, and instead freezes the kernel. Anyone else got any clues?



Thanks in advance for any help,

Muzer (Murray Colpman).



Message has 2 Replies:
  Re: Kernel freeze when attempting to use rotation sensor
 
I don't normally bump things, but this has been unanswered for over two weeks, so I think it deserves it. I really can't believe that rotation sensors would be this broken, and yet, I can't see anything wrong with my code. It really is odd... (14 years ago, 24-Jun-10, to lugnet.robotics.rcx.legos)
  Re: Kernel freeze when attempting to use rotation sensor
 
Greetings, I would suggest comparing this code with other programs that make use of rotation sensors, such as the following: * LDCC - (URL) particular, dccdemo.c uses a rotation sensor as part of a DCC throttle. * Power Functions - (URL) this thread (...) (14 years ago, 17-Jul-10, to lugnet.robotics.rcx.legos)

3 Messages in This Thread:


Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

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