Romi OnBoardIO

Has anyone used romi to turn on yellow led, or the red and green for that mater which are on bidirectional pins. There is an example of reading the push bittonsin RobotContainer.java. I have been able to change code as to read all three. I thought I could replace the lines with PrintCommand

when.active(new PrintCommand(“Button A is Pressed”))
whenInactive(new PrintCommand(Button A is Released"));

with setYellowLed(true) and setYellowLed(false)

always get a compile error. Any suggestions?

What compile error do you get?

Major problem is no matter what I enter the entries have a red line under them. This was one of many tries. The code was the java code in library that had made any reference to Romi. To my knowledge setYelloLed is a method defined in OnBoardIO.java.

I altered in RobotContainer.java after the comment line //Example how to use the onboard IO
onboardButtonA

    .whenActive(new setYellowLed(true)  // my altered line
    .whenInactive(new PrintCommand("Button A Released")));

The compiler responded with

  • What went wrong:
    Execution failed for task ‘:compileJava’.

Compilation failed; see the compiler error output for details.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

BUILD FAILED in 2s
2 actionable tasks: 2 executed
The terminal process “cmd.exe /d /c gradlew simulateExternalJava -Dorg.gradle.java.home=“C:\Users\Public\wpilib\2021\jdk”” terminated with exit code: 1.

So, I am just learning commands, so I may be off, but I will take a stab.
First, the error you printed is not the actual piece of the code that broke, but the result of the breakage, if you scroll up a bit, or hover over the underline in the code, you will get a better sense of what went wrong.

In order to understand what happened, you need to understand the command framework a bit.

in the original example code,

// Example of how to use the onboard IO
    Button onboardButtonA = new Button(m_onboardIO::getButtonAPressed);
    onboardButtonA
        .whenActive(new PrintCommand("Button A Pressed"))
        .whenInactive(new PrintCommand("Button A Released"));

First…
Button onboardButtonA = new Button(m_onboardIO::getButtonAPressed);
We create a new instance of the button by referencing the private method in the OI subsystem. using the :: operator which is similar to a lambda expression.

Since it is a button, this is an input device, so we can have our code react to it.

Then…

onboardButtonA
       .whenActive(new PrintCommand("Button A Pressed"))
       .whenInactive(new PrintCommand("Button A Released"));

When it is pressed, we run a new print command (which is like an instant command that does nothing but print a result).

So, you are not able to replace that with a direct method reference (the setYellowLED()) without making the program confused.

Now that we know what is wrong (assuming I am correct), how would you like to proceed to fix it? We could switch out of command framework and access the LED directly, or try to create a new command that runs the led.

So what I did was:
m_controller.XButton.whenPressed(() -> m_onboardIO.setYellowLed(true));
m_controller.YButton.whenPressed(() -> m_onboardIO.setYellowLed(false));

If you wanted to do it with the pushbutton on the ROMI:

onboardButtonA
      .whenActive(() -> m_onboardIO.setYellowLed(true))
      .whenInactive(() -> m_onboardIO.setYellowLed(false));

If you want to change the red / green LEDs make sure you have set it to output. Disabling button B/C:
private final OnBoardIO m_onboardIO = new OnBoardIO(ChannelMode.OUTPUT, ChannelMode.OUTPUT);

Not make sure you have the latest specifically for the YellowLED cause there was a bug

1 Like

Thank you for possibly help. I am also a learner and find WPI libraries confusing at best. I have programmed in C+ and assembly for many devices. TI, MicroChip, Intel, Zilog and Motorola. There, I control the port and pin direction. With WPI I have no control! As I get deeper in library I find I know less and less. Any help would be appreciated. The // Example of how to use the onboard IO is Really not an example. I have searched with Google and found no examples as to how to use the Romi’s input and output pins. Not to mention the additional 5 AIN0, AIN1, PWM2, PWM3, and DIO8 (wpi nomenclature). It is those pins and external addons like a range finder is my goal. I was trying to add a line follower and needed inputs from IR’s to control guidance. So if I could get a led to light, I could turn on and off my IR. Then read the receiver with A, B, C, or DIO8.

1.) I would like to turn on the yellow led, somehow. Whatever is required to accomplish.
2.) How do I do it with the Bidirectional pins. Button B and green LED DIO1 or C and red.
3.) And where I started, Push A and turn on Yellow, and when push is released on A, turn off.

