Project

General

Profile

Revision 066b08bb

ID066b08bbbefc8d476e67e5a2122e1b2a96b22599
Parent cfdb3afa
Child 360e3b6c

Added by Thomas Mullins about 11 years ago

Adding Charles's headlight code

View differences:

scout_avr/Makefile
16 16
HDR=src/*.h
17 17
FLAGS=-Isrc/ros_lib -Isrc -mmcu=$(MCU) -DF_CPU=$(F_CPU)UL -funsigned-char -Os -fpack-struct -Wall
18 18

  
19
ROS_MSG_DEPS=rosserial_msgs std_msgs bom sonar
19
ROS_MSG_DEPS=rosserial_msgs std_msgs bom sonar headlights
20 20

  
21 21
default: scout_avr.hex
22 22

  
scout_avr/src/main.cpp
4 4
#include "bom.h"
5 5
#include "range.h"
6 6
#include "stepper.h"
7
#include "orb.h"
7 8
#include <std_msgs/Int16.h> // TODO remove
8 9
#include <bom/bom.h>
9 10
#include <sonar/sonar_distance.h>
10 11
#include <sonar/sonar_toggle.h>
11 12
#include <sonar/sonar_set_scan.h>
13
#include <headlights/set_headlights.h>
12 14
#include <util/delay.h>
13 15

  
14 16
/* Period of main loop in ms */
......
20 22
{
21 23
}
22 24

  
23
void callback(const std_msgs::Int16& msg)
25
void orb_callback(const headlights::set_headlights& msg)
24 26
{
27
  orb_set0(msg.left_red, msg.left_green, msg.left_blue);
28
  orb_set1(msg.right_red, msg.right_green, msg.right_blue);
25 29
}
26 30

  
27 31
/* dammit, Priya, this capitalization just looks ridiculous */
......
52 56
  ros::NodeHandle nh;
53 57
  nh.initNode();
54 58

  
55
  /* To be removed later; just an example of a subscirber */
56
  ros::Subscriber<std_msgs::Int16> test_in("test_in", callback);
57
  nh.subscribe(test_in);
58

  
59 59
  /* Stepper */
60 60
  // TODO ROS messages to set bounds
61 61
  step_init();
......
83 83
  ros::Publisher bom_pub("bom", &bom_msg);
84 84
  nh.advertise(bom_pub);
85 85

  
86
  /* Headlights (aka Orbs) */
87
  orb_init();
88
  ros::Subscriber<headlights::set_headlights> orb_sub("set_headlights",
89
      orb_callback);
90
  nh.subscribe(orb_sub);
91

  
86 92
  id = 0;
87 93
  next = 0;
88 94
  while (1)
......
104 110
      id = 0;
105 111
    }
106 112
    set_robot_id(id);
107
    bom_send(id & 1);
113
    bom_send(0);
108 114

  
109 115
    /* BOM */
110 116
    for (i = 0; i < 4; i++) {
scout_avr/src/orb.cpp
1
extern "C" {
2
#include <avr/io.h>
3
#include <util/delay.h>
4
}
5
#include "orb.h"
6

  
7
void orb_init() {
8

  
9
  /* set pins to output mode */
10
	DDRB |= _BV(PB4) | _BV(PB5) | _BV(PB6);
11
  DDRE |= _BV(PE3) | _BV(PE4) | _BV(PE5);
12

  
13
  orb_set0(0, 0, 0);
14
  orb_set1(0, 0, 0);
15
  	
16
	/* timer 2 */
17
  TCCR2A |= _BV(COM2A1) | _BV(WGM20);
18
	TCCR2B |= _BV(CS21);
19

  
20
	/* timer 1 */
21
	TCCR1A |= _BV(COM1A1) | _BV(COM1B1) | _BV(WGM10);
22
	TCCR1B |= _BV(CS11);
23

  
24
	/* timer 3 */
25
	TCCR3A |= _BV(COM3A1) | _BV(COM3B1) | _BV(COM3C1) | _BV(WGM30);
26
	TCCR3B |= _BV(CS31);
27
}
28

  
29
void orb_set0(unsigned char r, unsigned char g, unsigned char b) {
30
	OCR1B = r;
31
	OCR1A = g;
32
	OCR2A = b;
33
}
34

  
35
void orb_set1(unsigned char r, unsigned char g, unsigned char b) {
36
	OCR3B = r;
37
	OCR3A = g;
38
	OCR3C = b;
39
}
scout_avr/src/orb.h
1
#ifndef ORB_H
2
#define ORB_H
3

  
4
void orb_init();
5
void orb_set0(unsigned char r, unsigned char g, unsigned char b);
6
void orb_set1(unsigned char r, unsigned char g, unsigned char b);
7

  
8
#endif

Also available in: Unified diff