View unanswered posts | View active topics It is currently Sat Nov 25, 2017 3:55 am






Reply to topic  [ 28 posts ]  Go to page Previous  1, 2
IR code for tetrix 
Author Message
Rookie

Joined: Wed Jan 14, 2015 7:13 pm
Posts: 28
Post Re: IR code for tetrix
I wish it were so, the motors have an error and the floating statement has an issue, but nearly there


Wed Jan 21, 2015 2:45 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1523
Post Re: IR code for tetrix
What are the errors?


Wed Jan 21, 2015 3:43 pm
Profile
Rookie

Joined: Tue Jan 13, 2015 10:48 pm
Posts: 23
Post Re: IR code for tetrix
Substitute "motorE" for "MotorE" in the code.


Wed Jan 21, 2015 7:18 pm
Profile
Rookie

Joined: Wed Jan 14, 2015 7:13 pm
Posts: 28
Post Re: IR code for tetrix
#pragma config(Hubs, S1, HTMotor, HTServo, none, none)
#pragma config(Sensor, S2, HTIRS2, sensorI2CCustom)
#pragma config(Motor, mtr_S1_C1_1, motorD, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S1_C1_2, motorE, tmotorTetrix, openLoop)
#pragma config(Servo, srvo_S1_C2_1, servo1, tServoNone)
#pragma config(Servo, srvo_S1_C2_2, servo2, tServoNone)
#pragma config(Servo, srvo_S1_C2_3, servo3, tServoNone)
#pragma config(Servo, srvo_S1_C2_4, servo4, tServoNone)
#pragma config(Servo, srvo_S1_C2_5, servo5, tServoNone)
#pragma config(Servo, srvo_S1_C2_6, servo6, tServoNone)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
#include "hitechnic-irseeker-v2.h"
#define Kp 20.0

task main()
{
tHTIRS2 irSeeker;
initSensor(&irSeeker, S2);
while (true)
{
readSensor(&irSeeker);
float = irSeeker.acDirection - 5.0;
motor[MotorD] = 50;
motor[MotorE] = -50;

wait1Msec(20);
}
}
red:severe, won't compile
yellow:not an issue

I modified the code a little to reduce errors


Wed Jan 21, 2015 7:22 pm
Profile
Rookie

Joined: Tue Jan 13, 2015 10:48 pm
Posts: 23
Post Re: IR code for tetrix
You actually caused more errors.
Code:
#pragma config(Hubs, S1, HTMotor, HTServo, none, none)
#pragma config(Sensor, S2, HTIRS2, sensorI2CCustom)
#pragma config(Motor, mtr_S1_C1_1, motorD, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S1_C1_2, motorE, tmotorTetrix, openLoop)
#pragma config(Servo, srvo_S1_C2_1, servo1, tServoNone)
#pragma config(Servo, srvo_S1_C2_2, servo2, tServoNone)
#pragma config(Servo, srvo_S1_C2_3, servo3, tServoNone)
#pragma config(Servo, srvo_S1_C2_4, servo4, tServoNone)
#pragma config(Servo, srvo_S1_C2_5, servo5, tServoNone)
#pragma config(Servo, srvo_S1_C2_6, servo6, tServoNone)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

#define Kp              20.0

#include "hitechnic-irseeker-2.h"

task main()
{
    tHTIRS2 irSeeker;
    initSensor(&irSeeker, S2);
    while (true)
    {
        readSensor(&irSeeker);
        float error = irSeeker.acDirection - 5.0;
        motor[motorD] = Kp*error;
        motor[motorE] = -Kp*error;
        wait1Msec(20);
    }
}


If there is further error, please tell use the specific error messages.
Also, please enclose your code in
Code:
[code][/code]

in the future.


Wed Jan 21, 2015 7:43 pm
Profile
Rookie

Joined: Wed Jan 14, 2015 7:13 pm
Posts: 28
Post Re: IR code for tetrix
the errors on the plain code were numbered at 4 for my RobotC where as, I made mine with 1 serious error


Wed Jan 21, 2015 7:48 pm
Profile
Rookie

Joined: Wed Jan 14, 2015 7:13 pm
Posts: 28
Post Re: IR code for tetrix
[code]
#pragma config(Hubs, S1, HTMotor, HTServo, none, none)
#pragma config(Sensor, S2, HTIRS2, sensorI2CCustom)
#pragma config(Motor, mtr_S1_C1_1, motorD, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S1_C1_2, motorE, tmotorTetrix, openLoop)
#pragma config(Servo, srvo_S1_C2_1, servo1, tServoNone)
#pragma config(Servo, srvo_S1_C2_2, servo2, tServoNone)
#pragma config(Servo, srvo_S1_C2_3, servo3, tServoNone)
#pragma config(Servo, srvo_S1_C2_4, servo4, tServoNone)
#pragma config(Servo, srvo_S1_C2_5, servo5, tServoNone)
#pragma config(Servo, srvo_S1_C2_6, servo6, tServoNone)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

