Welcome to Synthiam!

Program robots using technologies created from industry experts. ARC is our free-to-use robot programming software that makes features like vision recognition, navigation and artificial intelligence easy.

Get Started
Asked — Edited

C# If And Boolean Operators Are Broke Me Thinks.

Hi

I'm trying to move the ping sensor to 3 locations and capture the variables of $left, $Center and $right and compare which has the largest distance among these three locations to make the robot move in that direction.

I've moved from EZ-Script to the C# scripting for better conditional control. The goforward() command for the h-bridge in your c# example script of Radar Scan isn't working. I'm wanting to tailor that script to my own desires.

Below is a sample script illustrating that issue.

Code:



using System;
using System.IO;
using System.Windows.Forms;
using EZ_B;

namespace VName {

public class VClass {

public void Main(EZB ezb0, EZB ezb1, EZB ezb2, EZB ezb3, EZB ezb4) {

bool dir = true;
bool weMoved = false;

ezb0.Servo.SetServoPosition(Servo.ServoPortEnum.D5, 10);

while (true) {

int servoPos = ezb0.Servo.GetServoPosition(Servo.ServoPortEnum.D5);
int distance = ezb0.HC_SR04.GetValue(Digital.DigitalPortEnum.D0, Digital.DigitalPortEnum.D1);

if (distance 40)
ezb0.Movement.Goright(255, );
else if (servoPos 80)
dir = false;

if (servoPos < 10)
dir = true;

ezb0.Servo.SetServoPosition(Servo.ServoPortEnum.D5, servoPos);
}

System.Threading.Thread.Sleep(250);
}
}
}
}


Thanks,

Bill

AI Support Bot
Related Content
Synthiam
Based on your post activity, we found some content that may be interesting to you. Explore these other tutorials and community conversations.
PRO
Synthiam
#1  
I don't understand your code - sorry. It seems only part of your message is here. You can attach EZB files to your forum post, that might be easier for you in the future.

If you'd like to use EZ-Script, for $left, $right, and $center than use this example: Example-Script-CustomObjectAvoidance2.EZB
#2  
Sorry about that DJ,

I just edited and reposted it above. I had tried to post two code snipits on the same page. It's the c# example of the radar scanner. Which still gives me errors.

Yet in the above c# example I replaced the ezb0.Movement.Goright(255, ); with ezb0.Movement.Goright(); and it still gave me the:
Error: Cannot compile assembly. 2 Errors:
Line: 27 - 'EZ_B.Movement' does not contain a definition for 'Goright'
Line: 29 - 'EZ_B.Movement' does not contain a definition for 'Goleft'

The other issue I had with boolean operators was my using the wrong syntax. I neglected the {} case operators as in:
if ((x==10) && (y==10) && (z==10)){
MessageBox.Show("All are equal");
}

Many Thanks,

Bill
PRO
Synthiam
#3  
In the future, please use the upload feature to post your file. That way, it will be easier for anyone assisting.

1)
The command ezb0.Movement.Goright(255, ); is not a valid command. There is a comma, but nothing after it. And there is no Goright() command.

2)
The command ezb0.Movement.Goright() is not a valid command.

3)
The command you wish to use is ezb0.Movement.GoRight(). Remember C# is case sensitive, unlike Visual Basic. Please consult the manual for the proper use of capital and lower case letters.

3)
Boolean operators in c# are true and false, not numbers. I do not understand what you are asking, sorry.

If the C# compiler was broken, you would need to contact Microsoft - but i'm sure they would know about it way before you :). For information on programming, start off with a website tutorial like this: http://www.csharp-station.com/Tutorial.aspx

:)
#4  
Got it DJ,

That has me working perfectly.

I suspect though others will also be thrown off by that default example under File>Examples>Example Script - C Radar Scan in the ARC that uses the wrong case sensitivity and syntax for the movement control "ezb0.Movement.Goright(255, )".

I assumed it was correct as all the others are correct therefore I didn't consult the manual.

Thanks
PRO
Synthiam
#5  
Oh does the example have incorrect case? Thanks for letting me know.