Did you read my post? I can’t help you if you completely ignore my post

I don’t understand saying you have no control with WPILib? It is all open source even if you didn’t have us helping you, it could still be figured out by looking at the source.

In reply to jdaming

I got a post from Mr.R2 who ask and I replied to. During that time frame, your post came in, which I did not see since I was answering Mr.R2. I did not ignore you I just didn’t get to it. so

Yes I did read it after the fact but not before you quickly did the second post. I would not call this a completely ignore! Some of the comments below are to first post which I have not got to implement.

The yellow led is output only. I can not change it. Or am I missing something. I believe some solder is involved, I was dealing with the yellow led so I did not find it necessary to change those to output. In one of my earlier “tries” I did change to OUTPUT to control red and green with the method or command setGreenLed(true). This also caused method to red underline. But with your suggestion I am sure it will not.

Your code most likely is the answer I am looking for and am anxious to test it but your sharp response implying my lack of reading ability has delayed that effort.

Again this was written before I got your message and yes I was aware of the “bug” because of my google searches.

If you read my first post it is clear what my intentions are. Is this asking too much for the robot to respond to a key press? When BAE introduced the Romi, a lot of us were not involved in programming the competition robot. All documentation assumes the Romi programmers were involved and experts in this activity, but (surprise) some of us are not. Which should answer why I don’t understand the WPILib . As you say, It is open source and even if you didn’t have us helping you, it could still be figured out by looking at the source.
Yes, this is true. I am grateful for your help.

1 Like

The Yellow LED (DO3) and Button A (DI0) are fixed. DIO1 is either Button B or green LED. DIO2 is either Button C or red LED. The OnBoardIO command above sets DIO1 and DIO2.

1 Like

Thank you and it may be the bug but code compiled but but no yellow light. It may be because of bug may not be able to use this method.

I tried the m_controller.XButton and got XButton not defined so no compilation. Must find code that will activate buttons.

The bug only applies to the first time the LED is turned off / on. I think we have bigger problems here.

I copied the code from our robot and we have a helper class with the buttons try this before it:
JoystickButton XButton = new JoystickButton(m_XboxController, XboxController.Button.kX.value);

I am glad, and it seems that you are making some progress (though I could understand if it does not feel like it yet). @jdaming 's code seems to be the answer to the LED. I will try it out when I get a chance and report back. @jdaming has helped me a lot lately and is incredibly brilliant in the ways of programming in FRC.

If his examples do not make sense, you may want to try using the Romi timed robot project template instead of the example. It is counter-intuitive, but starting from scratch really is easier for us in the beginning until we found a need to learn the command framework. You can even use CPP instead of Java if you are more familiar with that (though the abstraction is essentially the same save for the Command Framework).

I can see how this could all be a bit confusing coming from a lower-level programming background. I am coming at it from the other end, mostly. We were a Python team until I started looking for mini robots and did a self-directed crash course (literally) learning about how to create libraries and drive h-bridges from scratch. Then came the Romi and everything got a lot easier and clearer for both my team and me.

Anyway, my guess about the confusion would be all the levels of abstraction involved (as I understand them anyway).

We have in order from higher to lower-level…

  • The command Framework (with the io subsystem)
  • Wpilib simulator
  • The web socket to the raspbery pi
  • The wpilib Romi Interface on the Pi
  • The I2C interface to the 32U4 control board
  • The firmware.
  • Then we get to our hardware.

To reverse this order, here is some documentation.
For Pololu’s interface, take a look here. <-- you may want to spend some time working with this directly if you have Arduino experience.
For the wpilib romi websocket interface, look here.
But of course, many people will jump right to the wpilib interface (I did) which has docs here.

The buttons, accelerometer, and Gyro are not really documented there, but the example program does work for the most part. to see what is happening there, you can look at the iosubsystem and look at the constructors of each of the items (you can call them directly in a timed robot project).

The Gyro specifically is confusing in the sense that it is a SimDevice(). So, whenever we use it, our team simply copies the entire class to our desired project and access it that way.

I think you will get the buttons and leds figured out, so I will jump right to the flexible DIO.

You can use the interface in the web portal described above to set it. Once done, you can use it to run many hardware devices (even h-bridges if you would like).

