Skip to content
This repository has been archived by the owner on Jul 1, 2018. It is now read-only.

Servo #263

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Servo #263

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
380 changes: 217 additions & 163 deletions eda/controller.brd

Large diffs are not rendered by default.

496 changes: 275 additions & 221 deletions eda/controller.sch

Large diffs are not rendered by default.

425 changes: 224 additions & 201 deletions eda/grizzly_bear.brd

Large diffs are not rendered by default.

334 changes: 185 additions & 149 deletions eda/grizzly_bear.sch

Large diffs are not rendered by default.

49 changes: 46 additions & 3 deletions smartsensor_fw/deploy/ss_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
},

"analog-in": {
"description": "This is a digital sensor. It can be used to get the " + \
"state of up to four switches.",
"description": "This is a analog sensor. It can be used to get the " + \
"state of up to four inputs.",
"chunksNumer": 0xFF,
"chunksDenom": 0xFF,
"channels": [
Expand Down Expand Up @@ -104,7 +104,50 @@
"additional": array('B', [0x01, 0xFF, 0xFF])
},
]
}
},

"solenoid": {
"description": "This is a solenoid. It can be used to control " + \
"up to four solenoids.",
"chunksNumer": 0xFF, # TODO(cduck): What is this?
"chunksDenom": 0xFF,
"channels": [
gameModeChannel,
{ "description": "This is the first digital channel.",
"type": 0x04,
"additional": array('B', [0x01, 0xFF, 0xFF])
},
{ "description": "This is the second digital channel.",
"type": 0x04,
"additional": array('B', [0x01, 0xFF, 0xFF])
},
{ "description": "This is the third digital channel.",
"type": 0x04,
"additional": array('B', [0x01, 0xFF, 0xFF])
},
{ "description": "This is the fourth digital channel.",
"type": 0x04,
"additional": array('B', [0x01, 0xFF, 0xFF])
},
]
},
"servo": {
"description": "This is a servo. It can be used to control " + \
"up to two servos.",
"chunksNumer": 0xFF,
"chunksDenom": 0xFF,
"channels": [
gameModeChannel,
{ "description": "This is the first analog channel.",
"type" : 0x03,
"additional": array('B', [0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x01])
},
{ "description": "This is the second analog channel.",
"type" : 0x03,
"additional": array('B', [0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x01])
}
]
},
}

def allTypes():
Expand Down
28 changes: 28 additions & 0 deletions smartsensor_fw/inc/servo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Licensed to Pioneers in Engineering under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. Pioneers in Engineering licenses
// this file to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License

#ifndef INC_SERVO_H_
#define INC_SERVO_H_

#include "inc/smartsensor/common.h"

// Public functions called from main.c
void initServo();
void activeServoRec(uint8_t *data, uint8_t len, uint8_t inband);
void activeServoSend(uint8_t *outData, uint8_t *outLen, uint8_t *inband);

#endif // INC_SERVO_H_
2 changes: 2 additions & 0 deletions smartsensor_fw/inc/smartsensor/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
// Sensor types
#define SENSOR_TYPE_DIGITAL 0x00
#define SENSOR_TYPE_ANALOG_IN 0x01
#define SENSOR_TYPE_SERVO 0x03
#define SENSOR_TYPE_SOLENOID 0x04
#define SENSOR_TYPE_GRIZZLY3 0x80
#define SENSOR_TYPE_BUZZER 0x81
#define SENSOR_TYPE_FLAG 0x82
Expand Down
28 changes: 28 additions & 0 deletions smartsensor_fw/inc/solenoid.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Licensed to Pioneers in Engineering under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. Pioneers in Engineering licenses
// this file to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License

#ifndef INC_SOLENOID_H_
#define INC_SOLENOID_H_

#include "inc/smartsensor/common.h"

// Public functions called from main.c
void initSolenoid();
void activeSolenoidRec(uint8_t *data, uint8_t len, uint8_t inband);
void activeSolenoidSend(uint8_t *outData, uint8_t *outLen, uint8_t *inband);

#endif // INC_SOLENOID_H_
104 changes: 104 additions & 0 deletions smartsensor_fw/src/servo.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// Licensed to Pioneers in Engineering under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. Pioneers in Engineering licenses
// this file to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License

// This file has battery buzzer related functions

#include "inc/servo.h"
#include <avr/io.h>
#include <avr/interrupt.h>

static uint8_t AL1 = 0x01;
static uint8_t AH1 = 0x00;
static uint8_t BL1 = 0x01;
static uint8_t BH1 = 0x00;



