Colour sensors calibrated

Dependencies:   mbed-rtos mbed Servo QEI

Fork of ICRSEurobot13 by Thomas Branch

Files at this revision

API Documentation at this revision

Comitter:
twighk
Date:
Fri Mar 29 16:28:56 2013 +0000
Parent:
0:200635fa1b08
Child:
2:45da48fab346
Commit message:
Arms / servos

Changed in this revision

Actuators/Arms/Arm.h Show annotated file Show diff for this revision Revisions of this file
Actuators/Arms/Servo.lib Show annotated file Show diff for this revision Revisions of this file
Actuators/MainMotor/MainMotor.h Show diff for this revision Revisions of this file
Actuators/MainMotors/MainMotor.h Show annotated file Show diff for this revision Revisions of this file
Actuators/Servo/Servo.h Show diff for this revision Revisions of this file
Sensors/Encoder/Encoder.h Show diff for this revision Revisions of this file
Sensors/Encoder/QEI.lib Show diff for this revision Revisions of this file
Sensors/Encoders/Encoder.h Show annotated file Show diff for this revision Revisions of this file
Sensors/Encoders/QEI.lib Show annotated file Show diff for this revision Revisions of this file
Sensors/Sonar/Sonar.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Actuators/Arms/Arm.h	Fri Mar 29 16:28:56 2013 +0000
@@ -0,0 +1,62 @@
+
+// Eurobot13 WhiteArm.h
+
+#include "mbed.h"
+#include "Servo.h"
+
+class Arm : public Servo
+{
+private:
+    bool updirn;
+
+public:
+    Arm(PinName yellow, bool upflip = false, float range = 0.0005, float degrees = 45.0) : Servo(yellow) {
+        calibrate(range, degrees);
+        updirn = upflip;
+    }
+
+    void operator()(float in) {
+        write(in);
+    }
+
+    void clockwise() { // full lock clockwise
+        write(updirn?1:0);
+    }
+
+    void anticlockwise() { // full lock anticlockwise
+        write(updirn?0:1);
+    }
+    
+    void relax() { // servo applies no force
+        _pwm = 0;
+    }
+};
+
+
+/*
+class Servo{
+    private:
+    PwmOut PWM;
+
+    public:
+    Servo(PinName pin1) : PWM(pin1){
+    }
+
+    void operator()(float in){
+        PWM = in;
+    }
+
+    void clockwise() { // full lock clockwise
+        PWM = .135;
+    }
+
+    void anticlockwise() { // full lock anticlockwise
+        PWM = .025;
+    }
+
+    void relax() { // servo applies no force
+        PWM = 0;
+    }
+
+};
+*/
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Actuators/Arms/Servo.lib	Fri Mar 29 16:28:56 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/Servo/#36b69a7ced07
--- a/Actuators/MainMotor/MainMotor.h	Fri Mar 29 11:35:34 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,29 +0,0 @@
-
-// Eurobot13 MainMotor.h
-
-#include "mbed.h"
-
-class MainMotor{
-    private:
-    PwmOut PWM1;
-    PwmOut PWM2;
-    
-    public:
-    MainMotor(PinName pin1, PinName pin2) : PWM1(pin1), PWM2(pin2){
-    }
-    
-    void operator()(float in){
-        power(in);
-    }
-    
-    void power(float power){
-        if( power > 0 ){
-            PWM1 = power;
-            PWM2 = 0;
-        } else {
-            PWM1 = 0;
-            PWM2 = -power;    
-        }
-    }
-
-};
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Actuators/MainMotors/MainMotor.h	Fri Mar 29 16:28:56 2013 +0000
@@ -0,0 +1,29 @@
+
+// Eurobot13 MainMotor.h
+
+#include "mbed.h"
+
+class MainMotor{
+    private:
+    PwmOut PWM1;
+    PwmOut PWM2;
+    
+    public:
+    MainMotor(PinName pin1, PinName pin2) : PWM1(pin1), PWM2(pin2){
+    }
+    
+    void operator()(float in){
+        power(in);
+    }
+    
+    void power(float power){
+        if( power > 0 ){
+            PWM1 = power;
+            PWM2 = 0;
+        } else {
+            PWM1 = 0;
+            PWM2 = -power;    
+        }
+    }
+
+};
\ No newline at end of file
--- a/Actuators/Servo/Servo.h	Fri Mar 29 11:35:34 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,30 +0,0 @@
-
-// Eurobot13 Servo.h
-
-#include "mbed.h"
-
-class Servo{
-    private:
-    PwmOut PWM;
-    
-    public:
-    Servo(PinName pin1) : PWM(pin1){
-    }
-    
-    void operator()(float in){
-        PWM = in;
-    }
-    
-    void clockwise() { // full lock clockwise
-        PWM = .135;
-    }
-    
-    void anticlockwise() { // full lock anticlockwise
-        PWM = .025;
-    }
-    
-    void relax() { // servo applies no force
-        PWM = 0;
-    }
-
-};
\ No newline at end of file
--- a/Sensors/Encoder/Encoder.h	Fri Mar 29 11:35:34 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,29 +0,0 @@
-
-// Eurobot13 Encoder.cpp
-
-#include "QEI.h"
-#include "mbed.h"
-
-class Encoder{
-private:
-    DigitalIn green, yellow;
-    QEI wheel;
-    
-public:
-    Encoder(PinName pGreen, PinName pYellow)
-        : green(pGreen)
-        , yellow(pYellow)
-        , wheel(pGreen,pYellow, NC, 624)
-        {
-    green.mode(PullUp);
-    yellow.mode(PullUp);
-    }
-    
-    int getPoint(void){
-        return wheel.getPulses();
-    }
-    
-    void reset (void){
-        return wheel.reset();
-    }
-};
--- a/Sensors/Encoder/QEI.lib	Fri Mar 29 11:35:34 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/aberk/code/QEI/#5c2ad81551aa
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Sensors/Encoders/Encoder.h	Fri Mar 29 16:28:56 2013 +0000
@@ -0,0 +1,29 @@
+
+// Eurobot13 Encoder.cpp
+
+#include "QEI.h"
+#include "mbed.h"
+
+class Encoder{
+private:
+    DigitalIn green, yellow;
+    QEI wheel;
+    
+public:
+    Encoder(PinName pGreen, PinName pYellow)
+        : green(pGreen)
+        , yellow(pYellow)
+        , wheel(pGreen,pYellow, NC, 624)
+        {
+    green.mode(PullUp);
+    yellow.mode(PullUp);
+    }
+    
+    int getPoint(void){
+        return wheel.getPulses();
+    }
+    
+    void reset (void){
+        return wheel.reset();
+    }
+};
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Sensors/Encoders/QEI.lib	Fri Mar 29 16:28:56 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/aberk/code/QEI/#5c2ad81551aa
--- a/main.cpp	Fri Mar 29 11:35:34 2013 +0000
+++ b/main.cpp	Fri Mar 29 16:28:56 2013 +0000
@@ -3,9 +3,9 @@
 
 #include "mbed.h"
 
