Table of ContentsControlling the Hardware

Some of the components that you can build to increase and monitor the performance of your car have library functions defined that simplify their usage tremendously. They are all described in detail in the IC Manual, but due to version changes, a few commands are not correct. Here we will cover those functions and introduce a few of the more important ones that you will need. This page should contain all the information you need to implement your car.

  • MOTOR COMMANDS

    The basic motor function is:
    void motor(int m, int p)
    
    
    where m is the motor port number and p is the power. Using the special motor drivers, a power of -100 turns the motor off and 100 runs it at full speed.

  • SERVO COMMANDS

    The servo can be controlled through functions loaded up from the servo.c library file. To load the functions to the board, type:
    C> load servo.c
    
    
    The servo can then be positioned to any degree point around a circle. The function:
    servo_on();
    
    
    enables the servo and allows calls to:
    servo(int p)
    
    
    to position the servo at a radial position denoted in radians by p;

  • SHAFT ENCODERS

    The rotation counter, or shaft encoder, enables you to determine how many times a gear spins. The libray encoders.lis needs to be loaded before the encoder can be used. Once loaded, the function:
    enable_encoder(int p)
    
    
    initializes an encoder on digital port p. Ports 0 and 1 are the reccommended ports for encoders. This function sets a variable, port0_shaft_count (assuming port 0 was used) that counts the number of pulses generated by the encoder. The sampling rate is 1000 Hz (1000 times a second). This varibale can be set to anything you want since it is just a global varibale defined on the board. For instance, if if you want to find out how many rotations happen while a loop is exectuing, set the variable to 0 at the beginning of the loop and read the value at the end of the loop.

  • DIP SWITCHES

    The board has four dip switches on the board that can be used to send information to the program.
    int dip_switch(int s)
    
    
    returns the value, 1 for on and 0 for off, of switch s.

  • PORTS

    All of the digital and analog ports can return values. If a sensor is connected to a digital port,
    int digital(int p)
    
    
    returns a 1 or 0 depending on the state of the sensor on port p.
    int analog(int p)
    
    
    returns a number from 0 to 255 indicating the voltage range across port p.

  • TIME COMMANDS

    IC also has a few time commands to get and set the system time.
    void reset_system_time()
    
    
    sets the system time to 0. The two commands,
    long mseconds()
    float seconds()
    
    
    return the system time in milliseconds and seconds, resp, and
    void sleep(float sec)
    
    
    waits sec seconds before continuing with the program.
  • Oids Homepage