// Timer 1 interrupt
ISR(TIMER1_OVF_vect) {

// Create a counter in order to only send a pulse every 12 timer interrupts.
static unsigned char counter = 0;

// On the 12th timer interrupt run this to create a pulse
if (counter == 0) {

// Set timer 1 to phase and freq correct pwm mode
TCCR1A = (1 << COM1A1) | (1 << COM1A0) | (1 << COM1B1) | (1<< COM1B0);
TCCR1B = (1 << CS10) | (1 << WGM13);

// update the values in these registers to set the pulse length
OCR1AH = AH1;
OCR1AL = AL1;
OCR1BH = BH1;
OCR1BL = BL1;

counter++;

// Run this after the 12th interrupt to stop the PWM generator from creating a second pulse
} else if (counter == 1) {

// Set timer 1 to output disconnected mode
TCCR1A = (1 << WGM11);
TCCR1B = (1 << CS10) | (1 << WGM12) | (1 << WGM13);
counter++;
} else if (counter == 11) {
// Reset the counter at 11
counter = 0;
} else {
counter++;
}
}

// Private helper functions

// Public functions called from main.c
void initServo() {
// Set the PWM pins to output
DIGITAL_SET_OUT(IN1);
DIGITAL_SET_OUT(IN3);

// Initiate timer 1
TCCR1A = 0;
TCCR1B = (1 << CS10) | (1 << WGM13);

// Define the top value of timer 1
ICR1H = 0x25;
ICR1L = 0x40;

// Enable timer 1 overflow interrupt
TIMSK = (1 << TOIE1);

// Enable interrupts
sei();

}

void activeServoRec(uint8_t *data, uint8_t len, uint8_t inband) {
if (len > 1){
AL1 = data[0];
AH1 = data[1];
}
if (len > 3){
BL1 = data[2];
BH1 = data[3];
}
}
void activeServoSend(uint8_t *outData, uint8_t *outLen, uint8_t *inband) {
// TODO(cduck): Write this function
*outlen = 0;
}
70 changes: 70 additions & 0 deletions smartsensor_fw/src/solenoid.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Licensed to Pioneers in Engineering under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. Pioneers in Engineering licenses
// this file to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License

// This file has digital io smart sensor related functions

#include "inc/solenoid.h"

// Private global variables
uint8_t outValueSolenoid = 0;

// Private helper functions
void SolenoidSetValue(uint8_t val);


// Public functions called from main.c
void initSolenoid() {
DIGITAL_SET_LOW(IN0);
DIGITAL_SET_LOW(IN1);
DIGITAL_SET_LOW(IN2);
DIGITAL_SET_LOW(IN3);

// TODO(tobinsarah): allow configuration as input/output for each relevant pin
DIGITAL_SET_OUT(IN0);
DIGITAL_SET_OUT(IN1);
DIGITAL_SET_OUT(IN2);
DIGITAL_SET_OUT(IN3);
}
void activeSolenoidRec(uint8_t *data, uint8_t len, uint8_t inband) {
if (len >= 1) {
outValueSolenoid = data[0];
}
switch (gameMode) {
case MODE_ACTIVE: SolenoidSetValue(outValueSolenoid);
break;
case MODE_DISABLED: SolenoidSetValue(0);
break;
case MODE_PAUSED: SolenoidSetValue(0); // Don't update outputs
default: break;
}
}
void activeSolenoidSend(uint8_t *outData, uint8_t *outLen, uint8_t *inband) {
*outLen = 0;
}





// Private helper functions
// TODO(karthik-shanmugam): update pins
void SolenoidSetValue(uint8_t val) {
DIGITAL_SET(IN0, val & 1); // UPDATE IN0
DIGITAL_SET(IN1, val & 2); // UPDATE IN1
DIGITAL_SET(IN2, val & 4); // UPDATE IN2
DIGITAL_SET(IN3, val & 8); // UPDATE IN3
}
10 changes: 10 additions & 0 deletions smartsensor_fw/src/ss_type.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "inc/analog_in.h"
#include "inc/buzzer.h"
#include "inc/flag.h"
#include "inc/servo.h"

void ssInitType() {
switch (SENSOR_TYPE) {
Expand All @@ -37,6 +38,9 @@ void ssInitType() {
case SENSOR_TYPE_FLAG:
initFlag();
break;
case SENSOR_TYPE_SERVO:
initServo();
break;
default: break;
// TODO(cduck): Add more smart sensors types
}
Expand All @@ -56,6 +60,9 @@ void ssActiveSend(uint8_t *decodedBuffer, uint8_t *pacLen, uint8_t *inband) {
case SENSOR_TYPE_FLAG:
activeFlagSend(decodedBuffer, pacLen, inband);
break;
case SENSOR_TYPE_SERVO:
activeServoSend(decodedBuffer, pacLen, inband);
break;
default: break;
// TODO(cduck): Add more smart sensors types
}
Expand All @@ -75,6 +82,9 @@ void ssActiveInRec(uint8_t *decodedBuffer, uint8_t dataLen, uint8_t inband) {
case SENSOR_TYPE_FLAG:
activeFlagRec(decodedBuffer, dataLen, inband);
break;
case SENSOR_TYPE_SERVO:
activeServoRec(decodedBuffer, dataLen, inband);
break;
default: break;
// TODO(cduck): Add more smart sensors types
}
Expand Down