-#include "Actuators/MainMotor/MainMotor.h"
-#include "Sensors/Encoder/Encoder.h"
-#include "Actuators/Servo/Servo.h"
+#include "Actuators/MainMotors/MainMotor.h"
+#include "Sensors/Encoders/Encoder.h"
+#include "Actuators/Arms/Arm.h"
 
 PwmOut Led(LED1);
 
@@ -14,19 +14,34 @@
 void motorencodetest();
 void motorencodetestline();
 void motorsandservostest();
+void armtest();
 
 int main() {
     //motortest();
     //encodertest();
     //motorencodetest();
-    motorencodetestline();
+    //motorencodetestline();
     //motorsandservostest();
+    armtest();
 }
 
+void armtest(){
+    Arm white(p26), black(p25, false,0.0005, 180);
+    while(1){
+        white(0);
+        black(0);
+        wait(1);
+        white(1);
+        black(1);
+        wait(1);
+    }
+}
+
+
 void motorsandservostest(){
     Encoder Eleft(p27, p28), Eright(p30, p29);
     MainMotor mleft(p24,p23), mright(p21,p22);
-    Servo sTop(p25), sBottom(p26);
+    Arm sTop(p25), sBottom(p26);
     Serial pc(USBTX, USBRX);
     const float speed = 0.0;
     const float dspeed = 0.0;