However, rangefinders are not so clear-cut. Many of them (especially LIDAR) use I2c. There does not seem to be a wpilib interface for this on the Romi (besides the one running the entire robot:). Even if you wrote your own, there is a danger of the device’s address being the same as the Romi, so you would need to be careful when picking out such a device.

Many others use a ping… …response DIO. I have not gotten these to work either. I can get the IO working independently, but something goes awry when I try to use the WPILIB interface.

Which leaves analog sensors. I have had a lot of success with these. There is one cheap model I have that came with a kit that does not work (I can dig it up if you are interested), but most of the generic ones and all of the Maxobotics we got through various kits over the years and through First Choice this year, work perfectly.

Sorry for the long post, or if I am off-base or inaccurate, but that is how I understand the Romi pieces currently.
Please, anyone, step in to correct me if I am.

2 Likes

Thank you for the lengthy response. I also heard from a Chris Herzog who is watching this post in hopes of finding some answers. Since @jdaming provided some code which required a helper class using XButton on joystick I must provide my own method which I will work on after my response to your post. He also @jdaming posted code that used the Romi AButton and setYellowLed(true). This compiled, but did not light LED. My thought that in library although DIO3 is an output it is configured as an input. I have tried to examine the code DigitalOutput.java and so far unable to decode it. My limited knowledge. I will try again today.

It is obvious there are no simple solutions. In essence, in the opinion of Mr. Herzog “One the biggest issues is, to really do this effectively (program Romi) , you really need to be a C++ jock - like all of it, right to the esoteric end.” This is from someone who has programmed in C just short of 40 years. I would gladly share his post with his approval for it is relevant to the problem.

I will also try code to read the X and Y buttons of X Box Controller.

I will take your suggestion on using the Romi timed robot project. I do not think it was in the VS WPILIB. I recall only seeing one Romi project. It was a video from WPI called in Hour of Code (https://m.twitch.tv/videos/838364551). In the WPI blogs the project is there. For your information, the example shown in video DID NOT WORK! Later using the WPI blog I got the code from the repository. There was NO explanation as to what went wrong in the demo. A point was made in the failed demo to be sure to look for the solution.

Yes my background has been low level where I had control. It is with hands tied to try adapt to C and java with some success. Your comment on H-bridges brought to mind when I questioned the use of using PWM to control speed. Nothing but blank eyes and stares while explaining servo control of varying a 2 MS pulse in a 20 MS period resulting in both forward and reverse motion with neutral at 1.5 MS. As opposed to control of voltage/current as a percentage of the full period and in which one has to use the H-bridge to control direction of movement. The very heart of FRC. This is of no small importance for drive trains and with all due respect how many drivers, team captains and crews don’t care as long as the have a robot and they can control it. So much for the programmers and those libraries that must provide those features.

Forward to Pulolu. I have with Arduino and library wrote a line follow program. Far from finished and with at least one crossover a potential trap unless one has control of IO. Since we must program the Romi with WPI library I quite the pursuit down that path and started with Delphi blog.

I am using IR and not sonic as line detection method and your comments again inform me that once again things go awry when you try (underline try) to use the WPI library.

I really have to get back to IO , and I to have rambled. Sorry. We have a Zoom meeting tonight and the team is awaiting my answer on IO on the Romi.

I guess it depends on what you think is simple. I created this example in about a minute. I think WPILib is doing everything it can but program this for you. Here is my code.

I am left speechless. Thank you for programming this for me. I believe Mr.R_2 and Chris Herzog will wish to extend their thanks for your generous input. I think the information you provided for us will extend far farther then you could possible imagine. As stated you are incredibly brilliant in the ways of programming in FRC.

No problem happy to help I am glad to see more people working with the Romi and I hope it helps people learn and have a good time doing it.

FYI Just tested code. ButtonB turns red LED on and off. It may be my XBox controller but X and Y button have no effect on yellow light. I think we can figure it out from here.
Thanks

I was worried X and Y was confusing things so I disabled them. If you want to test you could uncomment out these lines

I assume button A worked for you too?

I saw the lines where commented. I tried, did not work. Button A did not light yellow LED. I started to add button C with OUTPUT but then things went sour and I lost red on B. Since the code I downloaded was changed I came back to reload code to start over and saw your post.

Forgot ZIP not changedf!