#define Kp 20.0

#include "hitechnic-irseeker-2.h"

task main()
{
tHTIRS2 irSeeker;
initSensor(&irSeeker, S2);

while (true)
{
readSensor(&irSeeker);
float error = irSeeker.acDirection - 5.0;

motor[motorD] = Kp*error;
motor[motorE] = -Kp*error;
wait1Msec(20);
}
}
[code/]
there were more errors
red:: severe
yellow:: miniscule


Wed Jan 21, 2015 7:51 pm
Profile
Rookie

Joined: Wed Jan 14, 2015 7:13 pm
Posts: 28
Post Re: IR code for tetrix
what does it mean when a window comes up saying "Exception Error in User Program:

Exception Type: 'Property not supported by emulator(77)'

Program Slot: 0, Task ID: main[0]
Error at PC: waitForI2CBus+0x0008
Task PC: Task: main+0x0000,
TaskState: 'Exception'
"?


Wed Jan 21, 2015 8:33 pm
Profile
Rookie

Joined: Tue Jan 13, 2015 10:48 pm
Posts: 23
Post Re: IR code for tetrix
My bad, it is actually "hitechnic-irseeker-v2.h"

Before continuing, I strongly, strongly recommend learning C. You have no idea how easy RobotC will be after you learn C.

Learning the basics of C takes at most an hour, and delving into the more advanced stuff isn't much harder either.


Wed Jan 21, 2015 9:48 pm
Profile
Rookie

Joined: Wed Jan 14, 2015 7:13 pm
Posts: 28
Post Re: IR code for tetrix
I understand the basics of RobotC but IR coding, it is not basic. I am learning coding every day, my second EC is robotics


Thu Jan 22, 2015 12:52 pm
Profile
Rookie

Joined: Wed Jan 14, 2015 7:13 pm
Posts: 28
Post Re: IR code for tetrix
JAYPD wrote:
what does it mean when a window comes up saying "Exception Error in User Program:

Exception Type: 'Property not supported by emulator(77)'

Program Slot: 0, Task ID: main[0]
Error at PC: waitForI2CBus+0x0008
Task PC: Task: main+0x0000,
TaskState: 'Exception'
"?


I realize that this meant a part of the code would not work on my pc


Thu Jan 22, 2015 12:56 pm
Profile
Rookie

Joined: Mon Jan 26, 2015 2:59 pm
Posts: 4
Post Re: IR code for tetrix
Thanks so much for this short program! My question is, what is the logic behind defining kp as 20? and how does it work. Any explanation would be helpful. Also, is it possible for the robot to know how far it is from the ir beacon solely from signal strength? Thanks.


Wed Feb 04, 2015 1:57 am
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1523
Post Re: IR code for tetrix
rkage wrote:
Thanks so much for this short program! My question is, what is the logic behind defining kp as 20? and how does it work. Any explanation would be helpful. Also, is it possible for the robot to know how far it is from the ir beacon solely from signal strength? Thanks.

The code is a classic Proportional-only control (part of PID control). You can google PID control to learn more about it. But essentially, it is a close-loop control system where it says the power to the motor should be proportional to how far you are from target. If you are far away from your target, you run the motor full speed. If you become closer and close, the "error" is smaller and smaller and the motor power becomes smaller as well (i.e. you go slower when you are about to reach target). So in this case, the target is the direction of the IR beacon (being zone 5). If the robot is way off target (e.g. zone 9), the error is then 9 - 5 = 4. So if you use this error value to determine the difference in power between the left and right wheel, you can make the robot turn to minimize error. But power difference of 4 is not enough to turn the robot, therefore, we need a scale factor and hence Kp. If Kp is 20, then the power difference would be 80. That will be more than enough to turn the robot towards the IR beacon. As the robot turns (i.e. the reading becomes, 8, then 7, then 6, for example), the error now becomes 6 - 5 = 1 and multiplied by Kp (20) that gives you a power difference between the wheels down to 20. As you can see the turning slowed down. When you final get a reading 5, the error becomes zero, the power difference between left and right wheel is now zero. So the robot is in theory aligned with the IR beacon.
Reading the IR strength will give you an indication whether you are getting closer to the IR beacon but it is difficult to translate that information to absolute distance to the beacon because the signal strength is affected by the battery level of the beacon as well as the sensitivity of your IR seeker.


Wed Feb 04, 2015 2:37 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 28 posts ]  Go to page Previous  1, 2

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.